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
);
402 /* FIXME-maybe: it would be nice if we noticed whether
403 the variable was defined *anywhere*, not just whether
404 it is defined in this compilation unit. But neither
405 xlc or GCC seem to need such a definition, and until
406 we do psymtabs (so that the minimal symbols from all
407 compilation units are available now), I'm not sure
408 how to get the information. */
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
);
440 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
443 lookup_function_type (read_type (&pp
, objfile
));
447 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
455 /* Read a number by which a type is referred to in dbx data,
456 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
457 Just a single number N is equivalent to (0,N).
458 Return the two numbers by storing them in the vector TYPENUMS.
459 TYPENUMS will then be used as an argument to dbx_lookup_type.
461 Returns 0 for success, -1 for error. */
464 read_type_number (pp
, typenums
)
466 register int *typenums
;
472 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
473 if (nbits
!= 0) return -1;
474 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
475 if (nbits
!= 0) return -1;
480 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
481 if (nbits
!= 0) return -1;
487 /* To handle GNU C++ typename abbreviation, we need to be able to
488 fill in a type's name as soon as space for that type is allocated.
489 `type_synonym_name' is the name of the type being allocated.
490 It is cleared as soon as it is used (lest all allocated types
493 static char *type_synonym_name
;
495 #if !defined (REG_STRUCT_HAS_ADDR)
496 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
501 define_symbol (valu
, string
, desc
, type
, objfile
)
506 struct objfile
*objfile
;
508 register struct symbol
*sym
;
509 char *p
= (char *) strchr (string
, ':');
514 /* We would like to eliminate nameless symbols, but keep their types.
515 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
516 to type 2, but, should not create a symbol to address that type. Since
517 the symbol will be nameless, there is no way any user can refer to it. */
521 /* Ignore syms with empty names. */
525 /* Ignore old-style symbols from cc -go */
535 /* If a nameless stab entry, all we need is the type, not the symbol.
536 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
537 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
539 sym
= (struct symbol
*)
540 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
541 memset (sym
, 0, sizeof (struct symbol
));
543 if (processing_gcc_compilation
)
545 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
546 number of bytes occupied by a type or object, which we ignore. */
547 SYMBOL_LINE(sym
) = desc
;
551 SYMBOL_LINE(sym
) = 0; /* unknown */
554 if (string
[0] == CPLUS_MARKER
)
556 /* Special GNU C++ names. */
560 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
561 &objfile
-> symbol_obstack
);
564 case 'v': /* $vtbl_ptr_type */
565 /* Was: SYMBOL_NAME (sym) = "vptr"; */
569 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
570 &objfile
-> symbol_obstack
);
574 /* This was an anonymous type that was never fixed up. */
578 complain (&unrecognized_cplus_name_complaint
, string
);
579 goto normal
; /* Do *something* with it */
585 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
586 SYMBOL_NAME (sym
) = (char *)
587 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
588 /* Open-coded memcpy--saves function call time. */
589 /* FIXME: Does it really? Try replacing with simple strcpy and
590 try it on an executable with a large symbol table. */
591 /* FIXME: considering that gcc can open code memcpy anyway, I
592 doubt it. xoxorich. */
594 register char *p1
= string
;
595 register char *p2
= SYMBOL_NAME (sym
);
603 /* If this symbol is from a C++ compilation, then attempt to cache the
604 demangled form for future reference. This is a typical time versus
605 space tradeoff, that was decided in favor of time because it sped up
606 C++ symbol lookups by a factor of about 20. */
608 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
612 /* Determine the type of name being defined. */
614 /* Getting GDB to correctly skip the symbol on an undefined symbol
615 descriptor and not ever dump core is a very dodgy proposition if
616 we do things this way. I say the acorn RISC machine can just
617 fix their compiler. */
618 /* The Acorn RISC machine's compiler can put out locals that don't
619 start with "234=" or "(3,4)=", so assume anything other than the
620 deftypes we know how to handle is a local. */
621 if (!strchr ("cfFGpPrStTvVXCR", *p
))
623 if (isdigit (*p
) || *p
== '(' || *p
== '-')
632 /* c is a special case, not followed by a type-number.
633 SYMBOL:c=iVALUE for an integer constant symbol.
634 SYMBOL:c=rVALUE for a floating constant symbol.
635 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
636 e.g. "b:c=e6,0" for "const b = blob1"
637 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
640 SYMBOL_CLASS (sym
) = LOC_CONST
;
641 SYMBOL_TYPE (sym
) = error_type (&p
);
642 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
643 add_symbol_to_list (sym
, &file_symbols
);
654 /* FIXME-if-picky-about-floating-accuracy: Should be using
655 target arithmetic to get the value. real.c in GCC
656 probably has the necessary code. */
658 /* FIXME: lookup_fundamental_type is a hack. We should be
659 creating a type especially for the type of float constants.
660 Problem is, what type should it be?
662 Also, what should the name of this type be? Should we
663 be using 'S' constants (see stabs.texinfo) instead? */
665 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
668 obstack_alloc (&objfile
-> symbol_obstack
,
669 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
670 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
671 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
672 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
677 /* Defining integer constants this way is kind of silly,
678 since 'e' constants allows the compiler to give not
679 only the value, but the type as well. C has at least
680 int, long, unsigned int, and long long as constant
681 types; other languages probably should have at least
682 unsigned as well as signed constants. */
684 /* We just need one int constant type for all objfiles.
685 It doesn't depend on languages or anything (arguably its
686 name should be a language-specific name for a type of
687 that size, but I'm inclined to say that if the compiler
688 wants a nice name for the type, it can use 'e'). */
689 static struct type
*int_const_type
;
691 /* Yes, this is as long as a *host* int. That is because we
693 if (int_const_type
== NULL
)
695 init_type (TYPE_CODE_INT
,
696 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
698 (struct objfile
*)NULL
);
699 SYMBOL_TYPE (sym
) = int_const_type
;
700 SYMBOL_VALUE (sym
) = atoi (p
);
701 SYMBOL_CLASS (sym
) = LOC_CONST
;
705 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
706 can be represented as integral.
707 e.g. "b:c=e6,0" for "const b = blob1"
708 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
710 SYMBOL_CLASS (sym
) = LOC_CONST
;
711 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
715 SYMBOL_TYPE (sym
) = error_type (&p
);
720 /* If the value is too big to fit in an int (perhaps because
721 it is unsigned), or something like that, we silently get
722 a bogus value. The type and everything else about it is
723 correct. Ideally, we should be using whatever we have
724 available for parsing unsigned and long long values,
726 SYMBOL_VALUE (sym
) = atoi (p
);
731 SYMBOL_CLASS (sym
) = LOC_CONST
;
732 SYMBOL_TYPE (sym
) = error_type (&p
);
735 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
736 add_symbol_to_list (sym
, &file_symbols
);
740 /* The name of a caught exception. */
741 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
742 SYMBOL_CLASS (sym
) = LOC_LABEL
;
743 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
744 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
745 add_symbol_to_list (sym
, &local_symbols
);
749 /* A static function definition. */
750 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
751 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
752 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
753 add_symbol_to_list (sym
, &file_symbols
);
754 /* fall into process_function_types. */
756 process_function_types
:
757 /* Function result types are described as the result type in stabs.
758 We need to convert this to the function-returning-type-X type
759 in GDB. E.g. "int" is converted to "function returning int". */
760 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
763 /* This code doesn't work -- it needs to realloc and can't. */
764 /* Attempt to set up to record a function prototype... */
765 struct type
*new = alloc_type (objfile
);
767 /* Generate a template for the type of this function. The
768 types of the arguments will be added as we read the symbol
770 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
771 SYMBOL_TYPE(sym
) = new;
772 TYPE_OBJFILE (new) = objfile
;
773 in_function_type
= new;
775 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
778 /* fall into process_prototype_types */
780 process_prototype_types
:
781 /* Sun acc puts declared types of arguments here. We don't care
782 about their actual types (FIXME -- we should remember the whole
783 function prototype), but the list may define some new types
784 that we have to remember, so we must scan it now. */
787 read_type (&p
, objfile
);
792 /* A global function definition. */
793 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
794 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
795 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
796 add_symbol_to_list (sym
, &global_symbols
);
797 goto process_function_types
;
800 /* For a class G (global) symbol, it appears that the
801 value is not correct. It is necessary to search for the
802 corresponding linker definition to find the value.
803 These definitions appear at the end of the namelist. */
804 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
805 i
= hashname (SYMBOL_NAME (sym
));
806 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
807 global_sym_chain
[i
] = sym
;
808 SYMBOL_CLASS (sym
) = LOC_STATIC
;
809 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
810 add_symbol_to_list (sym
, &global_symbols
);
813 /* This case is faked by a conditional above,
814 when there is no code letter in the dbx data.
815 Dbx data never actually contains 'l'. */
818 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
819 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
820 SYMBOL_VALUE (sym
) = valu
;
821 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
822 add_symbol_to_list (sym
, &local_symbols
);
827 /* pF is a two-letter code that means a function parameter in Fortran.
828 The type-number specifies the type of the return value.
829 Translate it into a pointer-to-function type. */
833 = lookup_pointer_type
834 (lookup_function_type (read_type (&p
, objfile
)));
837 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
839 /* Normally this is a parameter, a LOC_ARG. On the i960, it
840 can also be a LOC_LOCAL_ARG depending on symbol type. */
841 #ifndef DBX_PARM_SYMBOL_CLASS
842 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
845 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
846 SYMBOL_VALUE (sym
) = valu
;
847 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
849 /* This doesn't work yet. */
850 add_param_to_type (&in_function_type
, sym
);
852 add_symbol_to_list (sym
, &local_symbols
);
854 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
855 /* On little-endian machines, this crud is never necessary, and,
856 if the extra bytes contain garbage, is harmful. */
858 #else /* Big endian. */
859 /* If it's gcc-compiled, if it says `short', believe it. */
860 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
863 #if !BELIEVE_PCC_PROMOTION
865 /* This is the signed type which arguments get promoted to. */
866 static struct type
*pcc_promotion_type
;
867 /* This is the unsigned type which arguments get promoted to. */
868 static struct type
*pcc_unsigned_promotion_type
;
870 /* Call it "int" because this is mainly C lossage. */
871 if (pcc_promotion_type
== NULL
)
873 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
876 if (pcc_unsigned_promotion_type
== NULL
)
877 pcc_unsigned_promotion_type
=
878 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
879 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
881 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
882 /* This macro is defined on machines (e.g. sparc) where
883 we should believe the type of a PCC 'short' argument,
884 but shouldn't believe the address (the address is
885 the address of the corresponding int).
887 My guess is that this correction, as opposed to changing
888 the parameter to an 'int' (as done below, for PCC
889 on most machines), is the right thing to do
890 on all machines, but I don't want to risk breaking
891 something that already works. On most PCC machines,
892 the sparc problem doesn't come up because the calling
893 function has to zero the top bytes (not knowing whether
894 the called function wants an int or a short), so there
895 is little practical difference between an int and a short
896 (except perhaps what happens when the GDB user types
897 "print short_arg = 0x10000;").
899 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
900 actually produces the correct address (we don't need to fix it
901 up). I made this code adapt so that it will offset the symbol
902 if it was pointing at an int-aligned location and not
903 otherwise. This way you can use the same gdb for 4.0.x and
906 If the parameter is shorter than an int, and is integral
907 (e.g. char, short, or unsigned equivalent), and is claimed to
908 be passed on an integer boundary, don't believe it! Offset the
909 parameter's address to the tail-end of that integer. */
911 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
912 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
913 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
915 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
916 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
920 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
922 /* If PCC says a parameter is a short or a char,
923 it is really an int. */
924 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
925 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
928 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
929 ? pcc_unsigned_promotion_type
930 : pcc_promotion_type
;
934 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
936 #endif /* !BELIEVE_PCC_PROMOTION. */
937 #endif /* Big endian. */
940 /* acc seems to use P to delare the prototypes of functions that
941 are referenced by this file. gdb is not prepared to deal
942 with this extra information. FIXME, it ought to. */
945 read_type (&p
, objfile
);
946 goto process_prototype_types
;
951 /* Parameter which is in a register. */
952 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
953 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
954 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
955 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
957 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
958 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
960 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
961 add_symbol_to_list (sym
, &local_symbols
);
965 /* Register variable (either global or local). */
966 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
967 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
968 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
969 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
971 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
972 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
974 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
977 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
978 name to represent an argument passed in a register.
979 GCC uses 'P' for the same case. So if we find such a symbol pair
980 we combine it into one 'P' symbol. For Sun cc we need to do this
981 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
982 the 'p' symbol even if it never saves the argument onto the stack.
984 On most machines, we want to preserve both symbols, so that
985 we can still get information about what is going on with the
986 stack (VAX for computing args_printed, using stack slots instead
987 of saved registers in backtraces, etc.).
989 Note that this code illegally combines
990 main(argc) struct foo argc; { register struct foo argc; }
991 but this case is considered pathological and causes a warning
992 from a decent compiler. */
995 && local_symbols
->nsyms
> 0
996 #ifndef USE_REGISTER_NOT_ARG
997 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
999 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1000 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1004 struct symbol
*prev_sym
;
1005 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1006 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1007 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1008 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
1010 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1011 /* Use the type from the LOC_REGISTER; that is the type
1012 that is actually in that register. */
1013 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1014 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1019 add_symbol_to_list (sym
, &local_symbols
);
1022 add_symbol_to_list (sym
, &file_symbols
);
1026 /* Static symbol at top level of file */
1027 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1028 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1029 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1030 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1031 add_symbol_to_list (sym
, &file_symbols
);
1035 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1037 /* For a nameless type, we don't want a create a symbol, thus we
1038 did not use `sym'. Return without further processing. */
1039 if (nameless
) return NULL
;
1041 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1042 SYMBOL_VALUE (sym
) = valu
;
1043 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1044 /* C++ vagaries: we may have a type which is derived from
1045 a base type which did not have its name defined when the
1046 derived class was output. We fill in the derived class's
1047 base part member's name here in that case. */
1048 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1049 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1050 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1051 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1054 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1055 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1056 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1057 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1060 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1062 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1063 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1065 /* If we are giving a name to a type such as "pointer to
1066 foo" or "function returning foo", we better not set
1067 the TYPE_NAME. If the program contains "typedef char
1068 *caddr_t;", we don't want all variables of type char
1069 * to print as caddr_t. This is not just a
1070 consequence of GDB's type management; PCC and GCC (at
1071 least through version 2.4) both output variables of
1072 either type char * or caddr_t with the type number
1073 defined in the 't' symbol for caddr_t. If a future
1074 compiler cleans this up it GDB is not ready for it
1075 yet, but if it becomes ready we somehow need to
1076 disable this check (without breaking the PCC/GCC2.4
1081 Fortunately, this check seems not to be necessary
1082 for anything except pointers or functions. */
1085 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1088 add_symbol_to_list (sym
, &file_symbols
);
1092 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1093 by 't' which means we are typedef'ing it as well. */
1094 synonym
= *p
== 't';
1099 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1100 strlen (SYMBOL_NAME (sym
)),
1101 &objfile
-> symbol_obstack
);
1103 /* The semantics of C++ state that "struct foo { ... }" also defines
1104 a typedef for "foo". Unfortunately, cfront never makes the typedef
1105 when translating C++ into C. We make the typedef here so that
1106 "ptype foo" works as expected for cfront translated code. */
1107 else if (current_subfile
->language
== language_cplus
)
1110 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1111 strlen (SYMBOL_NAME (sym
)),
1112 &objfile
-> symbol_obstack
);
1115 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1117 /* For a nameless type, we don't want a create a symbol, thus we
1118 did not use `sym'. Return without further processing. */
1119 if (nameless
) return NULL
;
1121 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1122 SYMBOL_VALUE (sym
) = valu
;
1123 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1124 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1125 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1126 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1127 add_symbol_to_list (sym
, &file_symbols
);
1131 /* Clone the sym and then modify it. */
1132 register struct symbol
*typedef_sym
= (struct symbol
*)
1133 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1134 *typedef_sym
= *sym
;
1135 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1136 SYMBOL_VALUE (typedef_sym
) = valu
;
1137 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1138 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1139 TYPE_NAME (SYMBOL_TYPE (sym
))
1140 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1141 add_symbol_to_list (typedef_sym
, &file_symbols
);
1146 /* Static symbol of local scope */
1147 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1148 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1149 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1150 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1152 add_symbol_to_list (sym
, &global_symbols
);
1154 add_symbol_to_list (sym
, &local_symbols
);
1158 /* Reference parameter */
1159 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1160 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1161 SYMBOL_VALUE (sym
) = valu
;
1162 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1163 add_symbol_to_list (sym
, &local_symbols
);
1167 /* This is used by Sun FORTRAN for "function result value".
1168 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1169 that Pascal uses it too, but when I tried it Pascal used
1170 "x:3" (local symbol) instead. */
1171 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1172 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1173 SYMBOL_VALUE (sym
) = valu
;
1174 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1175 add_symbol_to_list (sym
, &local_symbols
);
1179 SYMBOL_TYPE (sym
) = error_type (&p
);
1180 SYMBOL_CLASS (sym
) = LOC_CONST
;
1181 SYMBOL_VALUE (sym
) = 0;
1182 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1183 add_symbol_to_list (sym
, &file_symbols
);
1187 /* When passing structures to a function, some systems sometimes pass
1188 the address in a register, not the structure itself.
1190 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1191 to LOC_REGPARM_ADDR for structures and unions. */
1193 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1194 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1196 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1197 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1198 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1200 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1201 subsequent arguments on the sparc, for example). */
1202 if (SYMBOL_CLASS (sym
) == LOC_ARG
1203 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1205 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1206 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1207 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1213 /* Skip rest of this symbol and return an error type.
1215 General notes on error recovery: error_type always skips to the
1216 end of the symbol (modulo cretinous dbx symbol name continuation).
1217 Thus code like this:
1219 if (*(*pp)++ != ';')
1220 return error_type (pp);
1222 is wrong because if *pp starts out pointing at '\0' (typically as the
1223 result of an earlier error), it will be incremented to point to the
1224 start of the next symbol, which might produce strange results, at least
1225 if you run off the end of the string table. Instead use
1228 return error_type (pp);
1234 foo = error_type (pp);
1238 And in case it isn't obvious, the point of all this hair is so the compiler
1239 can define new types and new syntaxes, and old versions of the
1240 debugger will be able to read the new symbol tables. */
1242 static struct type
*
1246 complain (&error_type_complaint
);
1249 /* Skip to end of symbol. */
1250 while (**pp
!= '\0')
1255 /* Check for and handle cretinous dbx symbol name continuation! */
1256 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1258 *pp
= next_symbol_text ();
1265 return (builtin_type_error
);
1269 /* Read type information or a type definition; return the type. Even
1270 though this routine accepts either type information or a type
1271 definition, the distinction is relevant--some parts of stabsread.c
1272 assume that type information starts with a digit, '-', or '(' in
1273 deciding whether to call read_type. */
1276 read_type (pp
, objfile
)
1278 struct objfile
*objfile
;
1280 register struct type
*type
= 0;
1284 char type_descriptor
;
1286 /* Size in bits of type if specified by a type attribute, or -1 if
1287 there is no size attribute. */
1290 /* Used to distinguish string and bitstring from char-array and set. */
1293 /* Read type number if present. The type number may be omitted.
1294 for instance in a two-dimensional array declared with type
1295 "ar1;1;10;ar1;1;10;4". */
1296 if ((**pp
>= '0' && **pp
<= '9')
1300 if (read_type_number (pp
, typenums
) != 0)
1301 return error_type (pp
);
1303 /* Type is not being defined here. Either it already exists,
1304 or this is a forward reference to it. dbx_alloc_type handles
1307 return dbx_alloc_type (typenums
, objfile
);
1309 /* Type is being defined here. */
1316 /* It might be a type attribute or a member type. */
1317 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1322 /* Type attributes. */
1325 /* Skip to the semicolon. */
1326 while (*p
!= ';' && *p
!= '\0')
1330 return error_type (pp
);
1332 /* Skip the semicolon. */
1338 type_size
= atoi (attr
+ 1);
1348 /* Ignore unrecognized type attributes, so future compilers
1349 can invent new ones. */
1354 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1359 /* 'typenums=' not present, type is anonymous. Read and return
1360 the definition, but don't put it in the type vector. */
1361 typenums
[0] = typenums
[1] = -1;
1365 type_descriptor
= (*pp
)[-1];
1366 switch (type_descriptor
)
1370 enum type_code code
;
1372 /* Used to index through file_symbols. */
1373 struct pending
*ppt
;
1376 /* Name including "struct", etc. */
1380 char *from
, *to
, *p
, *q1
, *q2
;
1382 /* Set the type code according to the following letter. */
1386 code
= TYPE_CODE_STRUCT
;
1389 code
= TYPE_CODE_UNION
;
1392 code
= TYPE_CODE_ENUM
;
1396 /* Complain and keep going, so compilers can invent new
1397 cross-reference types. */
1398 static struct complaint msg
=
1399 {"Unrecognized cross-reference type `%c'", 0, 0};
1400 complain (&msg
, (*pp
)[0]);
1401 code
= TYPE_CODE_STRUCT
;
1406 q1
= strchr(*pp
, '<');
1407 p
= strchr(*pp
, ':');
1409 return error_type (pp
);
1410 while (q1
&& p
> q1
&& p
[1] == ':')
1412 q2
= strchr(q1
, '>');
1418 return error_type (pp
);
1421 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1423 /* Copy the name. */
1429 /* Set the pointer ahead of the name which we just read, and
1434 /* Now check to see whether the type has already been
1435 declared. This was written for arrays of cross-referenced
1436 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1437 sure it is not necessary anymore. But it might be a good
1438 idea, to save a little memory. */
1440 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1441 for (i
= 0; i
< ppt
->nsyms
; i
++)
1443 struct symbol
*sym
= ppt
->symbol
[i
];
1445 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1446 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1447 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1448 && STREQ (SYMBOL_NAME (sym
), type_name
))
1450 obstack_free (&objfile
-> type_obstack
, type_name
);
1451 type
= SYMBOL_TYPE (sym
);
1456 /* Didn't find the type to which this refers, so we must
1457 be dealing with a forward reference. Allocate a type
1458 structure for it, and keep track of it so we can
1459 fill in the rest of the fields when we get the full
1461 type
= dbx_alloc_type (typenums
, objfile
);
1462 TYPE_CODE (type
) = code
;
1463 TYPE_TAG_NAME (type
) = type_name
;
1464 INIT_CPLUS_SPECIFIC(type
);
1465 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1467 add_undefined_type (type
);
1471 case '-': /* RS/6000 built-in type */
1490 /* Peek ahead at the number to detect void. */
1491 if (read_type_number (pp
, xtypenums
) != 0)
1492 return error_type (pp
);
1494 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1495 /* It's being defined as itself. That means it is "void". */
1496 type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
1501 /* Go back to the number and have read_type get it. This means
1502 that we can deal with something like t(1,2)=(3,4)=... which
1503 the Lucid compiler uses. */
1505 xtype
= read_type (pp
, objfile
);
1507 /* The type is being defined to another type. So we copy the type.
1508 This loses if we copy a C++ class and so we lose track of how
1509 the names are mangled (but g++ doesn't output stabs like this
1512 type
= alloc_type (objfile
);
1513 memcpy (type
, xtype
, sizeof (struct type
));
1515 /* The idea behind clearing the names is that the only purpose
1516 for defining a type to another type is so that the name of
1517 one can be different. So we probably don't need to worry much
1518 about the case where the compiler doesn't give a name to the
1520 TYPE_NAME (type
) = NULL
;
1521 TYPE_TAG_NAME (type
) = NULL
;
1523 if (typenums
[0] != -1)
1524 *dbx_lookup_type (typenums
) = type
;
1528 /* In the following types, we must be sure to overwrite any existing
1529 type that the typenums refer to, rather than allocating a new one
1530 and making the typenums point to the new one. This is because there
1531 may already be pointers to the existing type (if it had been
1532 forward-referenced), and we must change it to a pointer, function,
1533 reference, or whatever, *in-place*. */
1536 type1
= read_type (pp
, objfile
);
1537 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1540 case '&': /* Reference to another type */
1541 type1
= read_type (pp
, objfile
);
1542 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1545 case 'f': /* Function returning another type */
1546 if (os9k_stabs
&& **pp
== '(')
1548 /* Function prototype; skip it.
1549 We must conditionalize this on os9k_stabs because otherwise
1550 it could be confused with a Sun-style (1,3) typenumber
1556 type1
= read_type (pp
, objfile
);
1557 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1560 case 'k': /* Const qualifier on some type (Sun) */
1561 case 'c': /* Const qualifier on some type (OS9000) */
1562 /* Because 'c' means other things to AIX and 'k' is perfectly good,
1563 only accept 'c' in the os9k_stabs case. */
1564 if (type_descriptor
== 'c' && !os9k_stabs
)
1565 return error_type (pp
);
1566 type
= read_type (pp
, objfile
);
1567 /* FIXME! For now, we ignore const and volatile qualifiers. */
1570 case 'B': /* Volatile qual on some type (Sun) */
1571 case 'i': /* Volatile qual on some type (OS9000) */
1572 /* Because 'i' means other things to AIX and 'B' is perfectly good,
1573 only accept 'i' in the os9k_stabs case. */
1574 if (type_descriptor
== 'i' && !os9k_stabs
)
1575 return error_type (pp
);
1576 type
= read_type (pp
, objfile
);
1577 /* FIXME! For now, we ignore const and volatile qualifiers. */
1580 /* FIXME -- we should be doing smash_to_XXX types here. */
1581 case '@': /* Member (class & variable) type */
1583 struct type
*domain
= read_type (pp
, objfile
);
1584 struct type
*memtype
;
1587 /* Invalid member type data format. */
1588 return error_type (pp
);
1591 memtype
= read_type (pp
, objfile
);
1592 type
= dbx_alloc_type (typenums
, objfile
);
1593 smash_to_member_type (type
, domain
, memtype
);
1597 case '#': /* Method (class & fn) type */
1598 if ((*pp
)[0] == '#')
1600 /* We'll get the parameter types from the name. */
1601 struct type
*return_type
;
1604 return_type
= read_type (pp
, objfile
);
1605 if (*(*pp
)++ != ';')
1606 complain (&invalid_member_complaint
, symnum
);
1607 type
= allocate_stub_method (return_type
);
1608 if (typenums
[0] != -1)
1609 *dbx_lookup_type (typenums
) = type
;
1613 struct type
*domain
= read_type (pp
, objfile
);
1614 struct type
*return_type
;
1618 /* Invalid member type data format. */
1619 return error_type (pp
);
1623 return_type
= read_type (pp
, objfile
);
1624 args
= read_args (pp
, ';', objfile
);
1625 type
= dbx_alloc_type (typenums
, objfile
);
1626 smash_to_method_type (type
, domain
, return_type
, args
);
1630 case 'r': /* Range type */
1631 type
= read_range_type (pp
, typenums
, objfile
);
1632 if (typenums
[0] != -1)
1633 *dbx_lookup_type (typenums
) = type
;
1638 /* Const and volatile qualified type. */
1639 type
= read_type (pp
, objfile
);
1642 /* Sun ACC builtin int type */
1643 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1644 if (typenums
[0] != -1)
1645 *dbx_lookup_type (typenums
) = type
;
1649 case 'R': /* Sun ACC builtin float type */
1650 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1651 if (typenums
[0] != -1)
1652 *dbx_lookup_type (typenums
) = type
;
1655 case 'e': /* Enumeration type */
1656 type
= dbx_alloc_type (typenums
, objfile
);
1657 type
= read_enum_type (pp
, type
, objfile
);
1658 if (typenums
[0] != -1)
1659 *dbx_lookup_type (typenums
) = type
;
1662 case 's': /* Struct type */
1663 case 'u': /* Union type */
1664 type
= dbx_alloc_type (typenums
, objfile
);
1665 if (!TYPE_NAME (type
))
1667 TYPE_NAME (type
) = type_synonym_name
;
1669 type_synonym_name
= NULL
;
1670 switch (type_descriptor
)
1673 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1676 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1679 type
= read_struct_type (pp
, type
, objfile
);
1682 case 'a': /* Array type */
1684 return error_type (pp
);
1687 type
= dbx_alloc_type (typenums
, objfile
);
1688 type
= read_array_type (pp
, type
, objfile
);
1690 TYPE_CODE (type
) = TYPE_CODE_STRING
;
1694 type1
= read_type (pp
, objfile
);
1695 type
= create_set_type ((struct type
*) NULL
, type1
);
1697 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
1698 if (typenums
[0] != -1)
1699 *dbx_lookup_type (typenums
) = type
;
1703 --*pp
; /* Go back to the symbol in error */
1704 /* Particularly important if it was \0! */
1705 return error_type (pp
);
1710 warning ("GDB internal error, type is NULL in stabsread.c\n");
1711 return error_type (pp
);
1714 /* Size specified in a type attribute overrides any other size. */
1715 if (type_size
!= -1)
1716 TYPE_LENGTH (type
) = type_size
/ TARGET_CHAR_BIT
;
1721 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1722 Return the proper type node for a given builtin type number. */
1724 static struct type
*
1725 rs6000_builtin_type (typenum
)
1728 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1729 #define NUMBER_RECOGNIZED 30
1730 /* This includes an empty slot for type number -0. */
1731 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1732 struct type
*rettype
= NULL
;
1734 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1736 complain (&rs6000_builtin_complaint
, typenum
);
1737 return builtin_type_error
;
1739 if (negative_types
[-typenum
] != NULL
)
1740 return negative_types
[-typenum
];
1742 #if TARGET_CHAR_BIT != 8
1743 #error This code wrong for TARGET_CHAR_BIT not 8
1744 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1745 that if that ever becomes not true, the correct fix will be to
1746 make the size in the struct type to be in bits, not in units of
1753 /* The size of this and all the other types are fixed, defined
1754 by the debugging format. If there is a type called "int" which
1755 is other than 32 bits, then it should use a new negative type
1756 number (or avoid negative type numbers for that case).
1757 See stabs.texinfo. */
1758 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1761 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1764 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1767 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1770 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1771 "unsigned char", NULL
);
1774 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1777 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1778 "unsigned short", NULL
);
1781 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1782 "unsigned int", NULL
);
1785 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1788 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1789 "unsigned long", NULL
);
1792 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
1795 /* IEEE single precision (32 bit). */
1796 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1799 /* IEEE double precision (64 bit). */
1800 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1803 /* This is an IEEE double on the RS/6000, and different machines with
1804 different sizes for "long double" should use different negative
1805 type numbers. See stabs.texinfo. */
1806 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1809 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1812 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1815 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1818 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1821 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1824 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1828 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1832 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1836 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1840 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1844 /* Complex type consisting of two IEEE single precision values. */
1845 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1848 /* Complex type consisting of two IEEE double precision values. */
1849 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1852 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1855 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1858 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1861 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1864 negative_types
[-typenum
] = rettype
;
1868 /* This page contains subroutines of read_type. */
1870 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1871 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1872 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1873 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1875 /* Read member function stabs info for C++ classes. The form of each member
1878 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1880 An example with two member functions is:
1882 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1884 For the case of overloaded operators, the format is op$::*.funcs, where
1885 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1886 name (such as `+=') and `.' marks the end of the operator name.
1888 Returns 1 for success, 0 for failure. */
1891 read_member_functions (fip
, pp
, type
, objfile
)
1892 struct field_info
*fip
;
1895 struct objfile
*objfile
;
1899 /* Total number of member functions defined in this class. If the class
1900 defines two `f' functions, and one `g' function, then this will have
1902 int total_length
= 0;
1906 struct next_fnfield
*next
;
1907 struct fn_field fn_field
;
1909 struct type
*look_ahead_type
;
1910 struct next_fnfieldlist
*new_fnlist
;
1911 struct next_fnfield
*new_sublist
;
1915 /* Process each list until we find something that is not a member function
1916 or find the end of the functions. */
1920 /* We should be positioned at the start of the function name.
1921 Scan forward to find the first ':' and if it is not the
1922 first of a "::" delimiter, then this is not a member function. */
1934 look_ahead_type
= NULL
;
1937 new_fnlist
= (struct next_fnfieldlist
*)
1938 xmalloc (sizeof (struct next_fnfieldlist
));
1939 make_cleanup (free
, new_fnlist
);
1940 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1942 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1944 /* This is a completely wierd case. In order to stuff in the
1945 names that might contain colons (the usual name delimiter),
1946 Mike Tiemann defined a different name format which is
1947 signalled if the identifier is "op$". In that case, the
1948 format is "op$::XXXX." where XXXX is the name. This is
1949 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1950 /* This lets the user type "break operator+".
1951 We could just put in "+" as the name, but that wouldn't
1953 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1954 char *o
= opname
+ 3;
1956 /* Skip past '::'. */
1959 STABS_CONTINUE (pp
);
1965 main_fn_name
= savestring (opname
, o
- opname
);
1971 main_fn_name
= savestring (*pp
, p
- *pp
);
1972 /* Skip past '::'. */
1975 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1980 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1981 make_cleanup (free
, new_sublist
);
1982 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1984 /* Check for and handle cretinous dbx symbol name continuation! */
1985 if (look_ahead_type
== NULL
)
1988 STABS_CONTINUE (pp
);
1990 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1993 /* Invalid symtab info for member function. */
1999 /* g++ version 1 kludge */
2000 new_sublist
-> fn_field
.type
= look_ahead_type
;
2001 look_ahead_type
= NULL
;
2011 /* If this is just a stub, then we don't have the real name here. */
2013 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2015 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2016 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2017 new_sublist
-> fn_field
.is_stub
= 1;
2019 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2022 /* Set this member function's visibility fields. */
2025 case VISIBILITY_PRIVATE
:
2026 new_sublist
-> fn_field
.is_private
= 1;
2028 case VISIBILITY_PROTECTED
:
2029 new_sublist
-> fn_field
.is_protected
= 1;
2033 STABS_CONTINUE (pp
);
2036 case 'A': /* Normal functions. */
2037 new_sublist
-> fn_field
.is_const
= 0;
2038 new_sublist
-> fn_field
.is_volatile
= 0;
2041 case 'B': /* `const' member functions. */
2042 new_sublist
-> fn_field
.is_const
= 1;
2043 new_sublist
-> fn_field
.is_volatile
= 0;
2046 case 'C': /* `volatile' member function. */
2047 new_sublist
-> fn_field
.is_const
= 0;
2048 new_sublist
-> fn_field
.is_volatile
= 1;
2051 case 'D': /* `const volatile' member function. */
2052 new_sublist
-> fn_field
.is_const
= 1;
2053 new_sublist
-> fn_field
.is_volatile
= 1;
2056 case '*': /* File compiled with g++ version 1 -- no info */
2061 complain (&const_vol_complaint
, **pp
);
2070 /* virtual member function, followed by index.
2071 The sign bit is set to distinguish pointers-to-methods
2072 from virtual function indicies. Since the array is
2073 in words, the quantity must be shifted left by 1
2074 on 16 bit machine, and by 2 on 32 bit machine, forcing
2075 the sign bit out, and usable as a valid index into
2076 the array. Remove the sign bit here. */
2077 new_sublist
-> fn_field
.voffset
=
2078 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2082 STABS_CONTINUE (pp
);
2083 if (**pp
== ';' || **pp
== '\0')
2085 /* Must be g++ version 1. */
2086 new_sublist
-> fn_field
.fcontext
= 0;
2090 /* Figure out from whence this virtual function came.
2091 It may belong to virtual function table of
2092 one of its baseclasses. */
2093 look_ahead_type
= read_type (pp
, objfile
);
2096 /* g++ version 1 overloaded methods. */
2100 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2109 look_ahead_type
= NULL
;
2115 /* static member function. */
2116 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2117 if (strncmp (new_sublist
-> fn_field
.physname
,
2118 main_fn_name
, strlen (main_fn_name
)))
2120 new_sublist
-> fn_field
.is_stub
= 1;
2126 complain (&member_fn_complaint
, (*pp
)[-1]);
2127 /* Fall through into normal member function. */
2130 /* normal member function. */
2131 new_sublist
-> fn_field
.voffset
= 0;
2132 new_sublist
-> fn_field
.fcontext
= 0;
2136 new_sublist
-> next
= sublist
;
2137 sublist
= new_sublist
;
2139 STABS_CONTINUE (pp
);
2141 while (**pp
!= ';' && **pp
!= '\0');
2145 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2146 obstack_alloc (&objfile
-> type_obstack
,
2147 sizeof (struct fn_field
) * length
);
2148 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2149 sizeof (struct fn_field
) * length
);
2150 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2152 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2155 new_fnlist
-> fn_fieldlist
.length
= length
;
2156 new_fnlist
-> next
= fip
-> fnlist
;
2157 fip
-> fnlist
= new_fnlist
;
2159 total_length
+= length
;
2160 STABS_CONTINUE (pp
);
2165 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2166 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2167 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2168 memset (TYPE_FN_FIELDLISTS (type
), 0,
2169 sizeof (struct fn_fieldlist
) * nfn_fields
);
2170 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2171 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2177 /* Special GNU C++ name.
2179 Returns 1 for success, 0 for failure. "failure" means that we can't
2180 keep parsing and it's time for error_type(). */
2183 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2184 struct field_info
*fip
;
2187 struct objfile
*objfile
;
2192 struct type
*context
;
2202 /* At this point, *pp points to something like "22:23=*22...",
2203 where the type number before the ':' is the "context" and
2204 everything after is a regular type definition. Lookup the
2205 type, find it's name, and construct the field name. */
2207 context
= read_type (pp
, objfile
);
2211 case 'f': /* $vf -- a virtual function table pointer */
2212 fip
->list
->field
.name
=
2213 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2216 case 'b': /* $vb -- a virtual bsomethingorother */
2217 name
= type_name_no_tag (context
);
2220 complain (&invalid_cpp_type_complaint
, symnum
);
2223 fip
->list
->field
.name
=
2224 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2228 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2229 fip
->list
->field
.name
=
2230 obconcat (&objfile
->type_obstack
,
2231 "INVALID_CPLUSPLUS_ABBREV", "", "");
2235 /* At this point, *pp points to the ':'. Skip it and read the
2241 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2244 fip
->list
->field
.type
= read_type (pp
, objfile
);
2246 (*pp
)++; /* Skip the comma. */
2252 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2256 /* This field is unpacked. */
2257 fip
->list
->field
.bitsize
= 0;
2258 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2262 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2263 /* We have no idea what syntax an unrecognized abbrev would have, so
2264 better return 0. If we returned 1, we would need to at least advance
2265 *pp to avoid an infinite loop. */
2272 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2273 struct field_info
*fip
;
2277 struct objfile
*objfile
;
2279 fip
-> list
-> field
.name
=
2280 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2283 /* This means we have a visibility for a field coming. */
2287 fip
-> list
-> visibility
= *(*pp
)++;
2291 /* normal dbx-style format, no explicit visibility */
2292 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2295 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2300 /* Possible future hook for nested types. */
2303 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2309 /* Static class member. */
2310 fip
-> list
-> field
.bitpos
= (long) -1;
2316 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2320 else if (**pp
!= ',')
2322 /* Bad structure-type format. */
2323 complain (&stabs_general_complaint
, "bad structure-type format");
2327 (*pp
)++; /* Skip the comma. */
2331 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2334 complain (&stabs_general_complaint
, "bad structure-type format");
2337 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2340 complain (&stabs_general_complaint
, "bad structure-type format");
2345 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2347 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2348 it is a field which has been optimized out. The correct stab for
2349 this case is to use VISIBILITY_IGNORE, but that is a recent
2350 invention. (2) It is a 0-size array. For example
2351 union { int num; char str[0]; } foo. Printing "<no value>" for
2352 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2353 will continue to work, and a 0-size array as a whole doesn't
2354 have any contents to print.
2356 I suspect this probably could also happen with gcc -gstabs (not
2357 -gstabs+) for static fields, and perhaps other C++ extensions.
2358 Hopefully few people use -gstabs with gdb, since it is intended
2359 for dbx compatibility. */
2361 /* Ignore this field. */
2362 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2366 /* Detect an unpacked field and mark it as such.
2367 dbx gives a bit size for all fields.
2368 Note that forward refs cannot be packed,
2369 and treat enums as if they had the width of ints. */
2371 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2372 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2374 fip
-> list
-> field
.bitsize
= 0;
2376 if ((fip
-> list
-> field
.bitsize
2377 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2378 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2379 && (fip
-> list
-> field
.bitsize
2384 fip
-> list
-> field
.bitpos
% 8 == 0)
2386 fip
-> list
-> field
.bitsize
= 0;
2392 /* Read struct or class data fields. They have the form:
2394 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2396 At the end, we see a semicolon instead of a field.
2398 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2401 The optional VISIBILITY is one of:
2403 '/0' (VISIBILITY_PRIVATE)
2404 '/1' (VISIBILITY_PROTECTED)
2405 '/2' (VISIBILITY_PUBLIC)
2406 '/9' (VISIBILITY_IGNORE)
2408 or nothing, for C style fields with public visibility.
2410 Returns 1 for success, 0 for failure. */
2413 read_struct_fields (fip
, pp
, type
, objfile
)
2414 struct field_info
*fip
;
2417 struct objfile
*objfile
;
2420 struct nextfield
*new;
2422 /* We better set p right now, in case there are no fields at all... */
2426 /* Read each data member type until we find the terminating ';' at the end of
2427 the data member list, or break for some other reason such as finding the
2428 start of the member function list. */
2432 STABS_CONTINUE (pp
);
2433 /* Get space to record the next field's data. */
2434 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2435 make_cleanup (free
, new);
2436 memset (new, 0, sizeof (struct nextfield
));
2437 new -> next
= fip
-> list
;
2440 /* Get the field name. */
2443 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2444 unless the CPLUS_MARKER is followed by an underscore, in
2445 which case it is just the name of an anonymous type, which we
2446 should handle like any other type name. We accept either '$'
2447 or '.', because a field name can never contain one of these
2448 characters except as a CPLUS_MARKER (we probably should be
2449 doing that in most parts of GDB). */
2451 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2453 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2458 /* Look for the ':' that separates the field name from the field
2459 values. Data members are delimited by a single ':', while member
2460 functions are delimited by a pair of ':'s. When we hit the member
2461 functions (if any), terminate scan loop and return. */
2463 while (*p
!= ':' && *p
!= '\0')
2470 /* Check to see if we have hit the member functions yet. */
2475 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2477 if (p
[0] == ':' && p
[1] == ':')
2479 /* chill the list of fields: the last entry (at the head) is a
2480 partially constructed entry which we now scrub. */
2481 fip
-> list
= fip
-> list
-> next
;
2486 /* The stabs for C++ derived classes contain baseclass information which
2487 is marked by a '!' character after the total size. This function is
2488 called when we encounter the baseclass marker, and slurps up all the
2489 baseclass information.
2491 Immediately following the '!' marker is the number of base classes that
2492 the class is derived from, followed by information for each base class.
2493 For each base class, there are two visibility specifiers, a bit offset
2494 to the base class information within the derived class, a reference to
2495 the type for the base class, and a terminating semicolon.
2497 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2499 Baseclass information marker __________________|| | | | | | |
2500 Number of baseclasses __________________________| | | | | | |
2501 Visibility specifiers (2) ________________________| | | | | |
2502 Offset in bits from start of class _________________| | | | |
2503 Type number for base class ___________________________| | | |
2504 Visibility specifiers (2) _______________________________| | |
2505 Offset in bits from start of class ________________________| |
2506 Type number of base class ____________________________________|
2508 Return 1 for success, 0 for (error-type-inducing) failure. */
2511 read_baseclasses (fip
, pp
, type
, objfile
)
2512 struct field_info
*fip
;
2515 struct objfile
*objfile
;
2518 struct nextfield
*new;
2526 /* Skip the '!' baseclass information marker. */
2530 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2533 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2539 /* Some stupid compilers have trouble with the following, so break
2540 it up into simpler expressions. */
2541 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2542 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2545 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2548 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2549 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2553 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2555 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2557 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2558 make_cleanup (free
, new);
2559 memset (new, 0, sizeof (struct nextfield
));
2560 new -> next
= fip
-> list
;
2562 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2564 STABS_CONTINUE (pp
);
2568 /* Nothing to do. */
2571 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2574 /* Unknown character. Complain and treat it as non-virtual. */
2576 static struct complaint msg
= {
2577 "Unknown virtual character `%c' for baseclass", 0, 0};
2578 complain (&msg
, **pp
);
2583 new -> visibility
= *(*pp
)++;
2584 switch (new -> visibility
)
2586 case VISIBILITY_PRIVATE
:
2587 case VISIBILITY_PROTECTED
:
2588 case VISIBILITY_PUBLIC
:
2591 /* Bad visibility format. Complain and treat it as
2594 static struct complaint msg
= {
2595 "Unknown visibility `%c' for baseclass", 0, 0};
2596 complain (&msg
, new -> visibility
);
2597 new -> visibility
= VISIBILITY_PUBLIC
;
2604 /* The remaining value is the bit offset of the portion of the object
2605 corresponding to this baseclass. Always zero in the absence of
2606 multiple inheritance. */
2608 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2613 /* The last piece of baseclass information is the type of the
2614 base class. Read it, and remember it's type name as this
2617 new -> field
.type
= read_type (pp
, objfile
);
2618 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2620 /* skip trailing ';' and bump count of number of fields seen */
2629 /* The tail end of stabs for C++ classes that contain a virtual function
2630 pointer contains a tilde, a %, and a type number.
2631 The type number refers to the base class (possibly this class itself) which
2632 contains the vtable pointer for the current class.
2634 This function is called when we have parsed all the method declarations,
2635 so we can look for the vptr base class info. */
2638 read_tilde_fields (fip
, pp
, type
, objfile
)
2639 struct field_info
*fip
;
2642 struct objfile
*objfile
;
2646 STABS_CONTINUE (pp
);
2648 /* If we are positioned at a ';', then skip it. */
2658 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2660 /* Obsolete flags that used to indicate the presence
2661 of constructors and/or destructors. */
2665 /* Read either a '%' or the final ';'. */
2666 if (*(*pp
)++ == '%')
2668 /* The next number is the type number of the base class
2669 (possibly our own class) which supplies the vtable for
2670 this class. Parse it out, and search that class to find
2671 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2672 and TYPE_VPTR_FIELDNO. */
2677 t
= read_type (pp
, objfile
);
2679 while (*p
!= '\0' && *p
!= ';')
2685 /* Premature end of symbol. */
2689 TYPE_VPTR_BASETYPE (type
) = t
;
2690 if (type
== t
) /* Our own class provides vtbl ptr */
2692 for (i
= TYPE_NFIELDS (t
) - 1;
2693 i
>= TYPE_N_BASECLASSES (t
);
2696 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2697 sizeof (vptr_name
) - 1))
2699 TYPE_VPTR_FIELDNO (type
) = i
;
2703 /* Virtual function table field not found. */
2704 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2709 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2720 attach_fn_fields_to_type (fip
, type
)
2721 struct field_info
*fip
;
2722 register struct type
*type
;
2726 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2728 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2730 /* @@ Memory leak on objfile -> type_obstack? */
2733 TYPE_NFN_FIELDS_TOTAL (type
) +=
2734 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2737 for (n
= TYPE_NFN_FIELDS (type
);
2738 fip
-> fnlist
!= NULL
;
2739 fip
-> fnlist
= fip
-> fnlist
-> next
)
2741 --n
; /* Circumvent Sun3 compiler bug */
2742 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2747 /* Create the vector of fields, and record how big it is.
2748 We need this info to record proper virtual function table information
2749 for this class's virtual functions. */
2752 attach_fields_to_type (fip
, type
, objfile
)
2753 struct field_info
*fip
;
2754 register struct type
*type
;
2755 struct objfile
*objfile
;
2757 register int nfields
= 0;
2758 register int non_public_fields
= 0;
2759 register struct nextfield
*scan
;
2761 /* Count up the number of fields that we have, as well as taking note of
2762 whether or not there are any non-public fields, which requires us to
2763 allocate and build the private_field_bits and protected_field_bits
2766 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2769 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2771 non_public_fields
++;
2775 /* Now we know how many fields there are, and whether or not there are any
2776 non-public fields. Record the field count, allocate space for the
2777 array of fields, and create blank visibility bitfields if necessary. */
2779 TYPE_NFIELDS (type
) = nfields
;
2780 TYPE_FIELDS (type
) = (struct field
*)
2781 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2782 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2784 if (non_public_fields
)
2786 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2788 TYPE_FIELD_PRIVATE_BITS (type
) =
2789 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2790 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2792 TYPE_FIELD_PROTECTED_BITS (type
) =
2793 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2794 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2796 TYPE_FIELD_IGNORE_BITS (type
) =
2797 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2798 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2801 /* Copy the saved-up fields into the field vector. Start from the head
2802 of the list, adding to the tail of the field array, so that they end
2803 up in the same order in the array in which they were added to the list. */
2805 while (nfields
-- > 0)
2807 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2808 switch (fip
-> list
-> visibility
)
2810 case VISIBILITY_PRIVATE
:
2811 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2814 case VISIBILITY_PROTECTED
:
2815 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2818 case VISIBILITY_IGNORE
:
2819 SET_TYPE_FIELD_IGNORE (type
, nfields
);
2822 case VISIBILITY_PUBLIC
:
2826 /* Unknown visibility. Complain and treat it as public. */
2828 static struct complaint msg
= {
2829 "Unknown visibility `%c' for field", 0, 0};
2830 complain (&msg
, fip
-> list
-> visibility
);
2834 fip
-> list
= fip
-> list
-> next
;
2839 /* Read the description of a structure (or union type) and return an object
2840 describing the type.
2842 PP points to a character pointer that points to the next unconsumed token
2843 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2844 *PP will point to "4a:1,0,32;;".
2846 TYPE points to an incomplete type that needs to be filled in.
2848 OBJFILE points to the current objfile from which the stabs information is
2849 being read. (Note that it is redundant in that TYPE also contains a pointer
2850 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2853 static struct type
*
2854 read_struct_type (pp
, type
, objfile
)
2857 struct objfile
*objfile
;
2859 struct cleanup
*back_to
;
2860 struct field_info fi
;
2865 back_to
= make_cleanup (null_cleanup
, 0);
2867 INIT_CPLUS_SPECIFIC (type
);
2868 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2870 /* First comes the total size in bytes. */
2874 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2876 return error_type (pp
);
2879 /* Now read the baseclasses, if any, read the regular C struct or C++
2880 class member fields, attach the fields to the type, read the C++
2881 member functions, attach them to the type, and then read any tilde
2882 field (baseclass specifier for the class holding the main vtable). */
2884 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2885 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2886 || !attach_fields_to_type (&fi
, type
, objfile
)
2887 || !read_member_functions (&fi
, pp
, type
, objfile
)
2888 || !attach_fn_fields_to_type (&fi
, type
)
2889 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2891 do_cleanups (back_to
);
2892 return (error_type (pp
));
2895 do_cleanups (back_to
);
2899 /* Read a definition of an array type,
2900 and create and return a suitable type object.
2901 Also creates a range type which represents the bounds of that
2904 static struct type
*
2905 read_array_type (pp
, type
, objfile
)
2907 register struct type
*type
;
2908 struct objfile
*objfile
;
2910 struct type
*index_type
, *element_type
, *range_type
;
2915 /* Format of an array type:
2916 "ar<index type>;lower;upper;<array_contents_type>".
2917 OS9000: "arlower,upper;<array_contents_type>".
2919 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2920 for these, produce a type like float[][]. */
2923 index_type
= builtin_type_int
;
2926 index_type
= read_type (pp
, objfile
);
2928 /* Improper format of array type decl. */
2929 return error_type (pp
);
2933 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2938 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
2940 return error_type (pp
);
2942 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2947 upper
= read_huge_number (pp
, ';', &nbits
);
2949 return error_type (pp
);
2951 element_type
= read_type (pp
, objfile
);
2960 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2961 type
= create_array_type (type
, element_type
, range_type
);
2963 /* If we have an array whose element type is not yet known, but whose
2964 bounds *are* known, record it to be adjusted at the end of the file. */
2965 /* FIXME: Why check for zero length rather than TYPE_FLAG_STUB? I think
2966 the two have the same effect except that the latter is cleaner and the
2967 former would be wrong for types which really are zero-length (if we
2970 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2972 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2973 add_undefined_type (type
);
2980 /* Read a definition of an enumeration type,
2981 and create and return a suitable type object.
2982 Also defines the symbols that represent the values of the type. */
2984 static struct type
*
2985 read_enum_type (pp
, type
, objfile
)
2987 register struct type
*type
;
2988 struct objfile
*objfile
;
2993 register struct symbol
*sym
;
2995 struct pending
**symlist
;
2996 struct pending
*osyms
, *syms
;
3001 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3002 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3003 to do? For now, force all enum values to file scope. */
3004 if (within_function
)
3005 symlist
= &local_symbols
;
3008 symlist
= &file_symbols
;
3010 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3014 /* Size. Perhaps this does not have to be conditionalized on
3015 os9k_stabs (assuming the name of an enum constant can't start
3017 read_huge_number (pp
, 0, &nbits
);
3019 return error_type (pp
);
3022 /* Read the value-names and their values.
3023 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3024 A semicolon or comma instead of a NAME means the end. */
3025 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3027 STABS_CONTINUE (pp
);
3029 while (*p
!= ':') p
++;
3030 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3032 n
= read_huge_number (pp
, ',', &nbits
);
3034 return error_type (pp
);
3036 sym
= (struct symbol
*)
3037 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3038 memset (sym
, 0, sizeof (struct symbol
));
3039 SYMBOL_NAME (sym
) = name
;
3040 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3041 SYMBOL_CLASS (sym
) = LOC_CONST
;
3042 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3043 SYMBOL_VALUE (sym
) = n
;
3044 add_symbol_to_list (sym
, symlist
);
3049 (*pp
)++; /* Skip the semicolon. */
3051 /* Now fill in the fields of the type-structure. */
3053 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3054 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3055 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3056 TYPE_NFIELDS (type
) = nsyms
;
3057 TYPE_FIELDS (type
) = (struct field
*)
3058 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3059 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3061 /* Find the symbols for the values and put them into the type.
3062 The symbols can be found in the symlist that we put them on
3063 to cause them to be defined. osyms contains the old value
3064 of that symlist; everything up to there was defined by us. */
3065 /* Note that we preserve the order of the enum constants, so
3066 that in something like "enum {FOO, LAST_THING=FOO}" we print
3067 FOO, not LAST_THING. */
3069 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
3074 for (; j
< syms
->nsyms
; j
++,n
++)
3076 struct symbol
*xsym
= syms
->symbol
[j
];
3077 SYMBOL_TYPE (xsym
) = type
;
3078 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3079 TYPE_FIELD_VALUE (type
, n
) = 0;
3080 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3081 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3090 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3091 typedefs in every file (for int, long, etc):
3093 type = b <signed> <width>; <offset>; <nbits>
3094 signed = u or s. Possible c in addition to u or s (for char?).
3095 offset = offset from high order bit to start bit of type.
3096 width is # bytes in object of this type, nbits is # bits in type.
3098 The width/offset stuff appears to be for small objects stored in
3099 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3102 static struct type
*
3103 read_sun_builtin_type (pp
, typenums
, objfile
)
3106 struct objfile
*objfile
;
3121 return error_type (pp
);
3125 /* For some odd reason, all forms of char put a c here. This is strange
3126 because no other type has this honor. We can safely ignore this because
3127 we actually determine 'char'acterness by the number of bits specified in
3133 /* The first number appears to be the number of bytes occupied
3134 by this type, except that unsigned short is 4 instead of 2.
3135 Since this information is redundant with the third number,
3136 we will ignore it. */
3137 read_huge_number (pp
, ';', &nbits
);
3139 return error_type (pp
);
3141 /* The second number is always 0, so ignore it too. */
3142 read_huge_number (pp
, ';', &nbits
);
3144 return error_type (pp
);
3146 /* The third number is the number of bits for this type. */
3147 type_bits
= read_huge_number (pp
, 0, &nbits
);
3149 return error_type (pp
);
3150 /* The type *should* end with a semicolon. If it are embedded
3151 in a larger type the semicolon may be the only way to know where
3152 the type ends. If this type is at the end of the stabstring we
3153 can deal with the omitted semicolon (but we don't have to like
3154 it). Don't bother to complain(), Sun's compiler omits the semicolon
3160 return init_type (TYPE_CODE_VOID
, 1,
3161 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3164 return init_type (TYPE_CODE_INT
,
3165 type_bits
/ TARGET_CHAR_BIT
,
3166 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3170 static struct type
*
3171 read_sun_floating_type (pp
, typenums
, objfile
)
3174 struct objfile
*objfile
;
3180 /* The first number has more details about the type, for example
3182 details
= read_huge_number (pp
, ';', &nbits
);
3184 return error_type (pp
);
3186 /* The second number is the number of bytes occupied by this type */
3187 nbytes
= read_huge_number (pp
, ';', &nbits
);
3189 return error_type (pp
);
3191 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3192 || details
== NF_COMPLEX32
)
3193 /* This is a type we can't handle, but we do know the size.
3194 We also will be able to give it a name. */
3195 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3197 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3200 /* Read a number from the string pointed to by *PP.
3201 The value of *PP is advanced over the number.
3202 If END is nonzero, the character that ends the
3203 number must match END, or an error happens;
3204 and that character is skipped if it does match.
3205 If END is zero, *PP is left pointing to that character.
3207 If the number fits in a long, set *BITS to 0 and return the value.
3208 If not, set *BITS to be the number of bits in the number and return 0.
3210 If encounter garbage, set *BITS to -1 and return 0. */
3213 read_huge_number (pp
, end
, bits
)
3233 /* Leading zero means octal. GCC uses this to output values larger
3234 than an int (because that would be hard in decimal). */
3241 upper_limit
= LONG_MAX
/ radix
;
3242 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3244 if (n
<= upper_limit
)
3247 n
+= c
- '0'; /* FIXME this overflows anyway */
3252 /* This depends on large values being output in octal, which is
3259 /* Ignore leading zeroes. */
3263 else if (c
== '2' || c
== '3')
3289 /* Large decimal constants are an error (because it is hard to
3290 count how many bits are in them). */
3296 /* -0x7f is the same as 0x80. So deal with it by adding one to
3297 the number of bits. */
3309 /* It's *BITS which has the interesting information. */
3313 static struct type
*
3314 read_range_type (pp
, typenums
, objfile
)
3317 struct objfile
*objfile
;
3323 struct type
*result_type
;
3324 struct type
*index_type
;
3326 /* First comes a type we are a subrange of.
3327 In C it is usually 0, 1 or the type being defined. */
3328 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3329 not just a type number. */
3330 if (read_type_number (pp
, rangenums
) != 0)
3331 return error_type (pp
);
3332 self_subrange
= (rangenums
[0] == typenums
[0] &&
3333 rangenums
[1] == typenums
[1]);
3335 /* A semicolon should now follow; skip it. */
3339 /* The remaining two operands are usually lower and upper bounds
3340 of the range. But in some special cases they mean something else. */
3341 n2
= read_huge_number (pp
, ';', &n2bits
);
3342 n3
= read_huge_number (pp
, ';', &n3bits
);
3344 if (n2bits
== -1 || n3bits
== -1)
3345 return error_type (pp
);
3347 /* If limits are huge, must be large integral type. */
3348 if (n2bits
!= 0 || n3bits
!= 0)
3350 char got_signed
= 0;
3351 char got_unsigned
= 0;
3352 /* Number of bits in the type. */
3355 /* Range from 0 to <large number> is an unsigned large integral type. */
3356 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3361 /* Range from <large number> to <large number>-1 is a large signed
3362 integral type. Take care of the case where <large number> doesn't
3363 fit in a long but <large number>-1 does. */
3364 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3365 || (n2bits
!= 0 && n3bits
== 0
3366 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3373 if (got_signed
|| got_unsigned
)
3375 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3376 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3380 return error_type (pp
);
3383 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3384 if (self_subrange
&& n2
== 0 && n3
== 0)
3385 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
3387 /* If n3 is zero and n2 is not, we want a floating type,
3388 and n2 is the width in bytes.
3390 Fortran programs appear to use this for complex types also,
3391 and they give no way to distinguish between double and single-complex!
3393 GDB does not have complex types.
3395 Just return the complex as a float of that size. It won't work right
3396 for the complex values, but at least it makes the file loadable. */
3398 if (n3
== 0 && n2
> 0)
3400 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3403 /* If the upper bound is -1, it must really be an unsigned int. */
3405 else if (n2
== 0 && n3
== -1)
3407 /* It is unsigned int or unsigned long. */
3408 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3409 compatibility hack. */
3410 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3411 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3414 /* Special case: char is defined (Who knows why) as a subrange of
3415 itself with range 0-127. */
3416 else if (self_subrange
&& n2
== 0 && n3
== 127)
3417 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3419 /* We used to do this only for subrange of self or subrange of int. */
3423 /* n3 actually gives the size. */
3424 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3427 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3429 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3431 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3432 "unsigned long", and we already checked for that,
3433 so don't need to test for it here. */
3435 /* I think this is for Convex "long long". Since I don't know whether
3436 Convex sets self_subrange, I also accept that particular size regardless
3437 of self_subrange. */
3438 else if (n3
== 0 && n2
< 0
3440 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3441 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3442 else if (n2
== -n3
-1)
3445 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3447 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3448 if (n3
== 0x7fffffff)
3449 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3452 /* We have a real range type on our hands. Allocate space and
3453 return a real pointer. */
3455 /* At this point I don't have the faintest idea how to deal with
3456 a self_subrange type; I'm going to assume that this is used
3457 as an idiom, and that all of them are special cases. So . . . */
3459 return error_type (pp
);
3461 index_type
= *dbx_lookup_type (rangenums
);
3462 if (index_type
== NULL
)
3464 /* Does this actually ever happen? Is that why we are worrying
3465 about dealing with it rather than just calling error_type? */
3467 static struct type
*range_type_index
;
3469 complain (&range_type_base_complaint
, rangenums
[1]);
3470 if (range_type_index
== NULL
)
3472 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3473 0, "range type index type", NULL
);
3474 index_type
= range_type_index
;
3477 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3478 return (result_type
);
3481 /* Read in an argument list. This is a list of types, separated by commas
3482 and terminated with END. Return the list of types read in, or (struct type
3483 **)-1 if there is an error. */
3485 static struct type
**
3486 read_args (pp
, end
, objfile
)
3489 struct objfile
*objfile
;
3491 /* FIXME! Remove this arbitrary limit! */
3492 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3498 /* Invalid argument list: no ','. */
3499 return (struct type
**)-1;
3501 STABS_CONTINUE (pp
);
3502 types
[n
++] = read_type (pp
, objfile
);
3504 (*pp
)++; /* get past `end' (the ':' character) */
3508 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3510 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3512 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3513 memset (rval
+ n
, 0, sizeof (struct type
*));
3517 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3519 memcpy (rval
, types
, n
* sizeof (struct type
*));
3523 /* Common block handling. */
3525 /* List of symbols declared since the last BCOMM. This list is a tail
3526 of local_symbols. When ECOMM is seen, the symbols on the list
3527 are noted so their proper addresses can be filled in later,
3528 using the common block base address gotten from the assembler
3531 static struct pending
*common_block
;
3532 static int common_block_i
;
3534 /* Name of the current common block. We get it from the BCOMM instead of the
3535 ECOMM to match IBM documentation (even though IBM puts the name both places
3536 like everyone else). */
3537 static char *common_block_name
;
3539 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3540 to remain after this function returns. */
3543 common_block_start (name
, objfile
)
3545 struct objfile
*objfile
;
3547 if (common_block_name
!= NULL
)
3549 static struct complaint msg
= {
3550 "Invalid symbol data: common block within common block",
3554 common_block
= local_symbols
;
3555 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3556 common_block_name
= obsavestring (name
, strlen (name
),
3557 &objfile
-> symbol_obstack
);
3560 /* Process a N_ECOMM symbol. */
3563 common_block_end (objfile
)
3564 struct objfile
*objfile
;
3566 /* Symbols declared since the BCOMM are to have the common block
3567 start address added in when we know it. common_block and
3568 common_block_i point to the first symbol after the BCOMM in
3569 the local_symbols list; copy the list and hang it off the
3570 symbol for the common block name for later fixup. */
3573 struct pending
*new = 0;
3574 struct pending
*next
;
3577 if (common_block_name
== NULL
)
3579 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
3584 sym
= (struct symbol
*)
3585 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3586 memset (sym
, 0, sizeof (struct symbol
));
3587 SYMBOL_NAME (sym
) = common_block_name
;
3588 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3590 /* Now we copy all the symbols which have been defined since the BCOMM. */
3592 /* Copy all the struct pendings before common_block. */
3593 for (next
= local_symbols
;
3594 next
!= NULL
&& next
!= common_block
;
3597 for (j
= 0; j
< next
->nsyms
; j
++)
3598 add_symbol_to_list (next
->symbol
[j
], &new);
3601 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3602 NULL, it means copy all the local symbols (which we already did
3605 if (common_block
!= NULL
)
3606 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
3607 add_symbol_to_list (common_block
->symbol
[j
], &new);
3609 SYMBOL_TYPE (sym
) = (struct type
*) new;
3611 /* Should we be putting local_symbols back to what it was?
3614 i
= hashname (SYMBOL_NAME (sym
));
3615 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3616 global_sym_chain
[i
] = sym
;
3617 common_block_name
= NULL
;
3620 /* Add a common block's start address to the offset of each symbol
3621 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3622 the common block name). */
3625 fix_common_block (sym
, valu
)
3629 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
3630 for ( ; next
; next
= next
->next
)
3633 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3634 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3640 /* What about types defined as forward references inside of a small lexical
3642 /* Add a type to the list of undefined types to be checked through
3643 once this file has been read in. */
3646 add_undefined_type (type
)
3649 if (undef_types_length
== undef_types_allocated
)
3651 undef_types_allocated
*= 2;
3652 undef_types
= (struct type
**)
3653 xrealloc ((char *) undef_types
,
3654 undef_types_allocated
* sizeof (struct type
*));
3656 undef_types
[undef_types_length
++] = type
;
3659 /* Go through each undefined type, see if it's still undefined, and fix it
3660 up if possible. We have two kinds of undefined types:
3662 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3663 Fix: update array length using the element bounds
3664 and the target type's length.
3665 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3666 yet defined at the time a pointer to it was made.
3667 Fix: Do a full lookup on the struct/union tag. */
3669 cleanup_undefined_types ()
3673 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3675 switch (TYPE_CODE (*type
))
3678 case TYPE_CODE_STRUCT
:
3679 case TYPE_CODE_UNION
:
3680 case TYPE_CODE_ENUM
:
3682 /* Check if it has been defined since. Need to do this here
3683 as well as in check_stub_type to deal with the (legitimate in
3684 C though not C++) case of several types with the same name
3685 in different source files. */
3686 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3688 struct pending
*ppt
;
3690 /* Name of the type, without "struct" or "union" */
3691 char *typename
= TYPE_TAG_NAME (*type
);
3693 if (typename
== NULL
)
3695 static struct complaint msg
= {"need a type name", 0, 0};
3699 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3701 for (i
= 0; i
< ppt
->nsyms
; i
++)
3703 struct symbol
*sym
= ppt
->symbol
[i
];
3705 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3706 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3707 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3709 && STREQ (SYMBOL_NAME (sym
), typename
))
3711 memcpy (*type
, SYMBOL_TYPE (sym
),
3712 sizeof (struct type
));
3720 case TYPE_CODE_ARRAY
:
3722 /* This is a kludge which is here for historical reasons
3723 because I suspect that check_stub_type does not get
3724 called everywhere it needs to be called for arrays. Even
3725 with this kludge, those places are broken for the case
3726 where the stub type is defined in another compilation
3727 unit, but this kludge at least deals with it for the case
3728 in which it is the same compilation unit.
3730 Don't try to do this by calling check_stub_type; it might
3731 cause symbols to be read in lookup_symbol, and the symbol
3732 reader is not reentrant. */
3734 struct type
*range_type
;
3737 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3739 if (TYPE_NFIELDS (*type
) != 1)
3741 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3742 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3745 /* Now recompute the length of the array type, based on its
3746 number of elements and the target type's length. */
3747 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3748 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3749 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3750 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3752 /* If the target type is not a stub, we could be clearing
3753 TYPE_FLAG_TARGET_STUB for *type. */
3760 static struct complaint msg
= {"\
3761 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3762 complain (&msg
, TYPE_CODE (*type
));
3768 undef_types_length
= 0;
3771 /* Scan through all of the global symbols defined in the object file,
3772 assigning values to the debugging symbols that need to be assigned
3773 to. Get these symbols from the minimal symbol table. */
3776 scan_file_globals (objfile
)
3777 struct objfile
*objfile
;
3780 struct minimal_symbol
*msymbol
;
3781 struct symbol
*sym
, *prev
;
3783 if (objfile
->msymbols
== 0) /* Beware the null file. */
3786 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3792 /* Get the hash index and check all the symbols
3793 under that hash index. */
3795 hash
= hashname (SYMBOL_NAME (msymbol
));
3797 for (sym
= global_sym_chain
[hash
]; sym
;)
3799 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3800 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3802 /* Splice this symbol out of the hash chain and
3803 assign the value we have to it. */
3806 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3810 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3813 /* Check to see whether we need to fix up a common block. */
3814 /* Note: this code might be executed several times for
3815 the same symbol if there are multiple references. */
3817 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3819 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3823 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3828 sym
= SYMBOL_VALUE_CHAIN (prev
);
3832 sym
= global_sym_chain
[hash
];
3838 sym
= SYMBOL_VALUE_CHAIN (sym
);
3844 /* Initialize anything that needs initializing when starting to read
3845 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3853 /* Initialize anything that needs initializing when a completely new
3854 symbol file is specified (not just adding some symbols from another
3855 file, e.g. a shared library). */
3858 stabsread_new_init ()
3860 /* Empty the hash table of global syms looking for values. */
3861 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3864 /* Initialize anything that needs initializing at the same time as
3865 start_symtab() is called. */
3869 global_stabs
= NULL
; /* AIX COFF */
3870 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3871 n_this_object_header_files
= 1;
3872 type_vector_length
= 0;
3873 type_vector
= (struct type
**) 0;
3875 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3876 common_block_name
= NULL
;
3881 /* Call after end_symtab() */
3887 free ((char *) type_vector
);
3890 type_vector_length
= 0;
3891 previous_stab_code
= 0;
3895 finish_global_stabs (objfile
)
3896 struct objfile
*objfile
;
3900 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3901 free ((PTR
) global_stabs
);
3902 global_stabs
= NULL
;
3906 /* Initializer for this module */
3909 _initialize_stabsread ()
3911 undef_types_allocated
= 20;
3912 undef_types_length
= 0;
3913 undef_types
= (struct type
**)
3914 xmalloc (undef_types_allocated
* sizeof (struct type
*));