1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
36 #include "complaints.h"
41 /* Ask stabsread.h to define the vars it normally declares `extern'. */
43 #include "stabsread.h" /* Our own declarations */
46 /* The routines that read and process a complete stabs for a C struct or
47 C++ class pass lists of data member fields and lists of member function
48 fields in an instance of a field_info structure, as defined below.
49 This is part of some reorganization of low level C++ support and is
50 expected to eventually go away... (FIXME) */
56 struct nextfield
*next
;
58 /* This is the raw visibility from the stab. It is not checked
59 for being one of the visibilities we recognize, so code which
60 examines this field better be able to deal. */
65 struct next_fnfieldlist
67 struct next_fnfieldlist
*next
;
68 struct fn_fieldlist fn_fieldlist
;
73 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
75 static long read_huge_number
PARAMS ((char **, int, int *));
77 static struct type
*error_type
PARAMS ((char **));
80 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
84 fix_common_block
PARAMS ((struct symbol
*, int));
87 read_type_number
PARAMS ((char **, int *));
90 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
93 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
96 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
99 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
102 rs6000_builtin_type
PARAMS ((int));
105 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
109 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
113 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
117 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
121 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
124 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
128 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
131 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
133 static struct type
**
134 read_args
PARAMS ((char **, int, struct objfile
*));
137 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
140 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
141 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
143 /* Define this as 1 if a pcc declaration of a char or short argument
144 gives the correct address. Otherwise assume pcc gives the
145 address of the corresponding int, which is not the same on a
146 big-endian machine. */
148 #ifndef BELIEVE_PCC_PROMOTION
149 #define BELIEVE_PCC_PROMOTION 0
153 struct complaint dbx_class_complaint
=
155 "encountered DBX-style class variable debugging information.\n\
156 You seem to have compiled your program with \
157 \"g++ -g0\" instead of \"g++ -g\".\n\
158 Therefore GDB will not know about your class variables", 0, 0
162 struct complaint invalid_cpp_abbrev_complaint
=
163 {"invalid C++ abbreviation `%s'", 0, 0};
165 struct complaint invalid_cpp_type_complaint
=
166 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
168 struct complaint member_fn_complaint
=
169 {"member function type missing, got '%c'", 0, 0};
171 struct complaint const_vol_complaint
=
172 {"const/volatile indicator missing, got '%c'", 0, 0};
174 struct complaint error_type_complaint
=
175 {"debug info mismatch between compiler and debugger", 0, 0};
177 struct complaint invalid_member_complaint
=
178 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
180 struct complaint range_type_base_complaint
=
181 {"base type %d of range type is not defined", 0, 0};
183 struct complaint reg_value_complaint
=
184 {"register number too large in symbol %s", 0, 0};
186 struct complaint vtbl_notfound_complaint
=
187 {"virtual function table pointer not found when defining class `%s'", 0, 0};
189 struct complaint unrecognized_cplus_name_complaint
=
190 {"Unknown C++ symbol name `%s'", 0, 0};
192 struct complaint rs6000_builtin_complaint
=
193 {"Unknown builtin type %d", 0, 0};
195 struct complaint stabs_general_complaint
=
198 /* Make a list of forward references which haven't been defined. */
200 static struct type
**undef_types
;
201 static int undef_types_allocated
;
202 static int undef_types_length
;
204 /* Check for and handle cretinous stabs symbol name continuation! */
205 #define STABS_CONTINUE(pp) \
207 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
211 /* Look up a dbx type-number pair. Return the address of the slot
212 where the type for that number-pair is stored.
213 The number-pair is in TYPENUMS.
215 This can be used for finding the type associated with that pair
216 or for associating a new type with the pair. */
219 dbx_lookup_type (typenums
)
222 register int filenum
= typenums
[0];
223 register int index
= typenums
[1];
225 register int real_filenum
;
226 register struct header_file
*f
;
229 if (filenum
== -1) /* -1,-1 is for temporary types. */
232 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
234 static struct complaint msg
= {"\
235 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
237 complain (&msg
, filenum
, index
, symnum
);
245 /* Caller wants address of address of type. We think
246 that negative (rs6k builtin) types will never appear as
247 "lvalues", (nor should they), so we stuff the real type
248 pointer into a temp, and return its address. If referenced,
249 this will do the right thing. */
250 static struct type
*temp_type
;
252 temp_type
= rs6000_builtin_type(index
);
256 /* Type is defined outside of header files.
257 Find it in this object file's type vector. */
258 if (index
>= type_vector_length
)
260 old_len
= type_vector_length
;
263 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
264 type_vector
= (struct type
**)
265 malloc (type_vector_length
* sizeof (struct type
*));
267 while (index
>= type_vector_length
)
269 type_vector_length
*= 2;
271 type_vector
= (struct type
**)
272 xrealloc ((char *) type_vector
,
273 (type_vector_length
* sizeof (struct type
*)));
274 memset (&type_vector
[old_len
], 0,
275 (type_vector_length
- old_len
) * sizeof (struct type
*));
277 return (&type_vector
[index
]);
281 real_filenum
= this_object_header_files
[filenum
];
283 if (real_filenum
>= n_header_files
)
285 struct type
*temp_type
;
286 struct type
**temp_type_p
;
288 warning ("GDB internal error: bad real_filenum");
291 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
292 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
293 *temp_type_p
= temp_type
;
297 f
= &header_files
[real_filenum
];
299 f_orig_length
= f
->length
;
300 if (index
>= f_orig_length
)
302 while (index
>= f
->length
)
306 f
->vector
= (struct type
**)
307 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
308 memset (&f
->vector
[f_orig_length
], 0,
309 (f
->length
- f_orig_length
) * sizeof (struct type
*));
311 return (&f
->vector
[index
]);
315 /* Make sure there is a type allocated for type numbers TYPENUMS
316 and return the type object.
317 This can create an empty (zeroed) type object.
318 TYPENUMS may be (-1, -1) to return a new type object that is not
319 put into the type vector, and so may not be referred to by number. */
322 dbx_alloc_type (typenums
, objfile
)
324 struct objfile
*objfile
;
326 register struct type
**type_addr
;
328 if (typenums
[0] == -1)
330 return (alloc_type (objfile
));
333 type_addr
= dbx_lookup_type (typenums
);
335 /* If we are referring to a type not known at all yet,
336 allocate an empty type for it.
337 We will fill it in later if we find out how. */
340 *type_addr
= alloc_type (objfile
);
346 /* for all the stabs in a given stab vector, build appropriate types
347 and fix their symbols in given symbol vector. */
350 patch_block_stabs (symbols
, stabs
, objfile
)
351 struct pending
*symbols
;
352 struct pending_stabs
*stabs
;
353 struct objfile
*objfile
;
363 /* for all the stab entries, find their corresponding symbols and
364 patch their types! */
366 for (ii
= 0; ii
< stabs
->count
; ++ii
)
368 name
= stabs
->stab
[ii
];
369 pp
= (char*) strchr (name
, ':');
373 pp
= (char *)strchr(pp
, ':');
375 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
378 /* On xcoff, if a global is defined and never referenced,
379 ld will remove it from the executable. There is then
380 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
381 sym
= (struct symbol
*)
382 obstack_alloc (&objfile
->symbol_obstack
,
383 sizeof (struct symbol
));
385 memset (sym
, 0, sizeof (struct symbol
));
386 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
387 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
389 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
391 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
393 /* I don't think the linker does this with functions,
394 so as far as I know this is never executed.
395 But it doesn't hurt to check. */
397 lookup_function_type (read_type (&pp
, objfile
));
401 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
403 add_symbol_to_list (sym
, &global_symbols
);
408 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
411 lookup_function_type (read_type (&pp
, objfile
));
415 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
423 /* Read a number by which a type is referred to in dbx data,
424 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
425 Just a single number N is equivalent to (0,N).
426 Return the two numbers by storing them in the vector TYPENUMS.
427 TYPENUMS will then be used as an argument to dbx_lookup_type.
429 Returns 0 for success, -1 for error. */
432 read_type_number (pp
, typenums
)
434 register int *typenums
;
440 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
441 if (nbits
!= 0) return -1;
442 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
443 if (nbits
!= 0) return -1;
448 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
449 if (nbits
!= 0) return -1;
455 /* To handle GNU C++ typename abbreviation, we need to be able to
456 fill in a type's name as soon as space for that type is allocated.
457 `type_synonym_name' is the name of the type being allocated.
458 It is cleared as soon as it is used (lest all allocated types
461 static char *type_synonym_name
;
465 define_symbol (valu
, string
, desc
, type
, objfile
)
470 struct objfile
*objfile
;
472 register struct symbol
*sym
;
473 char *p
= (char *) strchr (string
, ':');
478 /* We would like to eliminate nameless symbols, but keep their types.
479 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
480 to type 2, but, should not create a symbol to address that type. Since
481 the symbol will be nameless, there is no way any user can refer to it. */
485 /* Ignore syms with empty names. */
489 /* Ignore old-style symbols from cc -go */
499 /* If a nameless stab entry, all we need is the type, not the symbol.
500 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
501 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
503 sym
= (struct symbol
*)
504 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
505 memset (sym
, 0, sizeof (struct symbol
));
507 if (processing_gcc_compilation
)
509 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
510 number of bytes occupied by a type or object, which we ignore. */
511 SYMBOL_LINE(sym
) = desc
;
515 SYMBOL_LINE(sym
) = 0; /* unknown */
518 if (string
[0] == CPLUS_MARKER
)
520 /* Special GNU C++ names. */
524 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
525 &objfile
-> symbol_obstack
);
528 case 'v': /* $vtbl_ptr_type */
529 /* Was: SYMBOL_NAME (sym) = "vptr"; */
533 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
534 &objfile
-> symbol_obstack
);
538 /* This was an anonymous type that was never fixed up. */
542 complain (&unrecognized_cplus_name_complaint
, string
);
543 goto normal
; /* Do *something* with it */
549 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
550 SYMBOL_NAME (sym
) = (char *)
551 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
552 /* Open-coded memcpy--saves function call time. */
553 /* FIXME: Does it really? Try replacing with simple strcpy and
554 try it on an executable with a large symbol table. */
555 /* FIXME: considering that gcc can open code memcpy anyway, I
556 doubt it. xoxorich. */
558 register char *p1
= string
;
559 register char *p2
= SYMBOL_NAME (sym
);
567 /* If this symbol is from a C++ compilation, then attempt to cache the
568 demangled form for future reference. This is a typical time versus
569 space tradeoff, that was decided in favor of time because it sped up
570 C++ symbol lookups by a factor of about 20. */
572 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
576 /* Determine the type of name being defined. */
578 /* Getting GDB to correctly skip the symbol on an undefined symbol
579 descriptor and not ever dump core is a very dodgy proposition if
580 we do things this way. I say the acorn RISC machine can just
581 fix their compiler. */
582 /* The Acorn RISC machine's compiler can put out locals that don't
583 start with "234=" or "(3,4)=", so assume anything other than the
584 deftypes we know how to handle is a local. */
585 if (!strchr ("cfFGpPrStTvVXCR", *p
))
587 if (isdigit (*p
) || *p
== '(' || *p
== '-')
596 /* c is a special case, not followed by a type-number.
597 SYMBOL:c=iVALUE for an integer constant symbol.
598 SYMBOL:c=rVALUE for a floating constant symbol.
599 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
600 e.g. "b:c=e6,0" for "const b = blob1"
601 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
604 SYMBOL_CLASS (sym
) = LOC_CONST
;
605 SYMBOL_TYPE (sym
) = error_type (&p
);
606 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
607 add_symbol_to_list (sym
, &file_symbols
);
618 /* FIXME-if-picky-about-floating-accuracy: Should be using
619 target arithmetic to get the value. real.c in GCC
620 probably has the necessary code. */
622 /* FIXME: lookup_fundamental_type is a hack. We should be
623 creating a type especially for the type of float constants.
624 Problem is, what type should it be?
626 Also, what should the name of this type be? Should we
627 be using 'S' constants (see stabs.texinfo) instead? */
629 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
632 obstack_alloc (&objfile
-> symbol_obstack
,
633 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
634 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
635 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
636 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
641 /* Defining integer constants this way is kind of silly,
642 since 'e' constants allows the compiler to give not
643 only the value, but the type as well. C has at least
644 int, long, unsigned int, and long long as constant
645 types; other languages probably should have at least
646 unsigned as well as signed constants. */
648 /* We just need one int constant type for all objfiles.
649 It doesn't depend on languages or anything (arguably its
650 name should be a language-specific name for a type of
651 that size, but I'm inclined to say that if the compiler
652 wants a nice name for the type, it can use 'e'). */
653 static struct type
*int_const_type
;
655 /* Yes, this is as long as a *host* int. That is because we
657 if (int_const_type
== NULL
)
659 init_type (TYPE_CODE_INT
,
660 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
662 (struct objfile
*)NULL
);
663 SYMBOL_TYPE (sym
) = int_const_type
;
664 SYMBOL_VALUE (sym
) = atoi (p
);
665 SYMBOL_CLASS (sym
) = LOC_CONST
;
669 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
670 can be represented as integral.
671 e.g. "b:c=e6,0" for "const b = blob1"
672 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
674 SYMBOL_CLASS (sym
) = LOC_CONST
;
675 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
679 SYMBOL_TYPE (sym
) = error_type (&p
);
684 /* If the value is too big to fit in an int (perhaps because
685 it is unsigned), or something like that, we silently get
686 a bogus value. The type and everything else about it is
687 correct. Ideally, we should be using whatever we have
688 available for parsing unsigned and long long values,
690 SYMBOL_VALUE (sym
) = atoi (p
);
695 SYMBOL_CLASS (sym
) = LOC_CONST
;
696 SYMBOL_TYPE (sym
) = error_type (&p
);
699 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
700 add_symbol_to_list (sym
, &file_symbols
);
704 /* The name of a caught exception. */
705 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
706 SYMBOL_CLASS (sym
) = LOC_LABEL
;
707 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
708 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
709 add_symbol_to_list (sym
, &local_symbols
);
713 /* A static function definition. */
714 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
715 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
716 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
717 add_symbol_to_list (sym
, &file_symbols
);
718 /* fall into process_function_types. */
720 process_function_types
:
721 /* Function result types are described as the result type in stabs.
722 We need to convert this to the function-returning-type-X type
723 in GDB. E.g. "int" is converted to "function returning int". */
724 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
727 /* This code doesn't work -- it needs to realloc and can't. */
728 /* Attempt to set up to record a function prototype... */
729 struct type
*new = alloc_type (objfile
);
731 /* Generate a template for the type of this function. The
732 types of the arguments will be added as we read the symbol
734 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
735 SYMBOL_TYPE(sym
) = new;
736 TYPE_OBJFILE (new) = objfile
;
737 in_function_type
= new;
739 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
742 /* fall into process_prototype_types */
744 process_prototype_types
:
745 /* Sun acc puts declared types of arguments here. We don't care
746 about their actual types (FIXME -- we should remember the whole
747 function prototype), but the list may define some new types
748 that we have to remember, so we must scan it now. */
751 read_type (&p
, objfile
);
756 /* A global function definition. */
757 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
758 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
759 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
760 add_symbol_to_list (sym
, &global_symbols
);
761 goto process_function_types
;
764 /* For a class G (global) symbol, it appears that the
765 value is not correct. It is necessary to search for the
766 corresponding linker definition to find the value.
767 These definitions appear at the end of the namelist. */
768 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
769 i
= hashname (SYMBOL_NAME (sym
));
770 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
771 global_sym_chain
[i
] = sym
;
772 SYMBOL_CLASS (sym
) = LOC_STATIC
;
773 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
774 add_symbol_to_list (sym
, &global_symbols
);
777 /* This case is faked by a conditional above,
778 when there is no code letter in the dbx data.
779 Dbx data never actually contains 'l'. */
781 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
782 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
783 SYMBOL_VALUE (sym
) = valu
;
784 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
785 add_symbol_to_list (sym
, &local_symbols
);
790 /* pF is a two-letter code that means a function parameter in Fortran.
791 The type-number specifies the type of the return value.
792 Translate it into a pointer-to-function type. */
796 = lookup_pointer_type
797 (lookup_function_type (read_type (&p
, objfile
)));
800 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
802 /* Normally this is a parameter, a LOC_ARG. On the i960, it
803 can also be a LOC_LOCAL_ARG depending on symbol type. */
804 #ifndef DBX_PARM_SYMBOL_CLASS
805 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
808 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
809 SYMBOL_VALUE (sym
) = valu
;
810 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
812 /* This doesn't work yet. */
813 add_param_to_type (&in_function_type
, sym
);
815 add_symbol_to_list (sym
, &local_symbols
);
817 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
818 /* On little-endian machines, this crud is never necessary, and,
819 if the extra bytes contain garbage, is harmful. */
821 #else /* Big endian. */
822 /* If it's gcc-compiled, if it says `short', believe it. */
823 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
826 #if !BELIEVE_PCC_PROMOTION
828 /* This is the signed type which arguments get promoted to. */
829 static struct type
*pcc_promotion_type
;
830 /* This is the unsigned type which arguments get promoted to. */
831 static struct type
*pcc_unsigned_promotion_type
;
833 /* Call it "int" because this is mainly C lossage. */
834 if (pcc_promotion_type
== NULL
)
836 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
839 if (pcc_unsigned_promotion_type
== NULL
)
840 pcc_unsigned_promotion_type
=
841 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
842 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
844 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
845 /* This macro is defined on machines (e.g. sparc) where
846 we should believe the type of a PCC 'short' argument,
847 but shouldn't believe the address (the address is
848 the address of the corresponding int).
850 My guess is that this correction, as opposed to changing
851 the parameter to an 'int' (as done below, for PCC
852 on most machines), is the right thing to do
853 on all machines, but I don't want to risk breaking
854 something that already works. On most PCC machines,
855 the sparc problem doesn't come up because the calling
856 function has to zero the top bytes (not knowing whether
857 the called function wants an int or a short), so there
858 is little practical difference between an int and a short
859 (except perhaps what happens when the GDB user types
860 "print short_arg = 0x10000;").
862 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
863 actually produces the correct address (we don't need to fix it
864 up). I made this code adapt so that it will offset the symbol
865 if it was pointing at an int-aligned location and not
866 otherwise. This way you can use the same gdb for 4.0.x and
869 If the parameter is shorter than an int, and is integral
870 (e.g. char, short, or unsigned equivalent), and is claimed to
871 be passed on an integer boundary, don't believe it! Offset the
872 parameter's address to the tail-end of that integer. */
874 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
875 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
876 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
878 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
879 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
883 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
885 /* If PCC says a parameter is a short or a char,
886 it is really an int. */
887 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
888 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
891 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
892 ? pcc_unsigned_promotion_type
893 : pcc_promotion_type
;
897 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
899 #endif /* !BELIEVE_PCC_PROMOTION. */
900 #endif /* Big endian. */
903 /* acc seems to use P to delare the prototypes of functions that
904 are referenced by this file. gdb is not prepared to deal
905 with this extra information. FIXME, it ought to. */
908 read_type (&p
, objfile
);
909 goto process_prototype_types
;
914 /* Parameter which is in a register. */
915 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
916 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
917 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
918 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
920 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
921 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
923 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
924 add_symbol_to_list (sym
, &local_symbols
);
928 /* Register variable (either global or local). */
929 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
930 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
931 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
932 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
934 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
935 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
937 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
940 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
941 name to represent an argument passed in a register.
942 GCC uses 'P' for the same case. So if we find such a symbol pair
943 we combine it into one 'P' symbol.
944 Note that this code illegally combines
945 main(argc) int argc; { register int argc = 1; }
946 but this case is considered pathological and causes a warning
947 from a decent compiler. */
949 && local_symbols
->nsyms
> 0)
951 struct symbol
*prev_sym
;
952 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
953 if (SYMBOL_CLASS (prev_sym
) == LOC_ARG
954 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
956 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
957 /* Use the type from the LOC_REGISTER; that is the type
958 that is actually in that register. */
959 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
960 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
965 add_symbol_to_list (sym
, &local_symbols
);
968 add_symbol_to_list (sym
, &file_symbols
);
972 /* Static symbol at top level of file */
973 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
974 SYMBOL_CLASS (sym
) = LOC_STATIC
;
975 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
976 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
977 add_symbol_to_list (sym
, &file_symbols
);
981 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
983 /* For a nameless type, we don't want a create a symbol, thus we
984 did not use `sym'. Return without further processing. */
985 if (nameless
) return NULL
;
987 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
988 SYMBOL_VALUE (sym
) = valu
;
989 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
990 /* C++ vagaries: we may have a type which is derived from
991 a base type which did not have its name defined when the
992 derived class was output. We fill in the derived class's
993 base part member's name here in that case. */
994 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
995 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
996 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
997 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1000 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1001 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1002 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1003 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1006 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1008 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1009 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1011 /* If we are giving a name to a type such as "pointer to
1012 foo" or "function returning foo", we better not set
1013 the TYPE_NAME. If the program contains "typedef char
1014 *caddr_t;", we don't want all variables of type char
1015 * to print as caddr_t. This is not just a
1016 consequence of GDB's type management; PCC and GCC (at
1017 least through version 2.4) both output variables of
1018 either type char * or caddr_t with the type number
1019 defined in the 't' symbol for caddr_t. If a future
1020 compiler cleans this up it GDB is not ready for it
1021 yet, but if it becomes ready we somehow need to
1022 disable this check (without breaking the PCC/GCC2.4
1027 Fortunately, this check seems not to be necessary
1028 for anything except pointers or functions. */
1031 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1034 add_symbol_to_list (sym
, &file_symbols
);
1038 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1039 by 't' which means we are typedef'ing it as well. */
1040 synonym
= *p
== 't';
1045 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1046 strlen (SYMBOL_NAME (sym
)),
1047 &objfile
-> symbol_obstack
);
1049 /* The semantics of C++ state that "struct foo { ... }" also defines
1050 a typedef for "foo". Unfortunately, cfront never makes the typedef
1051 when translating C++ into C. We make the typedef here so that
1052 "ptype foo" works as expected for cfront translated code. */
1053 else if (current_subfile
->language
== language_cplus
)
1056 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1057 strlen (SYMBOL_NAME (sym
)),
1058 &objfile
-> symbol_obstack
);
1061 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1063 /* For a nameless type, we don't want a create a symbol, thus we
1064 did not use `sym'. Return without further processing. */
1065 if (nameless
) return NULL
;
1067 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1068 SYMBOL_VALUE (sym
) = valu
;
1069 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1070 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1071 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1072 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1073 add_symbol_to_list (sym
, &file_symbols
);
1077 /* Clone the sym and then modify it. */
1078 register struct symbol
*typedef_sym
= (struct symbol
*)
1079 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1080 *typedef_sym
= *sym
;
1081 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1082 SYMBOL_VALUE (typedef_sym
) = valu
;
1083 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1084 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1085 TYPE_NAME (SYMBOL_TYPE (sym
))
1086 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1087 add_symbol_to_list (typedef_sym
, &file_symbols
);
1092 /* Static symbol of local scope */
1093 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1094 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1095 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1096 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1097 add_symbol_to_list (sym
, &local_symbols
);
1101 /* Reference parameter */
1102 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1103 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1104 SYMBOL_VALUE (sym
) = valu
;
1105 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1106 add_symbol_to_list (sym
, &local_symbols
);
1110 /* This is used by Sun FORTRAN for "function result value".
1111 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1112 that Pascal uses it too, but when I tried it Pascal used
1113 "x:3" (local symbol) instead. */
1114 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1115 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1116 SYMBOL_VALUE (sym
) = valu
;
1117 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1118 add_symbol_to_list (sym
, &local_symbols
);
1122 SYMBOL_TYPE (sym
) = error_type (&p
);
1123 SYMBOL_CLASS (sym
) = LOC_CONST
;
1124 SYMBOL_VALUE (sym
) = 0;
1125 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1126 add_symbol_to_list (sym
, &file_symbols
);
1130 /* When passing structures to a function, some systems sometimes pass
1131 the address in a register, not the structure itself.
1133 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1134 to LOC_REGPARM_ADDR for structures and unions. */
1136 #if !defined (REG_STRUCT_HAS_ADDR)
1137 #define REG_STRUCT_HAS_ADDR(gcc_p) 0
1140 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1141 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
)
1142 && ( (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1143 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1144 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1150 /* Skip rest of this symbol and return an error type.
1152 General notes on error recovery: error_type always skips to the
1153 end of the symbol (modulo cretinous dbx symbol name continuation).
1154 Thus code like this:
1156 if (*(*pp)++ != ';')
1157 return error_type (pp);
1159 is wrong because if *pp starts out pointing at '\0' (typically as the
1160 result of an earlier error), it will be incremented to point to the
1161 start of the next symbol, which might produce strange results, at least
1162 if you run off the end of the string table. Instead use
1165 return error_type (pp);
1171 foo = error_type (pp);
1175 And in case it isn't obvious, the point of all this hair is so the compiler
1176 can define new types and new syntaxes, and old versions of the
1177 debugger will be able to read the new symbol tables. */
1179 static struct type
*
1183 complain (&error_type_complaint
);
1186 /* Skip to end of symbol. */
1187 while (**pp
!= '\0')
1192 /* Check for and handle cretinous dbx symbol name continuation! */
1193 if ((*pp
)[-1] == '\\')
1195 *pp
= next_symbol_text ();
1202 return (builtin_type_error
);
1206 /* Read type information or a type definition; return the type. Even
1207 though this routine accepts either type information or a type
1208 definition, the distinction is relevant--some parts of stabsread.c
1209 assume that type information starts with a digit, '-', or '(' in
1210 deciding whether to call read_type. */
1213 read_type (pp
, objfile
)
1215 struct objfile
*objfile
;
1217 register struct type
*type
= 0;
1221 char type_descriptor
;
1223 /* Size in bits of type if specified by a type attribute, or -1 if
1224 there is no size attribute. */
1227 /* Read type number if present. The type number may be omitted.
1228 for instance in a two-dimensional array declared with type
1229 "ar1;1;10;ar1;1;10;4". */
1230 if ((**pp
>= '0' && **pp
<= '9')
1234 if (read_type_number (pp
, typenums
) != 0)
1235 return error_type (pp
);
1237 /* Type is not being defined here. Either it already exists,
1238 or this is a forward reference to it. dbx_alloc_type handles
1241 return dbx_alloc_type (typenums
, objfile
);
1243 /* Type is being defined here. */
1250 /* It might be a type attribute or a member type. */
1251 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1256 /* Type attributes. */
1259 /* Skip to the semicolon. */
1260 while (*p
!= ';' && *p
!= '\0')
1264 return error_type (pp
);
1266 /* Skip the semicolon. */
1272 type_size
= atoi (attr
+ 1);
1277 /* Ignore unrecognized type attributes, so future compilers
1278 can invent new ones. */
1283 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1288 /* 'typenums=' not present, type is anonymous. Read and return
1289 the definition, but don't put it in the type vector. */
1290 typenums
[0] = typenums
[1] = -1;
1294 type_descriptor
= (*pp
)[-1];
1295 switch (type_descriptor
)
1299 enum type_code code
;
1301 /* Used to index through file_symbols. */
1302 struct pending
*ppt
;
1305 /* Name including "struct", etc. */
1309 char *from
, *to
, *p
;
1311 /* Set the type code according to the following letter. */
1315 code
= TYPE_CODE_STRUCT
;
1318 code
= TYPE_CODE_UNION
;
1321 code
= TYPE_CODE_ENUM
;
1325 /* Complain and keep going, so compilers can invent new
1326 cross-reference types. */
1327 static struct complaint msg
=
1328 {"Unrecognized cross-reference type `%c'", 0, 0};
1329 complain (&msg
, (*pp
)[0]);
1330 code
= TYPE_CODE_STRUCT
;
1335 p
= strchr(*pp
, ':');
1337 return error_type (pp
);
1343 return error_type (pp
);
1346 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1348 /* Copy the name. */
1354 /* Set the pointer ahead of the name which we just read, and
1359 /* Now check to see whether the type has already been declared. */
1360 /* This is necessary at least in the case where the
1361 program says something like
1363 The compiler puts out a cross-reference; we better find
1364 set the length of the structure correctly so we can
1365 set the length of the array. */
1366 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1367 for (i
= 0; i
< ppt
->nsyms
; i
++)
1369 struct symbol
*sym
= ppt
->symbol
[i
];
1371 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1372 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1373 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1374 && STREQ (SYMBOL_NAME (sym
), type_name
))
1376 obstack_free (&objfile
-> type_obstack
, type_name
);
1377 type
= SYMBOL_TYPE (sym
);
1382 /* Didn't find the type to which this refers, so we must
1383 be dealing with a forward reference. Allocate a type
1384 structure for it, and keep track of it so we can
1385 fill in the rest of the fields when we get the full
1387 type
= dbx_alloc_type (typenums
, objfile
);
1388 TYPE_CODE (type
) = code
;
1389 TYPE_TAG_NAME (type
) = type_name
;
1390 INIT_CPLUS_SPECIFIC(type
);
1391 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1393 add_undefined_type (type
);
1397 case '-': /* RS/6000 built-in type */
1411 if (read_type_number (pp
, xtypenums
) != 0)
1412 return error_type (pp
);
1414 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1415 /* It's being defined as itself. That means it is "void". */
1416 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
1419 struct type
*xtype
= *dbx_lookup_type (xtypenums
);
1421 /* This can happen if we had '-' followed by a garbage character,
1424 return error_type (pp
);
1426 /* The type is being defined to another type. So we copy the type.
1427 This loses if we copy a C++ class and so we lose track of how
1428 the names are mangled (but g++ doesn't output stabs like this
1431 type
= alloc_type (objfile
);
1432 memcpy (type
, xtype
, sizeof (struct type
));
1434 /* The idea behind clearing the names is that the only purpose
1435 for defining a type to another type is so that the name of
1436 one can be different. So we probably don't need to worry much
1437 about the case where the compiler doesn't give a name to the
1439 TYPE_NAME (type
) = NULL
;
1440 TYPE_TAG_NAME (type
) = NULL
;
1442 if (typenums
[0] != -1)
1443 *dbx_lookup_type (typenums
) = type
;
1446 /* In the following types, we must be sure to overwrite any existing
1447 type that the typenums refer to, rather than allocating a new one
1448 and making the typenums point to the new one. This is because there
1449 may already be pointers to the existing type (if it had been
1450 forward-referenced), and we must change it to a pointer, function,
1451 reference, or whatever, *in-place*. */
1454 type1
= read_type (pp
, objfile
);
1455 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1458 case '&': /* Reference to another type */
1459 type1
= read_type (pp
, objfile
);
1460 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1463 case 'f': /* Function returning another type */
1464 type1
= read_type (pp
, objfile
);
1465 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1468 case 'k': /* Const qualifier on some type (Sun) */
1469 type
= read_type (pp
, objfile
);
1470 /* FIXME! For now, we ignore const and volatile qualifiers. */
1473 case 'B': /* Volatile qual on some type (Sun) */
1474 type
= read_type (pp
, objfile
);
1475 /* FIXME! For now, we ignore const and volatile qualifiers. */
1478 /* FIXME -- we should be doing smash_to_XXX types here. */
1479 case '@': /* Member (class & variable) type */
1481 struct type
*domain
= read_type (pp
, objfile
);
1482 struct type
*memtype
;
1485 /* Invalid member type data format. */
1486 return error_type (pp
);
1489 memtype
= read_type (pp
, objfile
);
1490 type
= dbx_alloc_type (typenums
, objfile
);
1491 smash_to_member_type (type
, domain
, memtype
);
1495 case '#': /* Method (class & fn) type */
1496 if ((*pp
)[0] == '#')
1498 /* We'll get the parameter types from the name. */
1499 struct type
*return_type
;
1502 return_type
= read_type (pp
, objfile
);
1503 if (*(*pp
)++ != ';')
1504 complain (&invalid_member_complaint
, symnum
);
1505 type
= allocate_stub_method (return_type
);
1506 if (typenums
[0] != -1)
1507 *dbx_lookup_type (typenums
) = type
;
1511 struct type
*domain
= read_type (pp
, objfile
);
1512 struct type
*return_type
;
1516 /* Invalid member type data format. */
1517 return error_type (pp
);
1521 return_type
= read_type (pp
, objfile
);
1522 args
= read_args (pp
, ';', objfile
);
1523 type
= dbx_alloc_type (typenums
, objfile
);
1524 smash_to_method_type (type
, domain
, return_type
, args
);
1528 case 'r': /* Range type */
1529 type
= read_range_type (pp
, typenums
, objfile
);
1530 if (typenums
[0] != -1)
1531 *dbx_lookup_type (typenums
) = type
;
1534 case 'b': /* Sun ACC builtin int type */
1535 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1536 if (typenums
[0] != -1)
1537 *dbx_lookup_type (typenums
) = type
;
1540 case 'R': /* Sun ACC builtin float type */
1541 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1542 if (typenums
[0] != -1)
1543 *dbx_lookup_type (typenums
) = type
;
1546 case 'e': /* Enumeration type */
1547 type
= dbx_alloc_type (typenums
, objfile
);
1548 type
= read_enum_type (pp
, type
, objfile
);
1549 if (typenums
[0] != -1)
1550 *dbx_lookup_type (typenums
) = type
;
1553 case 's': /* Struct type */
1554 case 'u': /* Union type */
1555 type
= dbx_alloc_type (typenums
, objfile
);
1556 if (!TYPE_NAME (type
))
1558 TYPE_NAME (type
) = type_synonym_name
;
1560 type_synonym_name
= NULL
;
1561 switch (type_descriptor
)
1564 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1567 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1570 type
= read_struct_type (pp
, type
, objfile
);
1573 case 'a': /* Array type */
1575 return error_type (pp
);
1578 type
= dbx_alloc_type (typenums
, objfile
);
1579 type
= read_array_type (pp
, type
, objfile
);
1583 --*pp
; /* Go back to the symbol in error */
1584 /* Particularly important if it was \0! */
1585 return error_type (pp
);
1590 warning ("GDB internal error, type is NULL in stabsread.c\n");
1591 return error_type (pp
);
1594 /* Size specified in a type attribute overrides any other size. */
1595 if (type_size
!= -1)
1596 TYPE_LENGTH (type
) = type_size
/ TARGET_CHAR_BIT
;
1601 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1602 Return the proper type node for a given builtin type number. */
1604 static struct type
*
1605 rs6000_builtin_type (typenum
)
1608 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1609 #define NUMBER_RECOGNIZED 30
1610 /* This includes an empty slot for type number -0. */
1611 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1612 struct type
*rettype
= NULL
;
1614 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1616 complain (&rs6000_builtin_complaint
, typenum
);
1617 return builtin_type_error
;
1619 if (negative_types
[-typenum
] != NULL
)
1620 return negative_types
[-typenum
];
1622 #if TARGET_CHAR_BIT != 8
1623 #error This code wrong for TARGET_CHAR_BIT not 8
1624 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1625 that if that ever becomes not true, the correct fix will be to
1626 make the size in the struct type to be in bits, not in units of
1633 /* The size of this and all the other types are fixed, defined
1634 by the debugging format. If there is a type called "int" which
1635 is other than 32 bits, then it should use a new negative type
1636 number (or avoid negative type numbers for that case).
1637 See stabs.texinfo. */
1638 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1641 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1644 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1647 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1650 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1651 "unsigned char", NULL
);
1654 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1657 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1658 "unsigned short", NULL
);
1661 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1662 "unsigned int", NULL
);
1665 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1668 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1669 "unsigned long", NULL
);
1672 rettype
= init_type (TYPE_CODE_VOID
, 0, 0, "void", NULL
);
1675 /* IEEE single precision (32 bit). */
1676 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1679 /* IEEE double precision (64 bit). */
1680 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1683 /* This is an IEEE double on the RS/6000, and different machines with
1684 different sizes for "long double" should use different negative
1685 type numbers. See stabs.texinfo. */
1686 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1689 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1692 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1695 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1698 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1701 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1704 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1708 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1712 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1716 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1720 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1724 /* Complex type consisting of two IEEE single precision values. */
1725 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1728 /* Complex type consisting of two IEEE double precision values. */
1729 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1732 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1735 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1738 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1741 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1744 negative_types
[-typenum
] = rettype
;
1748 /* This page contains subroutines of read_type. */
1750 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1751 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1752 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1753 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1755 /* Read member function stabs info for C++ classes. The form of each member
1758 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1760 An example with two member functions is:
1762 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1764 For the case of overloaded operators, the format is op$::*.funcs, where
1765 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1766 name (such as `+=') and `.' marks the end of the operator name.
1768 Returns 1 for success, 0 for failure. */
1771 read_member_functions (fip
, pp
, type
, objfile
)
1772 struct field_info
*fip
;
1775 struct objfile
*objfile
;
1779 /* Total number of member functions defined in this class. If the class
1780 defines two `f' functions, and one `g' function, then this will have
1782 int total_length
= 0;
1786 struct next_fnfield
*next
;
1787 struct fn_field fn_field
;
1789 struct type
*look_ahead_type
;
1790 struct next_fnfieldlist
*new_fnlist
;
1791 struct next_fnfield
*new_sublist
;
1795 /* Process each list until we find something that is not a member function
1796 or find the end of the functions. */
1800 /* We should be positioned at the start of the function name.
1801 Scan forward to find the first ':' and if it is not the
1802 first of a "::" delimiter, then this is not a member function. */
1814 look_ahead_type
= NULL
;
1817 new_fnlist
= (struct next_fnfieldlist
*)
1818 xmalloc (sizeof (struct next_fnfieldlist
));
1819 make_cleanup (free
, new_fnlist
);
1820 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1822 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1824 /* This is a completely wierd case. In order to stuff in the
1825 names that might contain colons (the usual name delimiter),
1826 Mike Tiemann defined a different name format which is
1827 signalled if the identifier is "op$". In that case, the
1828 format is "op$::XXXX." where XXXX is the name. This is
1829 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1830 /* This lets the user type "break operator+".
1831 We could just put in "+" as the name, but that wouldn't
1833 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1834 char *o
= opname
+ 3;
1836 /* Skip past '::'. */
1839 STABS_CONTINUE (pp
);
1845 main_fn_name
= savestring (opname
, o
- opname
);
1851 main_fn_name
= savestring (*pp
, p
- *pp
);
1852 /* Skip past '::'. */
1855 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1860 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1861 make_cleanup (free
, new_sublist
);
1862 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1864 /* Check for and handle cretinous dbx symbol name continuation! */
1865 if (look_ahead_type
== NULL
)
1868 STABS_CONTINUE (pp
);
1870 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1873 /* Invalid symtab info for member function. */
1879 /* g++ version 1 kludge */
1880 new_sublist
-> fn_field
.type
= look_ahead_type
;
1881 look_ahead_type
= NULL
;
1891 /* If this is just a stub, then we don't have the real name here. */
1893 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1895 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
1896 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
1897 new_sublist
-> fn_field
.is_stub
= 1;
1899 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1902 /* Set this member function's visibility fields. */
1905 case VISIBILITY_PRIVATE
:
1906 new_sublist
-> fn_field
.is_private
= 1;
1908 case VISIBILITY_PROTECTED
:
1909 new_sublist
-> fn_field
.is_protected
= 1;
1913 STABS_CONTINUE (pp
);
1916 case 'A': /* Normal functions. */
1917 new_sublist
-> fn_field
.is_const
= 0;
1918 new_sublist
-> fn_field
.is_volatile
= 0;
1921 case 'B': /* `const' member functions. */
1922 new_sublist
-> fn_field
.is_const
= 1;
1923 new_sublist
-> fn_field
.is_volatile
= 0;
1926 case 'C': /* `volatile' member function. */
1927 new_sublist
-> fn_field
.is_const
= 0;
1928 new_sublist
-> fn_field
.is_volatile
= 1;
1931 case 'D': /* `const volatile' member function. */
1932 new_sublist
-> fn_field
.is_const
= 1;
1933 new_sublist
-> fn_field
.is_volatile
= 1;
1936 case '*': /* File compiled with g++ version 1 -- no info */
1941 complain (&const_vol_complaint
, **pp
);
1950 /* virtual member function, followed by index.
1951 The sign bit is set to distinguish pointers-to-methods
1952 from virtual function indicies. Since the array is
1953 in words, the quantity must be shifted left by 1
1954 on 16 bit machine, and by 2 on 32 bit machine, forcing
1955 the sign bit out, and usable as a valid index into
1956 the array. Remove the sign bit here. */
1957 new_sublist
-> fn_field
.voffset
=
1958 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
1962 STABS_CONTINUE (pp
);
1963 if (**pp
== ';' || **pp
== '\0')
1965 /* Must be g++ version 1. */
1966 new_sublist
-> fn_field
.fcontext
= 0;
1970 /* Figure out from whence this virtual function came.
1971 It may belong to virtual function table of
1972 one of its baseclasses. */
1973 look_ahead_type
= read_type (pp
, objfile
);
1976 /* g++ version 1 overloaded methods. */
1980 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1989 look_ahead_type
= NULL
;
1995 /* static member function. */
1996 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
1997 if (strncmp (new_sublist
-> fn_field
.physname
,
1998 main_fn_name
, strlen (main_fn_name
)))
2000 new_sublist
-> fn_field
.is_stub
= 1;
2006 complain (&member_fn_complaint
, (*pp
)[-1]);
2007 /* Fall through into normal member function. */
2010 /* normal member function. */
2011 new_sublist
-> fn_field
.voffset
= 0;
2012 new_sublist
-> fn_field
.fcontext
= 0;
2016 new_sublist
-> next
= sublist
;
2017 sublist
= new_sublist
;
2019 STABS_CONTINUE (pp
);
2021 while (**pp
!= ';' && **pp
!= '\0');
2025 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2026 obstack_alloc (&objfile
-> type_obstack
,
2027 sizeof (struct fn_field
) * length
);
2028 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2029 sizeof (struct fn_field
) * length
);
2030 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2032 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2035 new_fnlist
-> fn_fieldlist
.length
= length
;
2036 new_fnlist
-> next
= fip
-> fnlist
;
2037 fip
-> fnlist
= new_fnlist
;
2039 total_length
+= length
;
2040 STABS_CONTINUE (pp
);
2045 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2046 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2047 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2048 memset (TYPE_FN_FIELDLISTS (type
), 0,
2049 sizeof (struct fn_fieldlist
) * nfn_fields
);
2050 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2051 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2057 /* Special GNU C++ name.
2059 Returns 1 for success, 0 for failure. "failure" means that we can't
2060 keep parsing and it's time for error_type(). */
2063 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2064 struct field_info
*fip
;
2067 struct objfile
*objfile
;
2072 struct type
*context
;
2082 /* At this point, *pp points to something like "22:23=*22...",
2083 where the type number before the ':' is the "context" and
2084 everything after is a regular type definition. Lookup the
2085 type, find it's name, and construct the field name. */
2087 context
= read_type (pp
, objfile
);
2091 case 'f': /* $vf -- a virtual function table pointer */
2092 fip
->list
->field
.name
=
2093 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2096 case 'b': /* $vb -- a virtual bsomethingorother */
2097 name
= type_name_no_tag (context
);
2100 complain (&invalid_cpp_type_complaint
, symnum
);
2103 fip
->list
->field
.name
=
2104 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2108 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2109 fip
->list
->field
.name
=
2110 obconcat (&objfile
->type_obstack
,
2111 "INVALID_CPLUSPLUS_ABBREV", "", "");
2115 /* At this point, *pp points to the ':'. Skip it and read the
2121 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2124 fip
->list
->field
.type
= read_type (pp
, objfile
);
2126 (*pp
)++; /* Skip the comma. */
2132 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2136 /* This field is unpacked. */
2137 fip
->list
->field
.bitsize
= 0;
2138 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2142 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2143 /* We have no idea what syntax an unrecognized abbrev would have, so
2144 better return 0. If we returned 1, we would need to at least advance
2145 *pp to avoid an infinite loop. */
2152 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2153 struct field_info
*fip
;
2157 struct objfile
*objfile
;
2159 fip
-> list
-> field
.name
=
2160 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2163 /* This means we have a visibility for a field coming. */
2167 fip
-> list
-> visibility
= *(*pp
)++;
2171 /* normal dbx-style format, no explicit visibility */
2172 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2175 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2180 /* Possible future hook for nested types. */
2183 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2189 /* Static class member. */
2190 fip
-> list
-> field
.bitpos
= (long) -1;
2196 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2200 else if (**pp
!= ',')
2202 /* Bad structure-type format. */
2203 complain (&stabs_general_complaint
, "bad structure-type format");
2207 (*pp
)++; /* Skip the comma. */
2211 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2214 complain (&stabs_general_complaint
, "bad structure-type format");
2217 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2220 complain (&stabs_general_complaint
, "bad structure-type format");
2225 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2227 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2228 it is a field which has been optimized out. The correct stab for
2229 this case is to use VISIBILITY_IGNORE, but that is a recent
2230 invention. (2) It is a 0-size array. For example
2231 union { int num; char str[0]; } foo. Printing "<no value>" for
2232 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2233 will continue to work, and a 0-size array as a whole doesn't
2234 have any contents to print.
2236 I suspect this probably could also happen with gcc -gstabs (not
2237 -gstabs+) for static fields, and perhaps other C++ extensions.
2238 Hopefully few people use -gstabs with gdb, since it is intended
2239 for dbx compatibility. */
2241 /* Ignore this field. */
2242 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2246 /* Detect an unpacked field and mark it as such.
2247 dbx gives a bit size for all fields.
2248 Note that forward refs cannot be packed,
2249 and treat enums as if they had the width of ints. */
2251 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2252 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2254 fip
-> list
-> field
.bitsize
= 0;
2256 if ((fip
-> list
-> field
.bitsize
2257 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2258 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2259 && (fip
-> list
-> field
.bitsize
2264 fip
-> list
-> field
.bitpos
% 8 == 0)
2266 fip
-> list
-> field
.bitsize
= 0;
2272 /* Read struct or class data fields. They have the form:
2274 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2276 At the end, we see a semicolon instead of a field.
2278 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2281 The optional VISIBILITY is one of:
2283 '/0' (VISIBILITY_PRIVATE)
2284 '/1' (VISIBILITY_PROTECTED)
2285 '/2' (VISIBILITY_PUBLIC)
2286 '/9' (VISIBILITY_IGNORE)
2288 or nothing, for C style fields with public visibility.
2290 Returns 1 for success, 0 for failure. */
2293 read_struct_fields (fip
, pp
, type
, objfile
)
2294 struct field_info
*fip
;
2297 struct objfile
*objfile
;
2300 struct nextfield
*new;
2302 /* We better set p right now, in case there are no fields at all... */
2306 /* Read each data member type until we find the terminating ';' at the end of
2307 the data member list, or break for some other reason such as finding the
2308 start of the member function list. */
2312 STABS_CONTINUE (pp
);
2313 /* Get space to record the next field's data. */
2314 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2315 make_cleanup (free
, new);
2316 memset (new, 0, sizeof (struct nextfield
));
2317 new -> next
= fip
-> list
;
2320 /* Get the field name. */
2323 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2324 unless the CPLUS_MARKER is followed by an underscore, in
2325 which case it is just the name of an anonymous type, which we
2326 should handle like any other type name. We accept either '$'
2327 or '.', because a field name can never contain one of these
2328 characters except as a CPLUS_MARKER (we probably should be
2329 doing that in most parts of GDB). */
2331 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2333 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2338 /* Look for the ':' that separates the field name from the field
2339 values. Data members are delimited by a single ':', while member
2340 functions are delimited by a pair of ':'s. When we hit the member
2341 functions (if any), terminate scan loop and return. */
2343 while (*p
!= ':' && *p
!= '\0')
2350 /* Check to see if we have hit the member functions yet. */
2355 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2359 /* chill the list of fields: the last entry (at the head) is a
2360 partially constructed entry which we now scrub. */
2361 fip
-> list
= fip
-> list
-> next
;
2366 /* The stabs for C++ derived classes contain baseclass information which
2367 is marked by a '!' character after the total size. This function is
2368 called when we encounter the baseclass marker, and slurps up all the
2369 baseclass information.
2371 Immediately following the '!' marker is the number of base classes that
2372 the class is derived from, followed by information for each base class.
2373 For each base class, there are two visibility specifiers, a bit offset
2374 to the base class information within the derived class, a reference to
2375 the type for the base class, and a terminating semicolon.
2377 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2379 Baseclass information marker __________________|| | | | | | |
2380 Number of baseclasses __________________________| | | | | | |
2381 Visibility specifiers (2) ________________________| | | | | |
2382 Offset in bits from start of class _________________| | | | |
2383 Type number for base class ___________________________| | | |
2384 Visibility specifiers (2) _______________________________| | |
2385 Offset in bits from start of class ________________________| |
2386 Type number of base class ____________________________________|
2388 Return 1 for success, 0 for (error-type-inducing) failure. */
2391 read_baseclasses (fip
, pp
, type
, objfile
)
2392 struct field_info
*fip
;
2395 struct objfile
*objfile
;
2398 struct nextfield
*new;
2406 /* Skip the '!' baseclass information marker. */
2410 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2413 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2419 /* Some stupid compilers have trouble with the following, so break
2420 it up into simpler expressions. */
2421 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2422 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2425 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2428 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2429 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2433 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2435 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2437 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2438 make_cleanup (free
, new);
2439 memset (new, 0, sizeof (struct nextfield
));
2440 new -> next
= fip
-> list
;
2442 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2444 STABS_CONTINUE (pp
);
2448 /* Nothing to do. */
2451 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2454 /* Unknown character. Complain and treat it as non-virtual. */
2456 static struct complaint msg
= {
2457 "Unknown virtual character `%c' for baseclass", 0, 0};
2458 complain (&msg
, **pp
);
2463 new -> visibility
= *(*pp
)++;
2464 switch (new -> visibility
)
2466 case VISIBILITY_PRIVATE
:
2467 case VISIBILITY_PROTECTED
:
2468 case VISIBILITY_PUBLIC
:
2471 /* Bad visibility format. Complain and treat it as
2474 static struct complaint msg
= {
2475 "Unknown visibility `%c' for baseclass", 0, 0};
2476 complain (&msg
, new -> visibility
);
2477 new -> visibility
= VISIBILITY_PUBLIC
;
2484 /* The remaining value is the bit offset of the portion of the object
2485 corresponding to this baseclass. Always zero in the absence of
2486 multiple inheritance. */
2488 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2493 /* The last piece of baseclass information is the type of the
2494 base class. Read it, and remember it's type name as this
2497 new -> field
.type
= read_type (pp
, objfile
);
2498 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2500 /* skip trailing ';' and bump count of number of fields seen */
2509 /* The tail end of stabs for C++ classes that contain a virtual function
2510 pointer contains a tilde, a %, and a type number.
2511 The type number refers to the base class (possibly this class itself) which
2512 contains the vtable pointer for the current class.
2514 This function is called when we have parsed all the method declarations,
2515 so we can look for the vptr base class info. */
2518 read_tilde_fields (fip
, pp
, type
, objfile
)
2519 struct field_info
*fip
;
2522 struct objfile
*objfile
;
2526 STABS_CONTINUE (pp
);
2528 /* If we are positioned at a ';', then skip it. */
2538 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2540 /* Obsolete flags that used to indicate the presence
2541 of constructors and/or destructors. */
2545 /* Read either a '%' or the final ';'. */
2546 if (*(*pp
)++ == '%')
2548 /* The next number is the type number of the base class
2549 (possibly our own class) which supplies the vtable for
2550 this class. Parse it out, and search that class to find
2551 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2552 and TYPE_VPTR_FIELDNO. */
2557 t
= read_type (pp
, objfile
);
2559 while (*p
!= '\0' && *p
!= ';')
2565 /* Premature end of symbol. */
2569 TYPE_VPTR_BASETYPE (type
) = t
;
2570 if (type
== t
) /* Our own class provides vtbl ptr */
2572 for (i
= TYPE_NFIELDS (t
) - 1;
2573 i
>= TYPE_N_BASECLASSES (t
);
2576 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2577 sizeof (vptr_name
) - 1))
2579 TYPE_VPTR_FIELDNO (type
) = i
;
2583 /* Virtual function table field not found. */
2584 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2589 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2600 attach_fn_fields_to_type (fip
, type
)
2601 struct field_info
*fip
;
2602 register struct type
*type
;
2606 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2608 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2610 /* @@ Memory leak on objfile -> type_obstack? */
2613 TYPE_NFN_FIELDS_TOTAL (type
) +=
2614 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2617 for (n
= TYPE_NFN_FIELDS (type
);
2618 fip
-> fnlist
!= NULL
;
2619 fip
-> fnlist
= fip
-> fnlist
-> next
)
2621 --n
; /* Circumvent Sun3 compiler bug */
2622 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2627 /* Create the vector of fields, and record how big it is.
2628 We need this info to record proper virtual function table information
2629 for this class's virtual functions. */
2632 attach_fields_to_type (fip
, type
, objfile
)
2633 struct field_info
*fip
;
2634 register struct type
*type
;
2635 struct objfile
*objfile
;
2637 register int nfields
= 0;
2638 register int non_public_fields
= 0;
2639 register struct nextfield
*scan
;
2641 /* Count up the number of fields that we have, as well as taking note of
2642 whether or not there are any non-public fields, which requires us to
2643 allocate and build the private_field_bits and protected_field_bits
2646 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2649 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2651 non_public_fields
++;
2655 /* Now we know how many fields there are, and whether or not there are any
2656 non-public fields. Record the field count, allocate space for the
2657 array of fields, and create blank visibility bitfields if necessary. */
2659 TYPE_NFIELDS (type
) = nfields
;
2660 TYPE_FIELDS (type
) = (struct field
*)
2661 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2662 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2664 if (non_public_fields
)
2666 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2668 TYPE_FIELD_PRIVATE_BITS (type
) =
2669 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2670 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2672 TYPE_FIELD_PROTECTED_BITS (type
) =
2673 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2674 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2676 TYPE_FIELD_IGNORE_BITS (type
) =
2677 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2678 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2681 /* Copy the saved-up fields into the field vector. Start from the head
2682 of the list, adding to the tail of the field array, so that they end
2683 up in the same order in the array in which they were added to the list. */
2685 while (nfields
-- > 0)
2687 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2688 switch (fip
-> list
-> visibility
)
2690 case VISIBILITY_PRIVATE
:
2691 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2694 case VISIBILITY_PROTECTED
:
2695 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2698 case VISIBILITY_IGNORE
:
2699 SET_TYPE_FIELD_IGNORE (type
, nfields
);
2702 case VISIBILITY_PUBLIC
:
2706 /* Unknown visibility. Complain and treat it as public. */
2708 static struct complaint msg
= {
2709 "Unknown visibility `%c' for field", 0, 0};
2710 complain (&msg
, fip
-> list
-> visibility
);
2714 fip
-> list
= fip
-> list
-> next
;
2719 /* Read the description of a structure (or union type) and return an object
2720 describing the type.
2722 PP points to a character pointer that points to the next unconsumed token
2723 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2724 *PP will point to "4a:1,0,32;;".
2726 TYPE points to an incomplete type that needs to be filled in.
2728 OBJFILE points to the current objfile from which the stabs information is
2729 being read. (Note that it is redundant in that TYPE also contains a pointer
2730 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2733 static struct type
*
2734 read_struct_type (pp
, type
, objfile
)
2737 struct objfile
*objfile
;
2739 struct cleanup
*back_to
;
2740 struct field_info fi
;
2745 back_to
= make_cleanup (null_cleanup
, 0);
2747 INIT_CPLUS_SPECIFIC (type
);
2748 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2750 /* First comes the total size in bytes. */
2754 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2756 return error_type (pp
);
2759 /* Now read the baseclasses, if any, read the regular C struct or C++
2760 class member fields, attach the fields to the type, read the C++
2761 member functions, attach them to the type, and then read any tilde
2762 field (baseclass specifier for the class holding the main vtable). */
2764 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2765 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2766 || !attach_fields_to_type (&fi
, type
, objfile
)
2767 || !read_member_functions (&fi
, pp
, type
, objfile
)
2768 || !attach_fn_fields_to_type (&fi
, type
)
2769 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2771 do_cleanups (back_to
);
2772 return (error_type (pp
));
2775 do_cleanups (back_to
);
2779 /* Read a definition of an array type,
2780 and create and return a suitable type object.
2781 Also creates a range type which represents the bounds of that
2784 static struct type
*
2785 read_array_type (pp
, type
, objfile
)
2787 register struct type
*type
;
2788 struct objfile
*objfile
;
2790 struct type
*index_type
, *element_type
, *range_type
;
2795 /* Format of an array type:
2796 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2799 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2800 for these, produce a type like float[][]. */
2802 index_type
= read_type (pp
, objfile
);
2804 /* Improper format of array type decl. */
2805 return error_type (pp
);
2808 if (!(**pp
>= '0' && **pp
<= '9'))
2813 lower
= read_huge_number (pp
, ';', &nbits
);
2815 return error_type (pp
);
2817 if (!(**pp
>= '0' && **pp
<= '9'))
2822 upper
= read_huge_number (pp
, ';', &nbits
);
2824 return error_type (pp
);
2826 element_type
= read_type (pp
, objfile
);
2835 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2836 type
= create_array_type (type
, element_type
, range_type
);
2838 /* If we have an array whose element type is not yet known, but whose
2839 bounds *are* known, record it to be adjusted at the end of the file. */
2841 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2843 add_undefined_type (type
);
2850 /* Read a definition of an enumeration type,
2851 and create and return a suitable type object.
2852 Also defines the symbols that represent the values of the type. */
2854 static struct type
*
2855 read_enum_type (pp
, type
, objfile
)
2857 register struct type
*type
;
2858 struct objfile
*objfile
;
2863 register struct symbol
*sym
;
2865 struct pending
**symlist
;
2866 struct pending
*osyms
, *syms
;
2870 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2871 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2872 to do? For now, force all enum values to file scope. */
2873 if (within_function
)
2874 symlist
= &local_symbols
;
2877 symlist
= &file_symbols
;
2879 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2881 /* Read the value-names and their values.
2882 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2883 A semicolon or comma instead of a NAME means the end. */
2884 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2887 STABS_CONTINUE (pp
);
2889 while (*p
!= ':') p
++;
2890 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2892 n
= read_huge_number (pp
, ',', &nbits
);
2894 return error_type (pp
);
2896 sym
= (struct symbol
*)
2897 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2898 memset (sym
, 0, sizeof (struct symbol
));
2899 SYMBOL_NAME (sym
) = name
;
2900 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
2901 SYMBOL_CLASS (sym
) = LOC_CONST
;
2902 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2903 SYMBOL_VALUE (sym
) = n
;
2904 add_symbol_to_list (sym
, symlist
);
2909 (*pp
)++; /* Skip the semicolon. */
2911 /* Now fill in the fields of the type-structure. */
2913 TYPE_LENGTH (type
) = sizeof (int);
2914 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2915 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2916 TYPE_NFIELDS (type
) = nsyms
;
2917 TYPE_FIELDS (type
) = (struct field
*)
2918 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2919 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2921 /* Find the symbols for the values and put them into the type.
2922 The symbols can be found in the symlist that we put them on
2923 to cause them to be defined. osyms contains the old value
2924 of that symlist; everything up to there was defined by us. */
2925 /* Note that we preserve the order of the enum constants, so
2926 that in something like "enum {FOO, LAST_THING=FOO}" we print
2927 FOO, not LAST_THING. */
2929 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2934 for (; j
< syms
->nsyms
; j
++,n
++)
2936 struct symbol
*xsym
= syms
->symbol
[j
];
2937 SYMBOL_TYPE (xsym
) = type
;
2938 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2939 TYPE_FIELD_VALUE (type
, n
) = 0;
2940 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2941 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2948 /* This screws up perfectly good C programs with enums. FIXME. */
2949 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2950 if(TYPE_NFIELDS(type
) == 2 &&
2951 ((STREQ(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2952 STREQ(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2953 (STREQ(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2954 STREQ(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2955 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2961 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2962 typedefs in every file (for int, long, etc):
2964 type = b <signed> <width>; <offset>; <nbits>
2965 signed = u or s. Possible c in addition to u or s (for char?).
2966 offset = offset from high order bit to start bit of type.
2967 width is # bytes in object of this type, nbits is # bits in type.
2969 The width/offset stuff appears to be for small objects stored in
2970 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2973 static struct type
*
2974 read_sun_builtin_type (pp
, typenums
, objfile
)
2977 struct objfile
*objfile
;
2992 return error_type (pp
);
2996 /* For some odd reason, all forms of char put a c here. This is strange
2997 because no other type has this honor. We can safely ignore this because
2998 we actually determine 'char'acterness by the number of bits specified in
3004 /* The first number appears to be the number of bytes occupied
3005 by this type, except that unsigned short is 4 instead of 2.
3006 Since this information is redundant with the third number,
3007 we will ignore it. */
3008 read_huge_number (pp
, ';', &nbits
);
3010 return error_type (pp
);
3012 /* The second number is always 0, so ignore it too. */
3013 read_huge_number (pp
, ';', &nbits
);
3015 return error_type (pp
);
3017 /* The third number is the number of bits for this type. */
3018 type_bits
= read_huge_number (pp
, 0, &nbits
);
3020 return error_type (pp
);
3022 return init_type (type_bits
== 0 ? TYPE_CODE_VOID
: TYPE_CODE_INT
,
3023 type_bits
/ TARGET_CHAR_BIT
,
3024 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3028 static struct type
*
3029 read_sun_floating_type (pp
, typenums
, objfile
)
3032 struct objfile
*objfile
;
3038 /* The first number has more details about the type, for example
3040 details
= read_huge_number (pp
, ';', &nbits
);
3042 return error_type (pp
);
3044 /* The second number is the number of bytes occupied by this type */
3045 nbytes
= read_huge_number (pp
, ';', &nbits
);
3047 return error_type (pp
);
3049 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3050 || details
== NF_COMPLEX32
)
3051 /* This is a type we can't handle, but we do know the size.
3052 We also will be able to give it a name. */
3053 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3055 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3058 /* Read a number from the string pointed to by *PP.
3059 The value of *PP is advanced over the number.
3060 If END is nonzero, the character that ends the
3061 number must match END, or an error happens;
3062 and that character is skipped if it does match.
3063 If END is zero, *PP is left pointing to that character.
3065 If the number fits in a long, set *BITS to 0 and return the value.
3066 If not, set *BITS to be the number of bits in the number and return 0.
3068 If encounter garbage, set *BITS to -1 and return 0. */
3071 read_huge_number (pp
, end
, bits
)
3091 /* Leading zero means octal. GCC uses this to output values larger
3092 than an int (because that would be hard in decimal). */
3099 upper_limit
= LONG_MAX
/ radix
;
3100 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3102 if (n
<= upper_limit
)
3105 n
+= c
- '0'; /* FIXME this overflows anyway */
3110 /* This depends on large values being output in octal, which is
3117 /* Ignore leading zeroes. */
3121 else if (c
== '2' || c
== '3')
3147 /* Large decimal constants are an error (because it is hard to
3148 count how many bits are in them). */
3154 /* -0x7f is the same as 0x80. So deal with it by adding one to
3155 the number of bits. */
3167 /* It's *BITS which has the interesting information. */
3171 static struct type
*
3172 read_range_type (pp
, typenums
, objfile
)
3175 struct objfile
*objfile
;
3181 struct type
*result_type
;
3182 struct type
*index_type
;
3184 /* First comes a type we are a subrange of.
3185 In C it is usually 0, 1 or the type being defined. */
3186 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3187 not just a type number. */
3188 if (read_type_number (pp
, rangenums
) != 0)
3189 return error_type (pp
);
3190 self_subrange
= (rangenums
[0] == typenums
[0] &&
3191 rangenums
[1] == typenums
[1]);
3193 /* A semicolon should now follow; skip it. */
3197 /* The remaining two operands are usually lower and upper bounds
3198 of the range. But in some special cases they mean something else. */
3199 n2
= read_huge_number (pp
, ';', &n2bits
);
3200 n3
= read_huge_number (pp
, ';', &n3bits
);
3202 if (n2bits
== -1 || n3bits
== -1)
3203 return error_type (pp
);
3205 /* If limits are huge, must be large integral type. */
3206 if (n2bits
!= 0 || n3bits
!= 0)
3208 char got_signed
= 0;
3209 char got_unsigned
= 0;
3210 /* Number of bits in the type. */
3213 /* Range from 0 to <large number> is an unsigned large integral type. */
3214 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3219 /* Range from <large number> to <large number>-1 is a large signed
3220 integral type. Take care of the case where <large number> doesn't
3221 fit in a long but <large number>-1 does. */
3222 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3223 || (n2bits
!= 0 && n3bits
== 0
3224 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3231 if (got_signed
|| got_unsigned
)
3233 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3234 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3238 return error_type (pp
);
3241 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3242 if (self_subrange
&& n2
== 0 && n3
== 0)
3243 return init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
3245 /* If n3 is zero and n2 is not, we want a floating type,
3246 and n2 is the width in bytes.
3248 Fortran programs appear to use this for complex types also,
3249 and they give no way to distinguish between double and single-complex!
3251 GDB does not have complex types.
3253 Just return the complex as a float of that size. It won't work right
3254 for the complex values, but at least it makes the file loadable. */
3256 if (n3
== 0 && n2
> 0)
3258 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3261 /* If the upper bound is -1, it must really be an unsigned int. */
3263 else if (n2
== 0 && n3
== -1)
3265 /* It is unsigned int or unsigned long. */
3266 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3267 compatibility hack. */
3268 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3269 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3272 /* Special case: char is defined (Who knows why) as a subrange of
3273 itself with range 0-127. */
3274 else if (self_subrange
&& n2
== 0 && n3
== 127)
3275 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3277 /* We used to do this only for subrange of self or subrange of int. */
3281 /* n3 actually gives the size. */
3282 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3285 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3287 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3289 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3290 "unsigned long", and we already checked for that,
3291 so don't need to test for it here. */
3293 /* I think this is for Convex "long long". Since I don't know whether
3294 Convex sets self_subrange, I also accept that particular size regardless
3295 of self_subrange. */
3296 else if (n3
== 0 && n2
< 0
3298 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3299 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3300 else if (n2
== -n3
-1)
3303 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3305 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3306 if (n3
== 0x7fffffff)
3307 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3310 /* We have a real range type on our hands. Allocate space and
3311 return a real pointer. */
3313 /* At this point I don't have the faintest idea how to deal with
3314 a self_subrange type; I'm going to assume that this is used
3315 as an idiom, and that all of them are special cases. So . . . */
3317 return error_type (pp
);
3319 index_type
= *dbx_lookup_type (rangenums
);
3320 if (index_type
== NULL
)
3322 /* Does this actually ever happen? Is that why we are worrying
3323 about dealing with it rather than just calling error_type? */
3325 static struct type
*range_type_index
;
3327 complain (&range_type_base_complaint
, rangenums
[1]);
3328 if (range_type_index
== NULL
)
3330 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3331 0, "range type index type", NULL
);
3332 index_type
= range_type_index
;
3335 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3336 return (result_type
);
3339 /* Read in an argument list. This is a list of types, separated by commas
3340 and terminated with END. Return the list of types read in, or (struct type
3341 **)-1 if there is an error. */
3343 static struct type
**
3344 read_args (pp
, end
, objfile
)
3347 struct objfile
*objfile
;
3349 /* FIXME! Remove this arbitrary limit! */
3350 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3356 /* Invalid argument list: no ','. */
3357 return (struct type
**)-1;
3359 STABS_CONTINUE (pp
);
3360 types
[n
++] = read_type (pp
, objfile
);
3362 (*pp
)++; /* get past `end' (the ':' character) */
3366 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3368 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3370 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3371 memset (rval
+ n
, 0, sizeof (struct type
*));
3375 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3377 memcpy (rval
, types
, n
* sizeof (struct type
*));
3381 /* Common block handling. */
3383 /* List of symbols declared since the last BCOMM. This list is a tail
3384 of local_symbols. When ECOMM is seen, the symbols on the list
3385 are noted so their proper addresses can be filled in later,
3386 using the common block base address gotten from the assembler
3389 static struct pending
*common_block
;
3390 static int common_block_i
;
3392 /* Name of the current common block. We get it from the BCOMM instead of the
3393 ECOMM to match IBM documentation (even though IBM puts the name both places
3394 like everyone else). */
3395 static char *common_block_name
;
3397 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3398 to remain after this function returns. */
3401 common_block_start (name
, objfile
)
3403 struct objfile
*objfile
;
3405 if (common_block_name
!= NULL
)
3407 static struct complaint msg
= {
3408 "Invalid symbol data: common block within common block",
3412 common_block
= local_symbols
;
3413 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3414 common_block_name
= obsavestring (name
, strlen (name
),
3415 &objfile
-> symbol_obstack
);
3418 /* Process a N_ECOMM symbol. */
3421 common_block_end (objfile
)
3422 struct objfile
*objfile
;
3424 /* Symbols declared since the BCOMM are to have the common block
3425 start address added in when we know it. common_block and
3426 common_block_i point to the first symbol after the BCOMM in
3427 the local_symbols list; copy the list and hang it off the
3428 symbol for the common block name for later fixup. */
3431 struct pending
*new = 0;
3432 struct pending
*next
;
3435 if (common_block_name
== NULL
)
3437 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
3442 sym
= (struct symbol
*)
3443 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3444 memset (sym
, 0, sizeof (struct symbol
));
3445 SYMBOL_NAME (sym
) = common_block_name
;
3446 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3448 /* Now we copy all the symbols which have been defined since the BCOMM. */
3450 /* Copy all the struct pendings before common_block. */
3451 for (next
= local_symbols
;
3452 next
!= NULL
&& next
!= common_block
;
3455 for (j
= 0; j
< next
->nsyms
; j
++)
3456 add_symbol_to_list (next
->symbol
[j
], &new);
3459 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3460 NULL, it means copy all the local symbols (which we already did
3463 if (common_block
!= NULL
)
3464 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
3465 add_symbol_to_list (common_block
->symbol
[j
], &new);
3467 SYMBOL_NAMESPACE (sym
) = (enum namespace)((long) new);
3469 /* Should we be putting local_symbols back to what it was?
3472 i
= hashname (SYMBOL_NAME (sym
));
3473 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3474 global_sym_chain
[i
] = sym
;
3475 common_block_name
= NULL
;
3478 /* Add a common block's start address to the offset of each symbol
3479 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3480 the common block name). */
3483 fix_common_block (sym
, valu
)
3487 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3488 for ( ; next
; next
= next
->next
)
3491 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3492 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3498 /* What about types defined as forward references inside of a small lexical
3500 /* Add a type to the list of undefined types to be checked through
3501 once this file has been read in. */
3504 add_undefined_type (type
)
3507 if (undef_types_length
== undef_types_allocated
)
3509 undef_types_allocated
*= 2;
3510 undef_types
= (struct type
**)
3511 xrealloc ((char *) undef_types
,
3512 undef_types_allocated
* sizeof (struct type
*));
3514 undef_types
[undef_types_length
++] = type
;
3517 /* Go through each undefined type, see if it's still undefined, and fix it
3518 up if possible. We have two kinds of undefined types:
3520 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3521 Fix: update array length using the element bounds
3522 and the target type's length.
3523 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3524 yet defined at the time a pointer to it was made.
3525 Fix: Do a full lookup on the struct/union tag. */
3527 cleanup_undefined_types ()
3531 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3533 switch (TYPE_CODE (*type
))
3536 case TYPE_CODE_STRUCT
:
3537 case TYPE_CODE_UNION
:
3538 case TYPE_CODE_ENUM
:
3540 /* Check if it has been defined since. */
3541 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3543 struct pending
*ppt
;
3545 /* Name of the type, without "struct" or "union" */
3546 char *typename
= TYPE_TAG_NAME (*type
);
3548 if (typename
== NULL
)
3550 static struct complaint msg
= {"need a type name", 0, 0};
3554 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3556 for (i
= 0; i
< ppt
->nsyms
; i
++)
3558 struct symbol
*sym
= ppt
->symbol
[i
];
3560 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3561 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3562 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3564 && STREQ (SYMBOL_NAME (sym
), typename
))
3566 memcpy (*type
, SYMBOL_TYPE (sym
),
3567 sizeof (struct type
));
3575 case TYPE_CODE_ARRAY
:
3577 struct type
*range_type
;
3580 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3582 if (TYPE_NFIELDS (*type
) != 1)
3584 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3585 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3588 /* Now recompute the length of the array type, based on its
3589 number of elements and the target type's length. */
3590 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3591 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3592 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3593 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3600 static struct complaint msg
= {"\
3601 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3602 complain (&msg
, TYPE_CODE (*type
));
3607 undef_types_length
= 0;
3610 /* Scan through all of the global symbols defined in the object file,
3611 assigning values to the debugging symbols that need to be assigned
3612 to. Get these symbols from the minimal symbol table. */
3615 scan_file_globals (objfile
)
3616 struct objfile
*objfile
;
3619 struct minimal_symbol
*msymbol
;
3620 struct symbol
*sym
, *prev
;
3622 if (objfile
->msymbols
== 0) /* Beware the null file. */
3625 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3631 /* Get the hash index and check all the symbols
3632 under that hash index. */
3634 hash
= hashname (SYMBOL_NAME (msymbol
));
3636 for (sym
= global_sym_chain
[hash
]; sym
;)
3638 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3639 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3641 /* Splice this symbol out of the hash chain and
3642 assign the value we have to it. */
3645 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3649 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3652 /* Check to see whether we need to fix up a common block. */
3653 /* Note: this code might be executed several times for
3654 the same symbol if there are multiple references. */
3656 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3658 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3662 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3667 sym
= SYMBOL_VALUE_CHAIN (prev
);
3671 sym
= global_sym_chain
[hash
];
3677 sym
= SYMBOL_VALUE_CHAIN (sym
);
3683 /* Initialize anything that needs initializing when starting to read
3684 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3692 /* Initialize anything that needs initializing when a completely new
3693 symbol file is specified (not just adding some symbols from another
3694 file, e.g. a shared library). */
3697 stabsread_new_init ()
3699 /* Empty the hash table of global syms looking for values. */
3700 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3703 /* Initialize anything that needs initializing at the same time as
3704 start_symtab() is called. */
3708 global_stabs
= NULL
; /* AIX COFF */
3709 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3710 n_this_object_header_files
= 1;
3711 type_vector_length
= 0;
3712 type_vector
= (struct type
**) 0;
3714 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3715 common_block_name
= NULL
;
3718 /* Call after end_symtab() */
3724 free ((char *) type_vector
);
3727 type_vector_length
= 0;
3728 previous_stab_code
= 0;
3732 finish_global_stabs (objfile
)
3733 struct objfile
*objfile
;
3737 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3738 free ((PTR
) global_stabs
);
3739 global_stabs
= NULL
;
3743 /* Initializer for this module */
3746 _initialize_stabsread ()
3748 undef_types_allocated
= 20;
3749 undef_types_length
= 0;
3750 undef_types
= (struct type
**)
3751 xmalloc (undef_types_allocated
* sizeof (struct type
*));