1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
35 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
37 #include "complaints.h"
42 /* Ask stabsread.h to define the vars it normally declares `extern'. */
44 #include "stabsread.h" /* Our own declarations */
47 /* The routines that read and process a complete stabs for a C struct or
48 C++ class pass lists of data member fields and lists of member function
49 fields in an instance of a field_info structure, as defined below.
50 This is part of some reorganization of low level C++ support and is
51 expected to eventually go away... (FIXME) */
57 struct nextfield
*next
;
59 /* This is the raw visibility from the stab. It is not checked
60 for being one of the visibilities we recognize, so code which
61 examines this field better be able to deal. */
66 struct next_fnfieldlist
68 struct next_fnfieldlist
*next
;
69 struct fn_fieldlist fn_fieldlist
;
74 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
76 static long read_huge_number
PARAMS ((char **, int, int *));
78 static struct type
*error_type
PARAMS ((char **));
81 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
85 fix_common_block
PARAMS ((struct symbol
*, int));
88 read_type_number
PARAMS ((char **, int *));
91 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
94 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
97 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
100 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
103 rs6000_builtin_type
PARAMS ((int));
106 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
110 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
114 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
118 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
122 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
125 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
129 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
132 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
134 static struct type
**
135 read_args
PARAMS ((char **, int, struct objfile
*));
138 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
141 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
142 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
144 /* Define this as 1 if a pcc declaration of a char or short argument
145 gives the correct address. Otherwise assume pcc gives the
146 address of the corresponding int, which is not the same on a
147 big-endian machine. */
149 #ifndef BELIEVE_PCC_PROMOTION
150 #define BELIEVE_PCC_PROMOTION 0
153 struct complaint invalid_cpp_abbrev_complaint
=
154 {"invalid C++ abbreviation `%s'", 0, 0};
156 struct complaint invalid_cpp_type_complaint
=
157 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
159 struct complaint member_fn_complaint
=
160 {"member function type missing, got '%c'", 0, 0};
162 struct complaint const_vol_complaint
=
163 {"const/volatile indicator missing, got '%c'", 0, 0};
165 struct complaint error_type_complaint
=
166 {"debug info mismatch between compiler and debugger", 0, 0};
168 struct complaint invalid_member_complaint
=
169 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
171 struct complaint range_type_base_complaint
=
172 {"base type %d of range type is not defined", 0, 0};
174 struct complaint reg_value_complaint
=
175 {"register number too large in symbol %s", 0, 0};
177 struct complaint vtbl_notfound_complaint
=
178 {"virtual function table pointer not found when defining class `%s'", 0, 0};
180 struct complaint unrecognized_cplus_name_complaint
=
181 {"Unknown C++ symbol name `%s'", 0, 0};
183 struct complaint rs6000_builtin_complaint
=
184 {"Unknown builtin type %d", 0, 0};
186 struct complaint stabs_general_complaint
=
189 /* Make a list of forward references which haven't been defined. */
191 static struct type
**undef_types
;
192 static int undef_types_allocated
;
193 static int undef_types_length
;
195 /* Check for and handle cretinous stabs symbol name continuation! */
196 #define STABS_CONTINUE(pp) \
198 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
199 *(pp) = next_symbol_text (); \
202 /* FIXME: These probably should be our own types (like rs6000_builtin_type
203 has its own types) rather than builtin_type_*. */
204 static struct type
**os9k_type_vector
[] = {
210 &builtin_type_unsigned_char
,
211 &builtin_type_unsigned_short
,
212 &builtin_type_unsigned_long
,
213 &builtin_type_unsigned_int
,
215 &builtin_type_double
,
217 &builtin_type_long_double
220 static void os9k_init_type_vector
PARAMS ((struct type
**));
223 os9k_init_type_vector(tv
)
227 for (i
=0; i
<sizeof(os9k_type_vector
)/sizeof(struct type
**); i
++)
228 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
231 /* Look up a dbx type-number pair. Return the address of the slot
232 where the type for that number-pair is stored.
233 The number-pair is in TYPENUMS.
235 This can be used for finding the type associated with that pair
236 or for associating a new type with the pair. */
239 dbx_lookup_type (typenums
)
242 register int filenum
= typenums
[0];
243 register int index
= typenums
[1];
245 register int real_filenum
;
246 register struct header_file
*f
;
249 if (filenum
== -1) /* -1,-1 is for temporary types. */
252 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
254 static struct complaint msg
= {"\
255 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
257 complain (&msg
, filenum
, index
, symnum
);
265 /* Caller wants address of address of type. We think
266 that negative (rs6k builtin) types will never appear as
267 "lvalues", (nor should they), so we stuff the real type
268 pointer into a temp, and return its address. If referenced,
269 this will do the right thing. */
270 static struct type
*temp_type
;
272 temp_type
= rs6000_builtin_type(index
);
276 /* Type is defined outside of header files.
277 Find it in this object file's type vector. */
278 if (index
>= type_vector_length
)
280 old_len
= type_vector_length
;
283 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
284 type_vector
= (struct type
**)
285 malloc (type_vector_length
* sizeof (struct type
*));
287 while (index
>= type_vector_length
)
289 type_vector_length
*= 2;
291 type_vector
= (struct type
**)
292 xrealloc ((char *) type_vector
,
293 (type_vector_length
* sizeof (struct type
*)));
294 memset (&type_vector
[old_len
], 0,
295 (type_vector_length
- old_len
) * sizeof (struct type
*));
298 /* Deal with OS9000 fundamental types. */
299 os9k_init_type_vector (type_vector
);
301 return (&type_vector
[index
]);
305 real_filenum
= this_object_header_files
[filenum
];
307 if (real_filenum
>= n_header_files
)
309 struct type
*temp_type
;
310 struct type
**temp_type_p
;
312 warning ("GDB internal error: bad real_filenum");
315 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
316 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
317 *temp_type_p
= temp_type
;
321 f
= &header_files
[real_filenum
];
323 f_orig_length
= f
->length
;
324 if (index
>= f_orig_length
)
326 while (index
>= f
->length
)
330 f
->vector
= (struct type
**)
331 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
332 memset (&f
->vector
[f_orig_length
], 0,
333 (f
->length
- f_orig_length
) * sizeof (struct type
*));
335 return (&f
->vector
[index
]);
339 /* Make sure there is a type allocated for type numbers TYPENUMS
340 and return the type object.
341 This can create an empty (zeroed) type object.
342 TYPENUMS may be (-1, -1) to return a new type object that is not
343 put into the type vector, and so may not be referred to by number. */
346 dbx_alloc_type (typenums
, objfile
)
348 struct objfile
*objfile
;
350 register struct type
**type_addr
;
352 if (typenums
[0] == -1)
354 return (alloc_type (objfile
));
357 type_addr
= dbx_lookup_type (typenums
);
359 /* If we are referring to a type not known at all yet,
360 allocate an empty type for it.
361 We will fill it in later if we find out how. */
364 *type_addr
= alloc_type (objfile
);
370 /* for all the stabs in a given stab vector, build appropriate types
371 and fix their symbols in given symbol vector. */
374 patch_block_stabs (symbols
, stabs
, objfile
)
375 struct pending
*symbols
;
376 struct pending_stabs
*stabs
;
377 struct objfile
*objfile
;
387 /* for all the stab entries, find their corresponding symbols and
388 patch their types! */
390 for (ii
= 0; ii
< stabs
->count
; ++ii
)
392 name
= stabs
->stab
[ii
];
393 pp
= (char*) strchr (name
, ':');
397 pp
= (char *)strchr(pp
, ':');
399 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
403 /* The following code is disabled because AIX's xlc also
404 puts out a stab but no C_EXT in the case where a
405 symbol is referenced but not defined (in that
406 compilation unit). So we just don't create a symbol,
407 and the user will get the symbol from the compilation
408 unit in which the symbol is actually defined. */
410 /* On xcoff, if a global is defined and never referenced,
411 ld will remove it from the executable. There is then
412 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
413 sym
= (struct symbol
*)
414 obstack_alloc (&objfile
->symbol_obstack
,
415 sizeof (struct symbol
));
417 memset (sym
, 0, sizeof (struct symbol
));
418 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
419 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
421 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
423 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
425 /* I don't think the linker does this with functions,
426 so as far as I know this is never executed.
427 But it doesn't hurt to check. */
429 lookup_function_type (read_type (&pp
, objfile
));
433 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
435 add_symbol_to_list (sym
, &global_symbols
);
441 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
444 lookup_function_type (read_type (&pp
, objfile
));
448 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
456 /* Read a number by which a type is referred to in dbx data,
457 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
458 Just a single number N is equivalent to (0,N).
459 Return the two numbers by storing them in the vector TYPENUMS.
460 TYPENUMS will then be used as an argument to dbx_lookup_type.
462 Returns 0 for success, -1 for error. */
465 read_type_number (pp
, typenums
)
467 register int *typenums
;
473 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
474 if (nbits
!= 0) return -1;
475 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
476 if (nbits
!= 0) return -1;
481 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
482 if (nbits
!= 0) return -1;
488 /* To handle GNU C++ typename abbreviation, we need to be able to
489 fill in a type's name as soon as space for that type is allocated.
490 `type_synonym_name' is the name of the type being allocated.
491 It is cleared as soon as it is used (lest all allocated types
494 static char *type_synonym_name
;
496 #if !defined (REG_STRUCT_HAS_ADDR)
497 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
502 define_symbol (valu
, string
, desc
, type
, objfile
)
507 struct objfile
*objfile
;
509 register struct symbol
*sym
;
510 char *p
= (char *) strchr (string
, ':');
515 /* We would like to eliminate nameless symbols, but keep their types.
516 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
517 to type 2, but, should not create a symbol to address that type. Since
518 the symbol will be nameless, there is no way any user can refer to it. */
522 /* Ignore syms with empty names. */
526 /* Ignore old-style symbols from cc -go */
536 /* If a nameless stab entry, all we need is the type, not the symbol.
537 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
538 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
540 sym
= (struct symbol
*)
541 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
542 memset (sym
, 0, sizeof (struct symbol
));
544 if (processing_gcc_compilation
)
546 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
547 number of bytes occupied by a type or object, which we ignore. */
548 SYMBOL_LINE(sym
) = desc
;
552 SYMBOL_LINE(sym
) = 0; /* unknown */
555 if (string
[0] == CPLUS_MARKER
)
557 /* Special GNU C++ names. */
561 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
562 &objfile
-> symbol_obstack
);
565 case 'v': /* $vtbl_ptr_type */
566 /* Was: SYMBOL_NAME (sym) = "vptr"; */
570 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
571 &objfile
-> symbol_obstack
);
575 /* This was an anonymous type that was never fixed up. */
579 complain (&unrecognized_cplus_name_complaint
, string
);
580 goto normal
; /* Do *something* with it */
586 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
587 SYMBOL_NAME (sym
) = (char *)
588 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
589 /* Open-coded memcpy--saves function call time. */
590 /* FIXME: Does it really? Try replacing with simple strcpy and
591 try it on an executable with a large symbol table. */
592 /* FIXME: considering that gcc can open code memcpy anyway, I
593 doubt it. xoxorich. */
595 register char *p1
= string
;
596 register char *p2
= SYMBOL_NAME (sym
);
604 /* If this symbol is from a C++ compilation, then attempt to cache the
605 demangled form for future reference. This is a typical time versus
606 space tradeoff, that was decided in favor of time because it sped up
607 C++ symbol lookups by a factor of about 20. */
609 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
613 /* Determine the type of name being defined. */
615 /* Getting GDB to correctly skip the symbol on an undefined symbol
616 descriptor and not ever dump core is a very dodgy proposition if
617 we do things this way. I say the acorn RISC machine can just
618 fix their compiler. */
619 /* The Acorn RISC machine's compiler can put out locals that don't
620 start with "234=" or "(3,4)=", so assume anything other than the
621 deftypes we know how to handle is a local. */
622 if (!strchr ("cfFGpPrStTvVXCR", *p
))
624 if (isdigit (*p
) || *p
== '(' || *p
== '-')
633 /* c is a special case, not followed by a type-number.
634 SYMBOL:c=iVALUE for an integer constant symbol.
635 SYMBOL:c=rVALUE for a floating constant symbol.
636 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
637 e.g. "b:c=e6,0" for "const b = blob1"
638 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
641 SYMBOL_CLASS (sym
) = LOC_CONST
;
642 SYMBOL_TYPE (sym
) = error_type (&p
);
643 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
644 add_symbol_to_list (sym
, &file_symbols
);
655 /* FIXME-if-picky-about-floating-accuracy: Should be using
656 target arithmetic to get the value. real.c in GCC
657 probably has the necessary code. */
659 /* FIXME: lookup_fundamental_type is a hack. We should be
660 creating a type especially for the type of float constants.
661 Problem is, what type should it be?
663 Also, what should the name of this type be? Should we
664 be using 'S' constants (see stabs.texinfo) instead? */
666 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
669 obstack_alloc (&objfile
-> symbol_obstack
,
670 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
671 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
672 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
673 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
678 /* Defining integer constants this way is kind of silly,
679 since 'e' constants allows the compiler to give not
680 only the value, but the type as well. C has at least
681 int, long, unsigned int, and long long as constant
682 types; other languages probably should have at least
683 unsigned as well as signed constants. */
685 /* We just need one int constant type for all objfiles.
686 It doesn't depend on languages or anything (arguably its
687 name should be a language-specific name for a type of
688 that size, but I'm inclined to say that if the compiler
689 wants a nice name for the type, it can use 'e'). */
690 static struct type
*int_const_type
;
692 /* Yes, this is as long as a *host* int. That is because we
694 if (int_const_type
== NULL
)
696 init_type (TYPE_CODE_INT
,
697 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
699 (struct objfile
*)NULL
);
700 SYMBOL_TYPE (sym
) = int_const_type
;
701 SYMBOL_VALUE (sym
) = atoi (p
);
702 SYMBOL_CLASS (sym
) = LOC_CONST
;
706 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
707 can be represented as integral.
708 e.g. "b:c=e6,0" for "const b = blob1"
709 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
711 SYMBOL_CLASS (sym
) = LOC_CONST
;
712 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
716 SYMBOL_TYPE (sym
) = error_type (&p
);
721 /* If the value is too big to fit in an int (perhaps because
722 it is unsigned), or something like that, we silently get
723 a bogus value. The type and everything else about it is
724 correct. Ideally, we should be using whatever we have
725 available for parsing unsigned and long long values,
727 SYMBOL_VALUE (sym
) = atoi (p
);
732 SYMBOL_CLASS (sym
) = LOC_CONST
;
733 SYMBOL_TYPE (sym
) = error_type (&p
);
736 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
737 add_symbol_to_list (sym
, &file_symbols
);
741 /* The name of a caught exception. */
742 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
743 SYMBOL_CLASS (sym
) = LOC_LABEL
;
744 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
745 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
746 add_symbol_to_list (sym
, &local_symbols
);
750 /* A static function definition. */
751 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
752 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
753 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
754 add_symbol_to_list (sym
, &file_symbols
);
755 /* fall into process_function_types. */
757 process_function_types
:
758 /* Function result types are described as the result type in stabs.
759 We need to convert this to the function-returning-type-X type
760 in GDB. E.g. "int" is converted to "function returning int". */
761 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
764 /* This code doesn't work -- it needs to realloc and can't. */
765 /* Attempt to set up to record a function prototype... */
766 struct type
*new = alloc_type (objfile
);
768 /* Generate a template for the type of this function. The
769 types of the arguments will be added as we read the symbol
771 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
772 SYMBOL_TYPE(sym
) = new;
773 TYPE_OBJFILE (new) = objfile
;
774 in_function_type
= new;
776 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
779 /* fall into process_prototype_types */
781 process_prototype_types
:
782 /* Sun acc puts declared types of arguments here. We don't care
783 about their actual types (FIXME -- we should remember the whole
784 function prototype), but the list may define some new types
785 that we have to remember, so we must scan it now. */
788 read_type (&p
, objfile
);
793 /* A global function definition. */
794 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
795 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
796 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
797 add_symbol_to_list (sym
, &global_symbols
);
798 goto process_function_types
;
801 /* For a class G (global) symbol, it appears that the
802 value is not correct. It is necessary to search for the
803 corresponding linker definition to find the value.
804 These definitions appear at the end of the namelist. */
805 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
806 i
= hashname (SYMBOL_NAME (sym
));
807 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
808 global_sym_chain
[i
] = sym
;
809 SYMBOL_CLASS (sym
) = LOC_STATIC
;
810 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
811 add_symbol_to_list (sym
, &global_symbols
);
814 /* This case is faked by a conditional above,
815 when there is no code letter in the dbx data.
816 Dbx data never actually contains 'l'. */
819 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
820 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
821 SYMBOL_VALUE (sym
) = valu
;
822 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
823 add_symbol_to_list (sym
, &local_symbols
);
828 /* pF is a two-letter code that means a function parameter in Fortran.
829 The type-number specifies the type of the return value.
830 Translate it into a pointer-to-function type. */
834 = lookup_pointer_type
835 (lookup_function_type (read_type (&p
, objfile
)));
838 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
840 /* Normally this is a parameter, a LOC_ARG. On the i960, it
841 can also be a LOC_LOCAL_ARG depending on symbol type. */
842 #ifndef DBX_PARM_SYMBOL_CLASS
843 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
846 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
847 SYMBOL_VALUE (sym
) = valu
;
848 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
850 /* This doesn't work yet. */
851 add_param_to_type (&in_function_type
, sym
);
853 add_symbol_to_list (sym
, &local_symbols
);
855 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
856 /* On little-endian machines, this crud is never necessary, and,
857 if the extra bytes contain garbage, is harmful. */
859 #else /* Big endian. */
860 /* If it's gcc-compiled, if it says `short', believe it. */
861 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
864 #if !BELIEVE_PCC_PROMOTION
866 /* This is the signed type which arguments get promoted to. */
867 static struct type
*pcc_promotion_type
;
868 /* This is the unsigned type which arguments get promoted to. */
869 static struct type
*pcc_unsigned_promotion_type
;
871 /* Call it "int" because this is mainly C lossage. */
872 if (pcc_promotion_type
== NULL
)
874 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
877 if (pcc_unsigned_promotion_type
== NULL
)
878 pcc_unsigned_promotion_type
=
879 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
880 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
882 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
883 /* This macro is defined on machines (e.g. sparc) where
884 we should believe the type of a PCC 'short' argument,
885 but shouldn't believe the address (the address is
886 the address of the corresponding int).
888 My guess is that this correction, as opposed to changing
889 the parameter to an 'int' (as done below, for PCC
890 on most machines), is the right thing to do
891 on all machines, but I don't want to risk breaking
892 something that already works. On most PCC machines,
893 the sparc problem doesn't come up because the calling
894 function has to zero the top bytes (not knowing whether
895 the called function wants an int or a short), so there
896 is little practical difference between an int and a short
897 (except perhaps what happens when the GDB user types
898 "print short_arg = 0x10000;").
900 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
901 actually produces the correct address (we don't need to fix it
902 up). I made this code adapt so that it will offset the symbol
903 if it was pointing at an int-aligned location and not
904 otherwise. This way you can use the same gdb for 4.0.x and
907 If the parameter is shorter than an int, and is integral
908 (e.g. char, short, or unsigned equivalent), and is claimed to
909 be passed on an integer boundary, don't believe it! Offset the
910 parameter's address to the tail-end of that integer. */
912 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
913 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
914 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
916 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
917 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
921 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
923 /* If PCC says a parameter is a short or a char,
924 it is really an int. */
925 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
926 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
929 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
930 ? pcc_unsigned_promotion_type
931 : pcc_promotion_type
;
935 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
937 #endif /* !BELIEVE_PCC_PROMOTION. */
938 #endif /* Big endian. */
941 /* acc seems to use P to delare the prototypes of functions that
942 are referenced by this file. gdb is not prepared to deal
943 with this extra information. FIXME, it ought to. */
946 read_type (&p
, objfile
);
947 goto process_prototype_types
;
952 /* Parameter which is in a register. */
953 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
954 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
955 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
956 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
958 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
959 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
961 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
962 add_symbol_to_list (sym
, &local_symbols
);
966 /* Register variable (either global or local). */
967 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
968 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
969 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
970 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
972 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
973 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
975 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
978 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
979 name to represent an argument passed in a register.
980 GCC uses 'P' for the same case. So if we find such a symbol pair
981 we combine it into one 'P' symbol.
983 But we only do this in the REG_STRUCT_HAS_ADDR case, so that
984 we can still get information about what is going on with the
985 stack (VAX for computing args_printed, using stack slots instead
986 of saved registers in backtraces, etc.).
988 Note that this code illegally combines
989 main(argc) struct foo argc; { register struct foo argc; }
990 but this case is considered pathological and causes a warning
991 from a decent compiler. */
994 && local_symbols
->nsyms
> 0
995 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
997 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
998 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
))
1000 struct symbol
*prev_sym
;
1001 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1002 if (SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1003 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
1005 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1006 /* Use the type from the LOC_REGISTER; that is the type
1007 that is actually in that register. */
1008 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1009 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1014 add_symbol_to_list (sym
, &local_symbols
);
1017 add_symbol_to_list (sym
, &file_symbols
);
1021 /* Static symbol at top level of file */
1022 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1023 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1024 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1025 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1026 add_symbol_to_list (sym
, &file_symbols
);
1030 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1032 /* For a nameless type, we don't want a create a symbol, thus we
1033 did not use `sym'. Return without further processing. */
1034 if (nameless
) return NULL
;
1036 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1037 SYMBOL_VALUE (sym
) = valu
;
1038 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1039 /* C++ vagaries: we may have a type which is derived from
1040 a base type which did not have its name defined when the
1041 derived class was output. We fill in the derived class's
1042 base part member's name here in that case. */
1043 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1044 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1045 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1046 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1049 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1050 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1051 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1052 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1055 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1057 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1058 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1060 /* If we are giving a name to a type such as "pointer to
1061 foo" or "function returning foo", we better not set
1062 the TYPE_NAME. If the program contains "typedef char
1063 *caddr_t;", we don't want all variables of type char
1064 * to print as caddr_t. This is not just a
1065 consequence of GDB's type management; PCC and GCC (at
1066 least through version 2.4) both output variables of
1067 either type char * or caddr_t with the type number
1068 defined in the 't' symbol for caddr_t. If a future
1069 compiler cleans this up it GDB is not ready for it
1070 yet, but if it becomes ready we somehow need to
1071 disable this check (without breaking the PCC/GCC2.4
1076 Fortunately, this check seems not to be necessary
1077 for anything except pointers or functions. */
1080 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1083 add_symbol_to_list (sym
, &file_symbols
);
1087 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1088 by 't' which means we are typedef'ing it as well. */
1089 synonym
= *p
== 't';
1094 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1095 strlen (SYMBOL_NAME (sym
)),
1096 &objfile
-> symbol_obstack
);
1098 /* The semantics of C++ state that "struct foo { ... }" also defines
1099 a typedef for "foo". Unfortunately, cfront never makes the typedef
1100 when translating C++ into C. We make the typedef here so that
1101 "ptype foo" works as expected for cfront translated code. */
1102 else if (current_subfile
->language
== language_cplus
)
1105 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1106 strlen (SYMBOL_NAME (sym
)),
1107 &objfile
-> symbol_obstack
);
1110 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1112 /* For a nameless type, we don't want a create a symbol, thus we
1113 did not use `sym'. Return without further processing. */
1114 if (nameless
) return NULL
;
1116 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1117 SYMBOL_VALUE (sym
) = valu
;
1118 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1119 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1120 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1121 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1122 add_symbol_to_list (sym
, &file_symbols
);
1126 /* Clone the sym and then modify it. */
1127 register struct symbol
*typedef_sym
= (struct symbol
*)
1128 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1129 *typedef_sym
= *sym
;
1130 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1131 SYMBOL_VALUE (typedef_sym
) = valu
;
1132 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1133 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1134 TYPE_NAME (SYMBOL_TYPE (sym
))
1135 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1136 add_symbol_to_list (typedef_sym
, &file_symbols
);
1141 /* Static symbol of local scope */
1142 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1143 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1144 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1145 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1147 add_symbol_to_list (sym
, &global_symbols
);
1149 add_symbol_to_list (sym
, &local_symbols
);
1153 /* Reference parameter */
1154 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1155 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1156 SYMBOL_VALUE (sym
) = valu
;
1157 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1158 add_symbol_to_list (sym
, &local_symbols
);
1162 /* This is used by Sun FORTRAN for "function result value".
1163 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1164 that Pascal uses it too, but when I tried it Pascal used
1165 "x:3" (local symbol) instead. */
1166 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1167 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1168 SYMBOL_VALUE (sym
) = valu
;
1169 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1170 add_symbol_to_list (sym
, &local_symbols
);
1174 SYMBOL_TYPE (sym
) = error_type (&p
);
1175 SYMBOL_CLASS (sym
) = LOC_CONST
;
1176 SYMBOL_VALUE (sym
) = 0;
1177 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1178 add_symbol_to_list (sym
, &file_symbols
);
1182 /* When passing structures to a function, some systems sometimes pass
1183 the address in a register, not the structure itself.
1185 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1186 to LOC_REGPARM_ADDR for structures and unions. */
1188 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1189 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1191 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1192 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1193 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1195 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1196 subsequent arguments on the sparc, for example). */
1197 if (SYMBOL_CLASS (sym
) == LOC_ARG
1198 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1200 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1201 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1202 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1208 /* Skip rest of this symbol and return an error type.
1210 General notes on error recovery: error_type always skips to the
1211 end of the symbol (modulo cretinous dbx symbol name continuation).
1212 Thus code like this:
1214 if (*(*pp)++ != ';')
1215 return error_type (pp);
1217 is wrong because if *pp starts out pointing at '\0' (typically as the
1218 result of an earlier error), it will be incremented to point to the
1219 start of the next symbol, which might produce strange results, at least
1220 if you run off the end of the string table. Instead use
1223 return error_type (pp);
1229 foo = error_type (pp);
1233 And in case it isn't obvious, the point of all this hair is so the compiler
1234 can define new types and new syntaxes, and old versions of the
1235 debugger will be able to read the new symbol tables. */
1237 static struct type
*
1241 complain (&error_type_complaint
);
1244 /* Skip to end of symbol. */
1245 while (**pp
!= '\0')
1250 /* Check for and handle cretinous dbx symbol name continuation! */
1251 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1253 *pp
= next_symbol_text ();
1260 return (builtin_type_error
);
1264 /* Read type information or a type definition; return the type. Even
1265 though this routine accepts either type information or a type
1266 definition, the distinction is relevant--some parts of stabsread.c
1267 assume that type information starts with a digit, '-', or '(' in
1268 deciding whether to call read_type. */
1271 read_type (pp
, objfile
)
1273 struct objfile
*objfile
;
1275 register struct type
*type
= 0;
1279 char type_descriptor
;
1281 /* Size in bits of type if specified by a type attribute, or -1 if
1282 there is no size attribute. */
1285 /* Used to distinguish string and bitstring from char-array and set. */
1288 /* Read type number if present. The type number may be omitted.
1289 for instance in a two-dimensional array declared with type
1290 "ar1;1;10;ar1;1;10;4". */
1291 if ((**pp
>= '0' && **pp
<= '9')
1295 if (read_type_number (pp
, typenums
) != 0)
1296 return error_type (pp
);
1298 /* Type is not being defined here. Either it already exists,
1299 or this is a forward reference to it. dbx_alloc_type handles
1302 return dbx_alloc_type (typenums
, objfile
);
1304 /* Type is being defined here. */
1311 /* It might be a type attribute or a member type. */
1312 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1317 /* Type attributes. */
1320 /* Skip to the semicolon. */
1321 while (*p
!= ';' && *p
!= '\0')
1325 return error_type (pp
);
1327 /* Skip the semicolon. */
1333 type_size
= atoi (attr
+ 1);
1343 /* Ignore unrecognized type attributes, so future compilers
1344 can invent new ones. */
1349 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1354 /* 'typenums=' not present, type is anonymous. Read and return
1355 the definition, but don't put it in the type vector. */
1356 typenums
[0] = typenums
[1] = -1;
1360 type_descriptor
= (*pp
)[-1];
1361 switch (type_descriptor
)
1365 enum type_code code
;
1367 /* Used to index through file_symbols. */
1368 struct pending
*ppt
;
1371 /* Name including "struct", etc. */
1375 char *from
, *to
, *p
, *q1
, *q2
;
1377 /* Set the type code according to the following letter. */
1381 code
= TYPE_CODE_STRUCT
;
1384 code
= TYPE_CODE_UNION
;
1387 code
= TYPE_CODE_ENUM
;
1391 /* Complain and keep going, so compilers can invent new
1392 cross-reference types. */
1393 static struct complaint msg
=
1394 {"Unrecognized cross-reference type `%c'", 0, 0};
1395 complain (&msg
, (*pp
)[0]);
1396 code
= TYPE_CODE_STRUCT
;
1401 q1
= strchr(*pp
, '<');
1402 p
= strchr(*pp
, ':');
1404 return error_type (pp
);
1405 while (q1
&& p
> q1
&& p
[1] == ':')
1407 q2
= strchr(q1
, '>');
1413 return error_type (pp
);
1416 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1418 /* Copy the name. */
1424 /* Set the pointer ahead of the name which we just read, and
1429 /* Now check to see whether the type has already been
1430 declared. This was written for arrays of cross-referenced
1431 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1432 sure it is not necessary anymore. But it might be a good
1433 idea, to save a little memory. */
1435 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1436 for (i
= 0; i
< ppt
->nsyms
; i
++)
1438 struct symbol
*sym
= ppt
->symbol
[i
];
1440 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1441 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1442 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1443 && STREQ (SYMBOL_NAME (sym
), type_name
))
1445 obstack_free (&objfile
-> type_obstack
, type_name
);
1446 type
= SYMBOL_TYPE (sym
);
1451 /* Didn't find the type to which this refers, so we must
1452 be dealing with a forward reference. Allocate a type
1453 structure for it, and keep track of it so we can
1454 fill in the rest of the fields when we get the full
1456 type
= dbx_alloc_type (typenums
, objfile
);
1457 TYPE_CODE (type
) = code
;
1458 TYPE_TAG_NAME (type
) = type_name
;
1459 INIT_CPLUS_SPECIFIC(type
);
1460 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1462 add_undefined_type (type
);
1466 case '-': /* RS/6000 built-in type */
1485 /* Peek ahead at the number to detect void. */
1486 if (read_type_number (pp
, xtypenums
) != 0)
1487 return error_type (pp
);
1489 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1490 /* It's being defined as itself. That means it is "void". */
1491 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
1496 /* Go back to the number and have read_type get it. This means
1497 that we can deal with something like t(1,2)=(3,4)=... which
1498 the Lucid compiler uses. */
1500 xtype
= read_type (pp
, objfile
);
1502 /* The type is being defined to another type. So we copy the type.
1503 This loses if we copy a C++ class and so we lose track of how
1504 the names are mangled (but g++ doesn't output stabs like this
1507 type
= alloc_type (objfile
);
1508 memcpy (type
, xtype
, sizeof (struct type
));
1510 /* The idea behind clearing the names is that the only purpose
1511 for defining a type to another type is so that the name of
1512 one can be different. So we probably don't need to worry much
1513 about the case where the compiler doesn't give a name to the
1515 TYPE_NAME (type
) = NULL
;
1516 TYPE_TAG_NAME (type
) = NULL
;
1518 if (typenums
[0] != -1)
1519 *dbx_lookup_type (typenums
) = type
;
1523 /* In the following types, we must be sure to overwrite any existing
1524 type that the typenums refer to, rather than allocating a new one
1525 and making the typenums point to the new one. This is because there
1526 may already be pointers to the existing type (if it had been
1527 forward-referenced), and we must change it to a pointer, function,
1528 reference, or whatever, *in-place*. */
1531 type1
= read_type (pp
, objfile
);
1532 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1535 case '&': /* Reference to another type */
1536 type1
= read_type (pp
, objfile
);
1537 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1540 case 'f': /* Function returning another type */
1541 if (os9k_stabs
&& **pp
== '(')
1543 /* Function prototype; skip it.
1544 We must conditionalize this on os9k_stabs because otherwise
1545 it could be confused with a Sun-style (1,3) typenumber
1551 type1
= read_type (pp
, objfile
);
1552 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1555 case 'k': /* Const qualifier on some type (Sun) */
1556 case 'c': /* Const qualifier on some type (OS9000) */
1557 /* Because 'c' means other things to AIX and 'k' is perfectly good,
1558 only accept 'c' in the os9k_stabs case. */
1559 if (type_descriptor
== 'c' && !os9k_stabs
)
1560 return error_type (pp
);
1561 type
= read_type (pp
, objfile
);
1562 /* FIXME! For now, we ignore const and volatile qualifiers. */
1565 case 'B': /* Volatile qual on some type (Sun) */
1566 case 'i': /* Volatile qual on some type (OS9000) */
1567 /* Because 'i' means other things to AIX and 'B' is perfectly good,
1568 only accept 'i' in the os9k_stabs case. */
1569 if (type_descriptor
== 'i' && !os9k_stabs
)
1570 return error_type (pp
);
1571 type
= read_type (pp
, objfile
);
1572 /* FIXME! For now, we ignore const and volatile qualifiers. */
1575 /* FIXME -- we should be doing smash_to_XXX types here. */
1576 case '@': /* Member (class & variable) type */
1578 struct type
*domain
= read_type (pp
, objfile
);
1579 struct type
*memtype
;
1582 /* Invalid member type data format. */
1583 return error_type (pp
);
1586 memtype
= read_type (pp
, objfile
);
1587 type
= dbx_alloc_type (typenums
, objfile
);
1588 smash_to_member_type (type
, domain
, memtype
);
1592 case '#': /* Method (class & fn) type */
1593 if ((*pp
)[0] == '#')
1595 /* We'll get the parameter types from the name. */
1596 struct type
*return_type
;
1599 return_type
= read_type (pp
, objfile
);
1600 if (*(*pp
)++ != ';')
1601 complain (&invalid_member_complaint
, symnum
);
1602 type
= allocate_stub_method (return_type
);
1603 if (typenums
[0] != -1)
1604 *dbx_lookup_type (typenums
) = type
;
1608 struct type
*domain
= read_type (pp
, objfile
);
1609 struct type
*return_type
;
1613 /* Invalid member type data format. */
1614 return error_type (pp
);
1618 return_type
= read_type (pp
, objfile
);
1619 args
= read_args (pp
, ';', objfile
);
1620 type
= dbx_alloc_type (typenums
, objfile
);
1621 smash_to_method_type (type
, domain
, return_type
, args
);
1625 case 'r': /* Range type */
1626 type
= read_range_type (pp
, typenums
, objfile
);
1627 if (typenums
[0] != -1)
1628 *dbx_lookup_type (typenums
) = type
;
1633 /* Const and volatile qualified type. */
1634 type
= read_type (pp
, objfile
);
1637 /* Sun ACC builtin int type */
1638 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1639 if (typenums
[0] != -1)
1640 *dbx_lookup_type (typenums
) = type
;
1644 case 'R': /* Sun ACC builtin float type */
1645 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1646 if (typenums
[0] != -1)
1647 *dbx_lookup_type (typenums
) = type
;
1650 case 'e': /* Enumeration type */
1651 type
= dbx_alloc_type (typenums
, objfile
);
1652 type
= read_enum_type (pp
, type
, objfile
);
1653 if (typenums
[0] != -1)
1654 *dbx_lookup_type (typenums
) = type
;
1657 case 's': /* Struct type */
1658 case 'u': /* Union type */
1659 type
= dbx_alloc_type (typenums
, objfile
);
1660 if (!TYPE_NAME (type
))
1662 TYPE_NAME (type
) = type_synonym_name
;
1664 type_synonym_name
= NULL
;
1665 switch (type_descriptor
)
1668 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1671 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1674 type
= read_struct_type (pp
, type
, objfile
);
1677 case 'a': /* Array type */
1679 return error_type (pp
);
1682 type
= dbx_alloc_type (typenums
, objfile
);
1683 type
= read_array_type (pp
, type
, objfile
);
1685 TYPE_CODE (type
) = TYPE_CODE_STRING
;
1689 type1
= read_type (pp
, objfile
);
1690 type
= create_set_type ((struct type
*) NULL
, type1
);
1692 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
1693 if (typenums
[0] != -1)
1694 *dbx_lookup_type (typenums
) = type
;
1698 --*pp
; /* Go back to the symbol in error */
1699 /* Particularly important if it was \0! */
1700 return error_type (pp
);
1705 warning ("GDB internal error, type is NULL in stabsread.c\n");
1706 return error_type (pp
);
1709 /* Size specified in a type attribute overrides any other size. */
1710 if (type_size
!= -1)
1711 TYPE_LENGTH (type
) = type_size
/ TARGET_CHAR_BIT
;
1716 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1717 Return the proper type node for a given builtin type number. */
1719 static struct type
*
1720 rs6000_builtin_type (typenum
)
1723 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1724 #define NUMBER_RECOGNIZED 30
1725 /* This includes an empty slot for type number -0. */
1726 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1727 struct type
*rettype
= NULL
;
1729 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1731 complain (&rs6000_builtin_complaint
, typenum
);
1732 return builtin_type_error
;
1734 if (negative_types
[-typenum
] != NULL
)
1735 return negative_types
[-typenum
];
1737 #if TARGET_CHAR_BIT != 8
1738 #error This code wrong for TARGET_CHAR_BIT not 8
1739 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1740 that if that ever becomes not true, the correct fix will be to
1741 make the size in the struct type to be in bits, not in units of
1748 /* The size of this and all the other types are fixed, defined
1749 by the debugging format. If there is a type called "int" which
1750 is other than 32 bits, then it should use a new negative type
1751 number (or avoid negative type numbers for that case).
1752 See stabs.texinfo. */
1753 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1756 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1759 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1762 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1765 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1766 "unsigned char", NULL
);
1769 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1772 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1773 "unsigned short", NULL
);
1776 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1777 "unsigned int", NULL
);
1780 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1783 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1784 "unsigned long", NULL
);
1787 rettype
= init_type (TYPE_CODE_VOID
, 0, 0, "void", NULL
);
1790 /* IEEE single precision (32 bit). */
1791 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1794 /* IEEE double precision (64 bit). */
1795 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1798 /* This is an IEEE double on the RS/6000, and different machines with
1799 different sizes for "long double" should use different negative
1800 type numbers. See stabs.texinfo. */
1801 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1804 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1807 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1810 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1813 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1816 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1819 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1823 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1827 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1831 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1835 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1839 /* Complex type consisting of two IEEE single precision values. */
1840 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1843 /* Complex type consisting of two IEEE double precision values. */
1844 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1847 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1850 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1853 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1856 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1859 negative_types
[-typenum
] = rettype
;
1863 /* This page contains subroutines of read_type. */
1865 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1866 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1867 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1868 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1870 /* Read member function stabs info for C++ classes. The form of each member
1873 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1875 An example with two member functions is:
1877 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1879 For the case of overloaded operators, the format is op$::*.funcs, where
1880 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1881 name (such as `+=') and `.' marks the end of the operator name.
1883 Returns 1 for success, 0 for failure. */
1886 read_member_functions (fip
, pp
, type
, objfile
)
1887 struct field_info
*fip
;
1890 struct objfile
*objfile
;
1894 /* Total number of member functions defined in this class. If the class
1895 defines two `f' functions, and one `g' function, then this will have
1897 int total_length
= 0;
1901 struct next_fnfield
*next
;
1902 struct fn_field fn_field
;
1904 struct type
*look_ahead_type
;
1905 struct next_fnfieldlist
*new_fnlist
;
1906 struct next_fnfield
*new_sublist
;
1910 /* Process each list until we find something that is not a member function
1911 or find the end of the functions. */
1915 /* We should be positioned at the start of the function name.
1916 Scan forward to find the first ':' and if it is not the
1917 first of a "::" delimiter, then this is not a member function. */
1929 look_ahead_type
= NULL
;
1932 new_fnlist
= (struct next_fnfieldlist
*)
1933 xmalloc (sizeof (struct next_fnfieldlist
));
1934 make_cleanup (free
, new_fnlist
);
1935 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1937 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1939 /* This is a completely wierd case. In order to stuff in the
1940 names that might contain colons (the usual name delimiter),
1941 Mike Tiemann defined a different name format which is
1942 signalled if the identifier is "op$". In that case, the
1943 format is "op$::XXXX." where XXXX is the name. This is
1944 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1945 /* This lets the user type "break operator+".
1946 We could just put in "+" as the name, but that wouldn't
1948 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1949 char *o
= opname
+ 3;
1951 /* Skip past '::'. */
1954 STABS_CONTINUE (pp
);
1960 main_fn_name
= savestring (opname
, o
- opname
);
1966 main_fn_name
= savestring (*pp
, p
- *pp
);
1967 /* Skip past '::'. */
1970 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1975 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1976 make_cleanup (free
, new_sublist
);
1977 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1979 /* Check for and handle cretinous dbx symbol name continuation! */
1980 if (look_ahead_type
== NULL
)
1983 STABS_CONTINUE (pp
);
1985 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1988 /* Invalid symtab info for member function. */
1994 /* g++ version 1 kludge */
1995 new_sublist
-> fn_field
.type
= look_ahead_type
;
1996 look_ahead_type
= NULL
;
2006 /* If this is just a stub, then we don't have the real name here. */
2008 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2010 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2011 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2012 new_sublist
-> fn_field
.is_stub
= 1;
2014 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2017 /* Set this member function's visibility fields. */
2020 case VISIBILITY_PRIVATE
:
2021 new_sublist
-> fn_field
.is_private
= 1;
2023 case VISIBILITY_PROTECTED
:
2024 new_sublist
-> fn_field
.is_protected
= 1;
2028 STABS_CONTINUE (pp
);
2031 case 'A': /* Normal functions. */
2032 new_sublist
-> fn_field
.is_const
= 0;
2033 new_sublist
-> fn_field
.is_volatile
= 0;
2036 case 'B': /* `const' member functions. */
2037 new_sublist
-> fn_field
.is_const
= 1;
2038 new_sublist
-> fn_field
.is_volatile
= 0;
2041 case 'C': /* `volatile' member function. */
2042 new_sublist
-> fn_field
.is_const
= 0;
2043 new_sublist
-> fn_field
.is_volatile
= 1;
2046 case 'D': /* `const volatile' member function. */
2047 new_sublist
-> fn_field
.is_const
= 1;
2048 new_sublist
-> fn_field
.is_volatile
= 1;
2051 case '*': /* File compiled with g++ version 1 -- no info */
2056 complain (&const_vol_complaint
, **pp
);
2065 /* virtual member function, followed by index.
2066 The sign bit is set to distinguish pointers-to-methods
2067 from virtual function indicies. Since the array is
2068 in words, the quantity must be shifted left by 1
2069 on 16 bit machine, and by 2 on 32 bit machine, forcing
2070 the sign bit out, and usable as a valid index into
2071 the array. Remove the sign bit here. */
2072 new_sublist
-> fn_field
.voffset
=
2073 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2077 STABS_CONTINUE (pp
);
2078 if (**pp
== ';' || **pp
== '\0')
2080 /* Must be g++ version 1. */
2081 new_sublist
-> fn_field
.fcontext
= 0;
2085 /* Figure out from whence this virtual function came.
2086 It may belong to virtual function table of
2087 one of its baseclasses. */
2088 look_ahead_type
= read_type (pp
, objfile
);
2091 /* g++ version 1 overloaded methods. */
2095 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2104 look_ahead_type
= NULL
;
2110 /* static member function. */
2111 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2112 if (strncmp (new_sublist
-> fn_field
.physname
,
2113 main_fn_name
, strlen (main_fn_name
)))
2115 new_sublist
-> fn_field
.is_stub
= 1;
2121 complain (&member_fn_complaint
, (*pp
)[-1]);
2122 /* Fall through into normal member function. */
2125 /* normal member function. */
2126 new_sublist
-> fn_field
.voffset
= 0;
2127 new_sublist
-> fn_field
.fcontext
= 0;
2131 new_sublist
-> next
= sublist
;
2132 sublist
= new_sublist
;
2134 STABS_CONTINUE (pp
);
2136 while (**pp
!= ';' && **pp
!= '\0');
2140 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2141 obstack_alloc (&objfile
-> type_obstack
,
2142 sizeof (struct fn_field
) * length
);
2143 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2144 sizeof (struct fn_field
) * length
);
2145 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2147 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2150 new_fnlist
-> fn_fieldlist
.length
= length
;
2151 new_fnlist
-> next
= fip
-> fnlist
;
2152 fip
-> fnlist
= new_fnlist
;
2154 total_length
+= length
;
2155 STABS_CONTINUE (pp
);
2160 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2161 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2162 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2163 memset (TYPE_FN_FIELDLISTS (type
), 0,
2164 sizeof (struct fn_fieldlist
) * nfn_fields
);
2165 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2166 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2172 /* Special GNU C++ name.
2174 Returns 1 for success, 0 for failure. "failure" means that we can't
2175 keep parsing and it's time for error_type(). */
2178 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2179 struct field_info
*fip
;
2182 struct objfile
*objfile
;
2187 struct type
*context
;
2197 /* At this point, *pp points to something like "22:23=*22...",
2198 where the type number before the ':' is the "context" and
2199 everything after is a regular type definition. Lookup the
2200 type, find it's name, and construct the field name. */
2202 context
= read_type (pp
, objfile
);
2206 case 'f': /* $vf -- a virtual function table pointer */
2207 fip
->list
->field
.name
=
2208 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2211 case 'b': /* $vb -- a virtual bsomethingorother */
2212 name
= type_name_no_tag (context
);
2215 complain (&invalid_cpp_type_complaint
, symnum
);
2218 fip
->list
->field
.name
=
2219 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2223 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2224 fip
->list
->field
.name
=
2225 obconcat (&objfile
->type_obstack
,
2226 "INVALID_CPLUSPLUS_ABBREV", "", "");
2230 /* At this point, *pp points to the ':'. Skip it and read the
2236 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2239 fip
->list
->field
.type
= read_type (pp
, objfile
);
2241 (*pp
)++; /* Skip the comma. */
2247 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2251 /* This field is unpacked. */
2252 fip
->list
->field
.bitsize
= 0;
2253 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2257 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2258 /* We have no idea what syntax an unrecognized abbrev would have, so
2259 better return 0. If we returned 1, we would need to at least advance
2260 *pp to avoid an infinite loop. */
2267 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2268 struct field_info
*fip
;
2272 struct objfile
*objfile
;
2274 fip
-> list
-> field
.name
=
2275 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2278 /* This means we have a visibility for a field coming. */
2282 fip
-> list
-> visibility
= *(*pp
)++;
2286 /* normal dbx-style format, no explicit visibility */
2287 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2290 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2295 /* Possible future hook for nested types. */
2298 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2304 /* Static class member. */
2305 fip
-> list
-> field
.bitpos
= (long) -1;
2311 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2315 else if (**pp
!= ',')
2317 /* Bad structure-type format. */
2318 complain (&stabs_general_complaint
, "bad structure-type format");
2322 (*pp
)++; /* Skip the comma. */
2326 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2329 complain (&stabs_general_complaint
, "bad structure-type format");
2332 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2335 complain (&stabs_general_complaint
, "bad structure-type format");
2340 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2342 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2343 it is a field which has been optimized out. The correct stab for
2344 this case is to use VISIBILITY_IGNORE, but that is a recent
2345 invention. (2) It is a 0-size array. For example
2346 union { int num; char str[0]; } foo. Printing "<no value>" for
2347 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2348 will continue to work, and a 0-size array as a whole doesn't
2349 have any contents to print.
2351 I suspect this probably could also happen with gcc -gstabs (not
2352 -gstabs+) for static fields, and perhaps other C++ extensions.
2353 Hopefully few people use -gstabs with gdb, since it is intended
2354 for dbx compatibility. */
2356 /* Ignore this field. */
2357 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2361 /* Detect an unpacked field and mark it as such.
2362 dbx gives a bit size for all fields.
2363 Note that forward refs cannot be packed,
2364 and treat enums as if they had the width of ints. */
2366 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2367 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2369 fip
-> list
-> field
.bitsize
= 0;
2371 if ((fip
-> list
-> field
.bitsize
2372 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2373 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2374 && (fip
-> list
-> field
.bitsize
2379 fip
-> list
-> field
.bitpos
% 8 == 0)
2381 fip
-> list
-> field
.bitsize
= 0;
2387 /* Read struct or class data fields. They have the form:
2389 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2391 At the end, we see a semicolon instead of a field.
2393 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2396 The optional VISIBILITY is one of:
2398 '/0' (VISIBILITY_PRIVATE)
2399 '/1' (VISIBILITY_PROTECTED)
2400 '/2' (VISIBILITY_PUBLIC)
2401 '/9' (VISIBILITY_IGNORE)
2403 or nothing, for C style fields with public visibility.
2405 Returns 1 for success, 0 for failure. */
2408 read_struct_fields (fip
, pp
, type
, objfile
)
2409 struct field_info
*fip
;
2412 struct objfile
*objfile
;
2415 struct nextfield
*new;
2417 /* We better set p right now, in case there are no fields at all... */
2421 /* Read each data member type until we find the terminating ';' at the end of
2422 the data member list, or break for some other reason such as finding the
2423 start of the member function list. */
2427 STABS_CONTINUE (pp
);
2428 /* Get space to record the next field's data. */
2429 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2430 make_cleanup (free
, new);
2431 memset (new, 0, sizeof (struct nextfield
));
2432 new -> next
= fip
-> list
;
2435 /* Get the field name. */
2438 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2439 unless the CPLUS_MARKER is followed by an underscore, in
2440 which case it is just the name of an anonymous type, which we
2441 should handle like any other type name. We accept either '$'
2442 or '.', because a field name can never contain one of these
2443 characters except as a CPLUS_MARKER (we probably should be
2444 doing that in most parts of GDB). */
2446 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2448 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2453 /* Look for the ':' that separates the field name from the field
2454 values. Data members are delimited by a single ':', while member
2455 functions are delimited by a pair of ':'s. When we hit the member
2456 functions (if any), terminate scan loop and return. */
2458 while (*p
!= ':' && *p
!= '\0')
2465 /* Check to see if we have hit the member functions yet. */
2470 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2472 if (p
[0] == ':' && p
[1] == ':')
2474 /* chill the list of fields: the last entry (at the head) is a
2475 partially constructed entry which we now scrub. */
2476 fip
-> list
= fip
-> list
-> next
;
2481 /* The stabs for C++ derived classes contain baseclass information which
2482 is marked by a '!' character after the total size. This function is
2483 called when we encounter the baseclass marker, and slurps up all the
2484 baseclass information.
2486 Immediately following the '!' marker is the number of base classes that
2487 the class is derived from, followed by information for each base class.
2488 For each base class, there are two visibility specifiers, a bit offset
2489 to the base class information within the derived class, a reference to
2490 the type for the base class, and a terminating semicolon.
2492 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2494 Baseclass information marker __________________|| | | | | | |
2495 Number of baseclasses __________________________| | | | | | |
2496 Visibility specifiers (2) ________________________| | | | | |
2497 Offset in bits from start of class _________________| | | | |
2498 Type number for base class ___________________________| | | |
2499 Visibility specifiers (2) _______________________________| | |
2500 Offset in bits from start of class ________________________| |
2501 Type number of base class ____________________________________|
2503 Return 1 for success, 0 for (error-type-inducing) failure. */
2506 read_baseclasses (fip
, pp
, type
, objfile
)
2507 struct field_info
*fip
;
2510 struct objfile
*objfile
;
2513 struct nextfield
*new;
2521 /* Skip the '!' baseclass information marker. */
2525 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2528 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2534 /* Some stupid compilers have trouble with the following, so break
2535 it up into simpler expressions. */
2536 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2537 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2540 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2543 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2544 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2548 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2550 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2552 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2553 make_cleanup (free
, new);
2554 memset (new, 0, sizeof (struct nextfield
));
2555 new -> next
= fip
-> list
;
2557 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2559 STABS_CONTINUE (pp
);
2563 /* Nothing to do. */
2566 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2569 /* Unknown character. Complain and treat it as non-virtual. */
2571 static struct complaint msg
= {
2572 "Unknown virtual character `%c' for baseclass", 0, 0};
2573 complain (&msg
, **pp
);
2578 new -> visibility
= *(*pp
)++;
2579 switch (new -> visibility
)
2581 case VISIBILITY_PRIVATE
:
2582 case VISIBILITY_PROTECTED
:
2583 case VISIBILITY_PUBLIC
:
2586 /* Bad visibility format. Complain and treat it as
2589 static struct complaint msg
= {
2590 "Unknown visibility `%c' for baseclass", 0, 0};
2591 complain (&msg
, new -> visibility
);
2592 new -> visibility
= VISIBILITY_PUBLIC
;
2599 /* The remaining value is the bit offset of the portion of the object
2600 corresponding to this baseclass. Always zero in the absence of
2601 multiple inheritance. */
2603 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2608 /* The last piece of baseclass information is the type of the
2609 base class. Read it, and remember it's type name as this
2612 new -> field
.type
= read_type (pp
, objfile
);
2613 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2615 /* skip trailing ';' and bump count of number of fields seen */
2624 /* The tail end of stabs for C++ classes that contain a virtual function
2625 pointer contains a tilde, a %, and a type number.
2626 The type number refers to the base class (possibly this class itself) which
2627 contains the vtable pointer for the current class.
2629 This function is called when we have parsed all the method declarations,
2630 so we can look for the vptr base class info. */
2633 read_tilde_fields (fip
, pp
, type
, objfile
)
2634 struct field_info
*fip
;
2637 struct objfile
*objfile
;
2641 STABS_CONTINUE (pp
);
2643 /* If we are positioned at a ';', then skip it. */
2653 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2655 /* Obsolete flags that used to indicate the presence
2656 of constructors and/or destructors. */
2660 /* Read either a '%' or the final ';'. */
2661 if (*(*pp
)++ == '%')
2663 /* The next number is the type number of the base class
2664 (possibly our own class) which supplies the vtable for
2665 this class. Parse it out, and search that class to find
2666 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2667 and TYPE_VPTR_FIELDNO. */
2672 t
= read_type (pp
, objfile
);
2674 while (*p
!= '\0' && *p
!= ';')
2680 /* Premature end of symbol. */
2684 TYPE_VPTR_BASETYPE (type
) = t
;
2685 if (type
== t
) /* Our own class provides vtbl ptr */
2687 for (i
= TYPE_NFIELDS (t
) - 1;
2688 i
>= TYPE_N_BASECLASSES (t
);
2691 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2692 sizeof (vptr_name
) - 1))
2694 TYPE_VPTR_FIELDNO (type
) = i
;
2698 /* Virtual function table field not found. */
2699 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2704 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2715 attach_fn_fields_to_type (fip
, type
)
2716 struct field_info
*fip
;
2717 register struct type
*type
;
2721 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2723 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2725 /* @@ Memory leak on objfile -> type_obstack? */
2728 TYPE_NFN_FIELDS_TOTAL (type
) +=
2729 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2732 for (n
= TYPE_NFN_FIELDS (type
);
2733 fip
-> fnlist
!= NULL
;
2734 fip
-> fnlist
= fip
-> fnlist
-> next
)
2736 --n
; /* Circumvent Sun3 compiler bug */
2737 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2742 /* Create the vector of fields, and record how big it is.
2743 We need this info to record proper virtual function table information
2744 for this class's virtual functions. */
2747 attach_fields_to_type (fip
, type
, objfile
)
2748 struct field_info
*fip
;
2749 register struct type
*type
;
2750 struct objfile
*objfile
;
2752 register int nfields
= 0;
2753 register int non_public_fields
= 0;
2754 register struct nextfield
*scan
;
2756 /* Count up the number of fields that we have, as well as taking note of
2757 whether or not there are any non-public fields, which requires us to
2758 allocate and build the private_field_bits and protected_field_bits
2761 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2764 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2766 non_public_fields
++;
2770 /* Now we know how many fields there are, and whether or not there are any
2771 non-public fields. Record the field count, allocate space for the
2772 array of fields, and create blank visibility bitfields if necessary. */
2774 TYPE_NFIELDS (type
) = nfields
;
2775 TYPE_FIELDS (type
) = (struct field
*)
2776 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2777 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2779 if (non_public_fields
)
2781 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2783 TYPE_FIELD_PRIVATE_BITS (type
) =
2784 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2785 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2787 TYPE_FIELD_PROTECTED_BITS (type
) =
2788 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2789 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2791 TYPE_FIELD_IGNORE_BITS (type
) =
2792 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2793 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2796 /* Copy the saved-up fields into the field vector. Start from the head
2797 of the list, adding to the tail of the field array, so that they end
2798 up in the same order in the array in which they were added to the list. */
2800 while (nfields
-- > 0)
2802 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2803 switch (fip
-> list
-> visibility
)
2805 case VISIBILITY_PRIVATE
:
2806 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2809 case VISIBILITY_PROTECTED
:
2810 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2813 case VISIBILITY_IGNORE
:
2814 SET_TYPE_FIELD_IGNORE (type
, nfields
);
2817 case VISIBILITY_PUBLIC
:
2821 /* Unknown visibility. Complain and treat it as public. */
2823 static struct complaint msg
= {
2824 "Unknown visibility `%c' for field", 0, 0};
2825 complain (&msg
, fip
-> list
-> visibility
);
2829 fip
-> list
= fip
-> list
-> next
;
2834 /* Read the description of a structure (or union type) and return an object
2835 describing the type.
2837 PP points to a character pointer that points to the next unconsumed token
2838 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2839 *PP will point to "4a:1,0,32;;".
2841 TYPE points to an incomplete type that needs to be filled in.
2843 OBJFILE points to the current objfile from which the stabs information is
2844 being read. (Note that it is redundant in that TYPE also contains a pointer
2845 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2848 static struct type
*
2849 read_struct_type (pp
, type
, objfile
)
2852 struct objfile
*objfile
;
2854 struct cleanup
*back_to
;
2855 struct field_info fi
;
2860 back_to
= make_cleanup (null_cleanup
, 0);
2862 INIT_CPLUS_SPECIFIC (type
);
2863 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2865 /* First comes the total size in bytes. */
2869 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2871 return error_type (pp
);
2874 /* Now read the baseclasses, if any, read the regular C struct or C++
2875 class member fields, attach the fields to the type, read the C++
2876 member functions, attach them to the type, and then read any tilde
2877 field (baseclass specifier for the class holding the main vtable). */
2879 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2880 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2881 || !attach_fields_to_type (&fi
, type
, objfile
)
2882 || !read_member_functions (&fi
, pp
, type
, objfile
)
2883 || !attach_fn_fields_to_type (&fi
, type
)
2884 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2886 do_cleanups (back_to
);
2887 return (error_type (pp
));
2890 do_cleanups (back_to
);
2894 /* Read a definition of an array type,
2895 and create and return a suitable type object.
2896 Also creates a range type which represents the bounds of that
2899 static struct type
*
2900 read_array_type (pp
, type
, objfile
)
2902 register struct type
*type
;
2903 struct objfile
*objfile
;
2905 struct type
*index_type
, *element_type
, *range_type
;
2910 /* Format of an array type:
2911 "ar<index type>;lower;upper;<array_contents_type>".
2912 OS9000: "arlower,upper;<array_contents_type>".
2914 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2915 for these, produce a type like float[][]. */
2918 index_type
= builtin_type_int
;
2921 index_type
= read_type (pp
, objfile
);
2923 /* Improper format of array type decl. */
2924 return error_type (pp
);
2928 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2933 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
2935 return error_type (pp
);
2937 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2942 upper
= read_huge_number (pp
, ';', &nbits
);
2944 return error_type (pp
);
2946 element_type
= read_type (pp
, objfile
);
2955 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2956 type
= create_array_type (type
, element_type
, range_type
);
2958 /* If we have an array whose element type is not yet known, but whose
2959 bounds *are* known, record it to be adjusted at the end of the file. */
2960 /* FIXME: Why check for zero length rather than TYPE_FLAG_STUB? I think
2961 the two have the same effect except that the latter is cleaner and the
2962 former would be wrong for types which really are zero-length (if we
2965 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2967 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2968 add_undefined_type (type
);
2975 /* Read a definition of an enumeration type,
2976 and create and return a suitable type object.
2977 Also defines the symbols that represent the values of the type. */
2979 static struct type
*
2980 read_enum_type (pp
, type
, objfile
)
2982 register struct type
*type
;
2983 struct objfile
*objfile
;
2988 register struct symbol
*sym
;
2990 struct pending
**symlist
;
2991 struct pending
*osyms
, *syms
;
2996 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2997 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2998 to do? For now, force all enum values to file scope. */
2999 if (within_function
)
3000 symlist
= &local_symbols
;
3003 symlist
= &file_symbols
;
3005 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3009 /* Size. Perhaps this does not have to be conditionalized on
3010 os9k_stabs (assuming the name of an enum constant can't start
3012 read_huge_number (pp
, 0, &nbits
);
3014 return error_type (pp
);
3017 /* Read the value-names and their values.
3018 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3019 A semicolon or comma instead of a NAME means the end. */
3020 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3022 STABS_CONTINUE (pp
);
3024 while (*p
!= ':') p
++;
3025 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3027 n
= read_huge_number (pp
, ',', &nbits
);
3029 return error_type (pp
);
3031 sym
= (struct symbol
*)
3032 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3033 memset (sym
, 0, sizeof (struct symbol
));
3034 SYMBOL_NAME (sym
) = name
;
3035 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3036 SYMBOL_CLASS (sym
) = LOC_CONST
;
3037 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3038 SYMBOL_VALUE (sym
) = n
;
3039 add_symbol_to_list (sym
, symlist
);
3044 (*pp
)++; /* Skip the semicolon. */
3046 /* Now fill in the fields of the type-structure. */
3048 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3049 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3050 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3051 TYPE_NFIELDS (type
) = nsyms
;
3052 TYPE_FIELDS (type
) = (struct field
*)
3053 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3054 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3056 /* Find the symbols for the values and put them into the type.
3057 The symbols can be found in the symlist that we put them on
3058 to cause them to be defined. osyms contains the old value
3059 of that symlist; everything up to there was defined by us. */
3060 /* Note that we preserve the order of the enum constants, so
3061 that in something like "enum {FOO, LAST_THING=FOO}" we print
3062 FOO, not LAST_THING. */
3064 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
3069 for (; j
< syms
->nsyms
; j
++,n
++)
3071 struct symbol
*xsym
= syms
->symbol
[j
];
3072 SYMBOL_TYPE (xsym
) = type
;
3073 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3074 TYPE_FIELD_VALUE (type
, n
) = 0;
3075 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3076 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3085 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3086 typedefs in every file (for int, long, etc):
3088 type = b <signed> <width>; <offset>; <nbits>
3089 signed = u or s. Possible c in addition to u or s (for char?).
3090 offset = offset from high order bit to start bit of type.
3091 width is # bytes in object of this type, nbits is # bits in type.
3093 The width/offset stuff appears to be for small objects stored in
3094 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3097 static struct type
*
3098 read_sun_builtin_type (pp
, typenums
, objfile
)
3101 struct objfile
*objfile
;
3116 return error_type (pp
);
3120 /* For some odd reason, all forms of char put a c here. This is strange
3121 because no other type has this honor. We can safely ignore this because
3122 we actually determine 'char'acterness by the number of bits specified in
3128 /* The first number appears to be the number of bytes occupied
3129 by this type, except that unsigned short is 4 instead of 2.
3130 Since this information is redundant with the third number,
3131 we will ignore it. */
3132 read_huge_number (pp
, ';', &nbits
);
3134 return error_type (pp
);
3136 /* The second number is always 0, so ignore it too. */
3137 read_huge_number (pp
, ';', &nbits
);
3139 return error_type (pp
);
3141 /* The third number is the number of bits for this type. */
3142 type_bits
= read_huge_number (pp
, 0, &nbits
);
3144 return error_type (pp
);
3145 /* The type *should* end with a semicolon. If it are embedded
3146 in a larger type the semicolon may be the only way to know where
3147 the type ends. If this type is at the end of the stabstring we
3148 can deal with the omitted semicolon (but we don't have to like
3149 it). Don't bother to complain(), Sun's compiler omits the semicolon
3154 return init_type (type_bits
== 0 ? TYPE_CODE_VOID
: TYPE_CODE_INT
,
3155 type_bits
/ TARGET_CHAR_BIT
,
3156 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3160 static struct type
*
3161 read_sun_floating_type (pp
, typenums
, objfile
)
3164 struct objfile
*objfile
;
3170 /* The first number has more details about the type, for example
3172 details
= read_huge_number (pp
, ';', &nbits
);
3174 return error_type (pp
);
3176 /* The second number is the number of bytes occupied by this type */
3177 nbytes
= read_huge_number (pp
, ';', &nbits
);
3179 return error_type (pp
);
3181 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3182 || details
== NF_COMPLEX32
)
3183 /* This is a type we can't handle, but we do know the size.
3184 We also will be able to give it a name. */
3185 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3187 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3190 /* Read a number from the string pointed to by *PP.
3191 The value of *PP is advanced over the number.
3192 If END is nonzero, the character that ends the
3193 number must match END, or an error happens;
3194 and that character is skipped if it does match.
3195 If END is zero, *PP is left pointing to that character.
3197 If the number fits in a long, set *BITS to 0 and return the value.
3198 If not, set *BITS to be the number of bits in the number and return 0.
3200 If encounter garbage, set *BITS to -1 and return 0. */
3203 read_huge_number (pp
, end
, bits
)
3223 /* Leading zero means octal. GCC uses this to output values larger
3224 than an int (because that would be hard in decimal). */
3231 upper_limit
= LONG_MAX
/ radix
;
3232 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3234 if (n
<= upper_limit
)
3237 n
+= c
- '0'; /* FIXME this overflows anyway */
3242 /* This depends on large values being output in octal, which is
3249 /* Ignore leading zeroes. */
3253 else if (c
== '2' || c
== '3')
3279 /* Large decimal constants are an error (because it is hard to
3280 count how many bits are in them). */
3286 /* -0x7f is the same as 0x80. So deal with it by adding one to
3287 the number of bits. */
3299 /* It's *BITS which has the interesting information. */
3303 static struct type
*
3304 read_range_type (pp
, typenums
, objfile
)
3307 struct objfile
*objfile
;
3313 struct type
*result_type
;
3314 struct type
*index_type
;
3316 /* First comes a type we are a subrange of.
3317 In C it is usually 0, 1 or the type being defined. */
3318 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3319 not just a type number. */
3320 if (read_type_number (pp
, rangenums
) != 0)
3321 return error_type (pp
);
3322 self_subrange
= (rangenums
[0] == typenums
[0] &&
3323 rangenums
[1] == typenums
[1]);
3325 /* A semicolon should now follow; skip it. */
3329 /* The remaining two operands are usually lower and upper bounds
3330 of the range. But in some special cases they mean something else. */
3331 n2
= read_huge_number (pp
, ';', &n2bits
);
3332 n3
= read_huge_number (pp
, ';', &n3bits
);
3334 if (n2bits
== -1 || n3bits
== -1)
3335 return error_type (pp
);
3337 /* If limits are huge, must be large integral type. */
3338 if (n2bits
!= 0 || n3bits
!= 0)
3340 char got_signed
= 0;
3341 char got_unsigned
= 0;
3342 /* Number of bits in the type. */
3345 /* Range from 0 to <large number> is an unsigned large integral type. */
3346 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3351 /* Range from <large number> to <large number>-1 is a large signed
3352 integral type. Take care of the case where <large number> doesn't
3353 fit in a long but <large number>-1 does. */
3354 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3355 || (n2bits
!= 0 && n3bits
== 0
3356 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3363 if (got_signed
|| got_unsigned
)
3365 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3366 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3370 return error_type (pp
);
3373 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3374 if (self_subrange
&& n2
== 0 && n3
== 0)
3375 return init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
3377 /* If n3 is zero and n2 is not, we want a floating type,
3378 and n2 is the width in bytes.
3380 Fortran programs appear to use this for complex types also,
3381 and they give no way to distinguish between double and single-complex!
3383 GDB does not have complex types.
3385 Just return the complex as a float of that size. It won't work right
3386 for the complex values, but at least it makes the file loadable. */
3388 if (n3
== 0 && n2
> 0)
3390 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3393 /* If the upper bound is -1, it must really be an unsigned int. */
3395 else if (n2
== 0 && n3
== -1)
3397 /* It is unsigned int or unsigned long. */
3398 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3399 compatibility hack. */
3400 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3401 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3404 /* Special case: char is defined (Who knows why) as a subrange of
3405 itself with range 0-127. */
3406 else if (self_subrange
&& n2
== 0 && n3
== 127)
3407 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3409 /* We used to do this only for subrange of self or subrange of int. */
3413 /* n3 actually gives the size. */
3414 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3417 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3419 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3421 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3422 "unsigned long", and we already checked for that,
3423 so don't need to test for it here. */
3425 /* I think this is for Convex "long long". Since I don't know whether
3426 Convex sets self_subrange, I also accept that particular size regardless
3427 of self_subrange. */
3428 else if (n3
== 0 && n2
< 0
3430 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3431 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3432 else if (n2
== -n3
-1)
3435 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3437 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3438 if (n3
== 0x7fffffff)
3439 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3442 /* We have a real range type on our hands. Allocate space and
3443 return a real pointer. */
3445 /* At this point I don't have the faintest idea how to deal with
3446 a self_subrange type; I'm going to assume that this is used
3447 as an idiom, and that all of them are special cases. So . . . */
3449 return error_type (pp
);
3451 index_type
= *dbx_lookup_type (rangenums
);
3452 if (index_type
== NULL
)
3454 /* Does this actually ever happen? Is that why we are worrying
3455 about dealing with it rather than just calling error_type? */
3457 static struct type
*range_type_index
;
3459 complain (&range_type_base_complaint
, rangenums
[1]);
3460 if (range_type_index
== NULL
)
3462 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3463 0, "range type index type", NULL
);
3464 index_type
= range_type_index
;
3467 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3468 return (result_type
);
3471 /* Read in an argument list. This is a list of types, separated by commas
3472 and terminated with END. Return the list of types read in, or (struct type
3473 **)-1 if there is an error. */
3475 static struct type
**
3476 read_args (pp
, end
, objfile
)
3479 struct objfile
*objfile
;
3481 /* FIXME! Remove this arbitrary limit! */
3482 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3488 /* Invalid argument list: no ','. */
3489 return (struct type
**)-1;
3491 STABS_CONTINUE (pp
);
3492 types
[n
++] = read_type (pp
, objfile
);
3494 (*pp
)++; /* get past `end' (the ':' character) */
3498 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3500 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3502 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3503 memset (rval
+ n
, 0, sizeof (struct type
*));
3507 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3509 memcpy (rval
, types
, n
* sizeof (struct type
*));
3513 /* Common block handling. */
3515 /* List of symbols declared since the last BCOMM. This list is a tail
3516 of local_symbols. When ECOMM is seen, the symbols on the list
3517 are noted so their proper addresses can be filled in later,
3518 using the common block base address gotten from the assembler
3521 static struct pending
*common_block
;
3522 static int common_block_i
;
3524 /* Name of the current common block. We get it from the BCOMM instead of the
3525 ECOMM to match IBM documentation (even though IBM puts the name both places
3526 like everyone else). */
3527 static char *common_block_name
;
3529 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3530 to remain after this function returns. */
3533 common_block_start (name
, objfile
)
3535 struct objfile
*objfile
;
3537 if (common_block_name
!= NULL
)
3539 static struct complaint msg
= {
3540 "Invalid symbol data: common block within common block",
3544 common_block
= local_symbols
;
3545 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3546 common_block_name
= obsavestring (name
, strlen (name
),
3547 &objfile
-> symbol_obstack
);
3550 /* Process a N_ECOMM symbol. */
3553 common_block_end (objfile
)
3554 struct objfile
*objfile
;
3556 /* Symbols declared since the BCOMM are to have the common block
3557 start address added in when we know it. common_block and
3558 common_block_i point to the first symbol after the BCOMM in
3559 the local_symbols list; copy the list and hang it off the
3560 symbol for the common block name for later fixup. */
3563 struct pending
*new = 0;
3564 struct pending
*next
;
3567 if (common_block_name
== NULL
)
3569 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
3574 sym
= (struct symbol
*)
3575 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3576 memset (sym
, 0, sizeof (struct symbol
));
3577 SYMBOL_NAME (sym
) = common_block_name
;
3578 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3580 /* Now we copy all the symbols which have been defined since the BCOMM. */
3582 /* Copy all the struct pendings before common_block. */
3583 for (next
= local_symbols
;
3584 next
!= NULL
&& next
!= common_block
;
3587 for (j
= 0; j
< next
->nsyms
; j
++)
3588 add_symbol_to_list (next
->symbol
[j
], &new);
3591 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3592 NULL, it means copy all the local symbols (which we already did
3595 if (common_block
!= NULL
)
3596 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
3597 add_symbol_to_list (common_block
->symbol
[j
], &new);
3599 SYMBOL_TYPE (sym
) = (struct type
*) new;
3601 /* Should we be putting local_symbols back to what it was?
3604 i
= hashname (SYMBOL_NAME (sym
));
3605 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3606 global_sym_chain
[i
] = sym
;
3607 common_block_name
= NULL
;
3610 /* Add a common block's start address to the offset of each symbol
3611 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3612 the common block name). */
3615 fix_common_block (sym
, valu
)
3619 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
3620 for ( ; next
; next
= next
->next
)
3623 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3624 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3630 /* What about types defined as forward references inside of a small lexical
3632 /* Add a type to the list of undefined types to be checked through
3633 once this file has been read in. */
3636 add_undefined_type (type
)
3639 if (undef_types_length
== undef_types_allocated
)
3641 undef_types_allocated
*= 2;
3642 undef_types
= (struct type
**)
3643 xrealloc ((char *) undef_types
,
3644 undef_types_allocated
* sizeof (struct type
*));
3646 undef_types
[undef_types_length
++] = type
;
3649 /* Go through each undefined type, see if it's still undefined, and fix it
3650 up if possible. We have two kinds of undefined types:
3652 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3653 Fix: update array length using the element bounds
3654 and the target type's length.
3655 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3656 yet defined at the time a pointer to it was made.
3657 Fix: Do a full lookup on the struct/union tag. */
3659 cleanup_undefined_types ()
3663 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3665 switch (TYPE_CODE (*type
))
3668 case TYPE_CODE_STRUCT
:
3669 case TYPE_CODE_UNION
:
3670 case TYPE_CODE_ENUM
:
3672 /* Check if it has been defined since. Need to do this here
3673 as well as in check_stub_type to deal with the (legitimate in
3674 C though not C++) case of several types with the same name
3675 in different source files. */
3676 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3678 struct pending
*ppt
;
3680 /* Name of the type, without "struct" or "union" */
3681 char *typename
= TYPE_TAG_NAME (*type
);
3683 if (typename
== NULL
)
3685 static struct complaint msg
= {"need a type name", 0, 0};
3689 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3691 for (i
= 0; i
< ppt
->nsyms
; i
++)
3693 struct symbol
*sym
= ppt
->symbol
[i
];
3695 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3696 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3697 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3699 && STREQ (SYMBOL_NAME (sym
), typename
))
3701 memcpy (*type
, SYMBOL_TYPE (sym
),
3702 sizeof (struct type
));
3710 case TYPE_CODE_ARRAY
:
3712 /* This is a kludge which is here for historical reasons
3713 because I suspect that check_stub_type does not get
3714 called everywhere it needs to be called for arrays. Even
3715 with this kludge, those places are broken for the case
3716 where the stub type is defined in another compilation
3717 unit, but this kludge at least deals with it for the case
3718 in which it is the same compilation unit.
3720 Don't try to do this by calling check_stub_type; it might
3721 cause symbols to be read in lookup_symbol, and the symbol
3722 reader is not reentrant. */
3724 struct type
*range_type
;
3727 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3729 if (TYPE_NFIELDS (*type
) != 1)
3731 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3732 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3735 /* Now recompute the length of the array type, based on its
3736 number of elements and the target type's length. */
3737 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3738 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3739 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3740 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3742 /* If the target type is not a stub, we could be clearing
3743 TYPE_FLAG_TARGET_STUB for *type. */
3750 static struct complaint msg
= {"\
3751 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3752 complain (&msg
, TYPE_CODE (*type
));
3758 undef_types_length
= 0;
3761 /* Scan through all of the global symbols defined in the object file,
3762 assigning values to the debugging symbols that need to be assigned
3763 to. Get these symbols from the minimal symbol table. */
3766 scan_file_globals (objfile
)
3767 struct objfile
*objfile
;
3770 struct minimal_symbol
*msymbol
;
3771 struct symbol
*sym
, *prev
;
3773 if (objfile
->msymbols
== 0) /* Beware the null file. */
3776 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3782 /* Get the hash index and check all the symbols
3783 under that hash index. */
3785 hash
= hashname (SYMBOL_NAME (msymbol
));
3787 for (sym
= global_sym_chain
[hash
]; sym
;)
3789 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3790 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3792 /* Splice this symbol out of the hash chain and
3793 assign the value we have to it. */
3796 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3800 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3803 /* Check to see whether we need to fix up a common block. */
3804 /* Note: this code might be executed several times for
3805 the same symbol if there are multiple references. */
3807 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3809 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3813 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3818 sym
= SYMBOL_VALUE_CHAIN (prev
);
3822 sym
= global_sym_chain
[hash
];
3828 sym
= SYMBOL_VALUE_CHAIN (sym
);
3834 /* Initialize anything that needs initializing when starting to read
3835 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3843 /* Initialize anything that needs initializing when a completely new
3844 symbol file is specified (not just adding some symbols from another
3845 file, e.g. a shared library). */
3848 stabsread_new_init ()
3850 /* Empty the hash table of global syms looking for values. */
3851 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3854 /* Initialize anything that needs initializing at the same time as
3855 start_symtab() is called. */
3859 global_stabs
= NULL
; /* AIX COFF */
3860 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3861 n_this_object_header_files
= 1;
3862 type_vector_length
= 0;
3863 type_vector
= (struct type
**) 0;
3865 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3866 common_block_name
= NULL
;
3871 /* Call after end_symtab() */
3877 free ((char *) type_vector
);
3880 type_vector_length
= 0;
3881 previous_stab_code
= 0;
3885 finish_global_stabs (objfile
)
3886 struct objfile
*objfile
;
3890 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3891 free ((PTR
) global_stabs
);
3892 global_stabs
= NULL
;
3896 /* Initializer for this module */
3899 _initialize_stabsread ()
3901 undef_types_allocated
= 20;
3902 undef_types_length
= 0;
3903 undef_types
= (struct type
**)
3904 xmalloc (undef_types_allocated
* sizeof (struct type
*));