1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
36 #include "complaints.h"
41 /* Ask stabsread.h to define the vars it normally declares `extern'. */
43 #include "stabsread.h" /* Our own declarations */
46 /* The routines that read and process a complete stabs for a C struct or
47 C++ class pass lists of data member fields and lists of member function
48 fields in an instance of a field_info structure, as defined below.
49 This is part of some reorganization of low level C++ support and is
50 expected to eventually go away... (FIXME) */
56 struct nextfield
*next
;
58 /* This is the raw visibility from the stab. It is not checked
59 for being one of the visibilities we recognize, so code which
60 examines this field better be able to deal. */
65 struct next_fnfieldlist
67 struct next_fnfieldlist
*next
;
68 struct fn_fieldlist fn_fieldlist
;
73 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
75 static long read_huge_number
PARAMS ((char **, int, int *));
77 static struct type
*error_type
PARAMS ((char **));
80 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
84 fix_common_block
PARAMS ((struct symbol
*, int));
87 read_type_number
PARAMS ((char **, int *));
90 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
93 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
96 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
99 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
102 rs6000_builtin_type
PARAMS ((int));
105 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
109 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
113 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
117 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
121 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
124 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
128 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
131 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
133 static struct type
**
134 read_args
PARAMS ((char **, int, struct objfile
*));
137 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
140 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
141 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
143 /* Define this as 1 if a pcc declaration of a char or short argument
144 gives the correct address. Otherwise assume pcc gives the
145 address of the corresponding int, which is not the same on a
146 big-endian machine. */
148 #ifndef BELIEVE_PCC_PROMOTION
149 #define BELIEVE_PCC_PROMOTION 0
153 struct complaint dbx_class_complaint
=
155 "encountered DBX-style class variable debugging information.\n\
156 You seem to have compiled your program with \
157 \"g++ -g0\" instead of \"g++ -g\".\n\
158 Therefore GDB will not know about your class variables", 0, 0
162 struct complaint invalid_cpp_abbrev_complaint
=
163 {"invalid C++ abbreviation `%s'", 0, 0};
165 struct complaint invalid_cpp_type_complaint
=
166 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
168 struct complaint member_fn_complaint
=
169 {"member function type missing, got '%c'", 0, 0};
171 struct complaint const_vol_complaint
=
172 {"const/volatile indicator missing, got '%c'", 0, 0};
174 struct complaint error_type_complaint
=
175 {"debug info mismatch between compiler and debugger", 0, 0};
177 struct complaint invalid_member_complaint
=
178 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
180 struct complaint range_type_base_complaint
=
181 {"base type %d of range type is not defined", 0, 0};
183 struct complaint reg_value_complaint
=
184 {"register number too large in symbol %s", 0, 0};
186 struct complaint vtbl_notfound_complaint
=
187 {"virtual function table pointer not found when defining class `%s'", 0, 0};
189 struct complaint unrecognized_cplus_name_complaint
=
190 {"Unknown C++ symbol name `%s'", 0, 0};
192 struct complaint rs6000_builtin_complaint
=
193 {"Unknown builtin type %d", 0, 0};
195 struct complaint stabs_general_complaint
=
198 /* Make a list of forward references which haven't been defined. */
200 static struct type
**undef_types
;
201 static int undef_types_allocated
;
202 static int undef_types_length
;
204 /* Check for and handle cretinous stabs symbol name continuation! */
205 #define STABS_CONTINUE(pp) \
207 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
211 /* Look up a dbx type-number pair. Return the address of the slot
212 where the type for that number-pair is stored.
213 The number-pair is in TYPENUMS.
215 This can be used for finding the type associated with that pair
216 or for associating a new type with the pair. */
219 dbx_lookup_type (typenums
)
222 register int filenum
= typenums
[0];
223 register int index
= typenums
[1];
225 register int real_filenum
;
226 register struct header_file
*f
;
229 if (filenum
== -1) /* -1,-1 is for temporary types. */
232 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
234 static struct complaint msg
= {"\
235 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
237 complain (&msg
, filenum
, index
, symnum
);
245 /* Caller wants address of address of type. We think
246 that negative (rs6k builtin) types will never appear as
247 "lvalues", (nor should they), so we stuff the real type
248 pointer into a temp, and return its address. If referenced,
249 this will do the right thing. */
250 static struct type
*temp_type
;
252 temp_type
= rs6000_builtin_type(index
);
256 /* Type is defined outside of header files.
257 Find it in this object file's type vector. */
258 if (index
>= type_vector_length
)
260 old_len
= type_vector_length
;
263 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
264 type_vector
= (struct type
**)
265 malloc (type_vector_length
* sizeof (struct type
*));
267 while (index
>= type_vector_length
)
269 type_vector_length
*= 2;
271 type_vector
= (struct type
**)
272 xrealloc ((char *) type_vector
,
273 (type_vector_length
* sizeof (struct type
*)));
274 memset (&type_vector
[old_len
], 0,
275 (type_vector_length
- old_len
) * sizeof (struct type
*));
277 return (&type_vector
[index
]);
281 real_filenum
= this_object_header_files
[filenum
];
283 if (real_filenum
>= n_header_files
)
285 struct type
*temp_type
;
286 struct type
**temp_type_p
;
288 warning ("GDB internal error: bad real_filenum");
291 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
292 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
293 *temp_type_p
= temp_type
;
297 f
= &header_files
[real_filenum
];
299 f_orig_length
= f
->length
;
300 if (index
>= f_orig_length
)
302 while (index
>= f
->length
)
306 f
->vector
= (struct type
**)
307 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
308 memset (&f
->vector
[f_orig_length
], 0,
309 (f
->length
- f_orig_length
) * sizeof (struct type
*));
311 return (&f
->vector
[index
]);
315 /* Make sure there is a type allocated for type numbers TYPENUMS
316 and return the type object.
317 This can create an empty (zeroed) type object.
318 TYPENUMS may be (-1, -1) to return a new type object that is not
319 put into the type vector, and so may not be referred to by number. */
322 dbx_alloc_type (typenums
, objfile
)
324 struct objfile
*objfile
;
326 register struct type
**type_addr
;
328 if (typenums
[0] == -1)
330 return (alloc_type (objfile
));
333 type_addr
= dbx_lookup_type (typenums
);
335 /* If we are referring to a type not known at all yet,
336 allocate an empty type for it.
337 We will fill it in later if we find out how. */
340 *type_addr
= alloc_type (objfile
);
346 /* for all the stabs in a given stab vector, build appropriate types
347 and fix their symbols in given symbol vector. */
350 patch_block_stabs (symbols
, stabs
, objfile
)
351 struct pending
*symbols
;
352 struct pending_stabs
*stabs
;
353 struct objfile
*objfile
;
363 /* for all the stab entries, find their corresponding symbols and
364 patch their types! */
366 for (ii
= 0; ii
< stabs
->count
; ++ii
)
368 name
= stabs
->stab
[ii
];
369 pp
= (char*) strchr (name
, ':');
373 pp
= (char *)strchr(pp
, ':');
375 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
378 /* On xcoff, if a global is defined and never referenced,
379 ld will remove it from the executable. There is then
380 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
381 sym
= (struct symbol
*)
382 obstack_alloc (&objfile
->symbol_obstack
,
383 sizeof (struct symbol
));
385 memset (sym
, 0, sizeof (struct symbol
));
386 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
387 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
389 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
391 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
393 /* I don't think the linker does this with functions,
394 so as far as I know this is never executed.
395 But it doesn't hurt to check. */
397 lookup_function_type (read_type (&pp
, objfile
));
401 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
403 add_symbol_to_list (sym
, &global_symbols
);
408 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
411 lookup_function_type (read_type (&pp
, objfile
));
415 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
423 /* Read a number by which a type is referred to in dbx data,
424 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
425 Just a single number N is equivalent to (0,N).
426 Return the two numbers by storing them in the vector TYPENUMS.
427 TYPENUMS will then be used as an argument to dbx_lookup_type.
429 Returns 0 for success, -1 for error. */
432 read_type_number (pp
, typenums
)
434 register int *typenums
;
440 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
441 if (nbits
!= 0) return -1;
442 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
443 if (nbits
!= 0) return -1;
448 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
449 if (nbits
!= 0) return -1;
455 /* To handle GNU C++ typename abbreviation, we need to be able to
456 fill in a type's name as soon as space for that type is allocated.
457 `type_synonym_name' is the name of the type being allocated.
458 It is cleared as soon as it is used (lest all allocated types
461 static char *type_synonym_name
;
465 define_symbol (valu
, string
, desc
, type
, objfile
)
470 struct objfile
*objfile
;
472 register struct symbol
*sym
;
473 char *p
= (char *) strchr (string
, ':');
478 /* We would like to eliminate nameless symbols, but keep their types.
479 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
480 to type 2, but, should not create a symbol to address that type. Since
481 the symbol will be nameless, there is no way any user can refer to it. */
485 /* Ignore syms with empty names. */
489 /* Ignore old-style symbols from cc -go */
499 /* If a nameless stab entry, all we need is the type, not the symbol.
500 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
501 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
503 sym
= (struct symbol
*)
504 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
505 memset (sym
, 0, sizeof (struct symbol
));
507 if (processing_gcc_compilation
)
509 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
510 number of bytes occupied by a type or object, which we ignore. */
511 SYMBOL_LINE(sym
) = desc
;
515 SYMBOL_LINE(sym
) = 0; /* unknown */
518 if (string
[0] == CPLUS_MARKER
)
520 /* Special GNU C++ names. */
524 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
525 &objfile
-> symbol_obstack
);
528 case 'v': /* $vtbl_ptr_type */
529 /* Was: SYMBOL_NAME (sym) = "vptr"; */
533 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
534 &objfile
-> symbol_obstack
);
538 /* This was an anonymous type that was never fixed up. */
542 complain (&unrecognized_cplus_name_complaint
, string
);
543 goto normal
; /* Do *something* with it */
549 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
550 SYMBOL_NAME (sym
) = (char *)
551 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
552 /* Open-coded memcpy--saves function call time. */
553 /* FIXME: Does it really? Try replacing with simple strcpy and
554 try it on an executable with a large symbol table. */
555 /* FIXME: considering that gcc can open code memcpy anyway, I
556 doubt it. xoxorich. */
558 register char *p1
= string
;
559 register char *p2
= SYMBOL_NAME (sym
);
567 /* If this symbol is from a C++ compilation, then attempt to cache the
568 demangled form for future reference. This is a typical time versus
569 space tradeoff, that was decided in favor of time because it sped up
570 C++ symbol lookups by a factor of about 20. */
572 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
576 /* Determine the type of name being defined. */
578 /* Getting GDB to correctly skip the symbol on an undefined symbol
579 descriptor and not ever dump core is a very dodgy proposition if
580 we do things this way. I say the acorn RISC machine can just
581 fix their compiler. */
582 /* The Acorn RISC machine's compiler can put out locals that don't
583 start with "234=" or "(3,4)=", so assume anything other than the
584 deftypes we know how to handle is a local. */
585 if (!strchr ("cfFGpPrStTvVXCR", *p
))
587 if (isdigit (*p
) || *p
== '(' || *p
== '-')
596 /* c is a special case, not followed by a type-number.
597 SYMBOL:c=iVALUE for an integer constant symbol.
598 SYMBOL:c=rVALUE for a floating constant symbol.
599 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
600 e.g. "b:c=e6,0" for "const b = blob1"
601 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
604 SYMBOL_CLASS (sym
) = LOC_CONST
;
605 SYMBOL_TYPE (sym
) = error_type (&p
);
606 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
607 add_symbol_to_list (sym
, &file_symbols
);
618 /* FIXME-if-picky-about-floating-accuracy: Should be using
619 target arithmetic to get the value. real.c in GCC
620 probably has the necessary code. */
622 /* FIXME: lookup_fundamental_type is a hack. We should be
623 creating a type especially for the type of float constants.
624 Problem is, what type should it be?
626 Also, what should the name of this type be? Should we
627 be using 'S' constants (see stabs.texinfo) instead? */
629 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
632 obstack_alloc (&objfile
-> symbol_obstack
,
633 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
634 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
635 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
636 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
641 /* Defining integer constants this way is kind of silly,
642 since 'e' constants allows the compiler to give not
643 only the value, but the type as well. C has at least
644 int, long, unsigned int, and long long as constant
645 types; other languages probably should have at least
646 unsigned as well as signed constants. */
648 /* We just need one int constant type for all objfiles.
649 It doesn't depend on languages or anything (arguably its
650 name should be a language-specific name for a type of
651 that size, but I'm inclined to say that if the compiler
652 wants a nice name for the type, it can use 'e'). */
653 static struct type
*int_const_type
;
655 /* Yes, this is as long as a *host* int. That is because we
657 if (int_const_type
== NULL
)
659 init_type (TYPE_CODE_INT
,
660 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
662 (struct objfile
*)NULL
);
663 SYMBOL_TYPE (sym
) = int_const_type
;
664 SYMBOL_VALUE (sym
) = atoi (p
);
665 SYMBOL_CLASS (sym
) = LOC_CONST
;
669 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
670 can be represented as integral.
671 e.g. "b:c=e6,0" for "const b = blob1"
672 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
674 SYMBOL_CLASS (sym
) = LOC_CONST
;
675 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
679 SYMBOL_TYPE (sym
) = error_type (&p
);
684 /* If the value is too big to fit in an int (perhaps because
685 it is unsigned), or something like that, we silently get
686 a bogus value. The type and everything else about it is
687 correct. Ideally, we should be using whatever we have
688 available for parsing unsigned and long long values,
690 SYMBOL_VALUE (sym
) = atoi (p
);
695 SYMBOL_CLASS (sym
) = LOC_CONST
;
696 SYMBOL_TYPE (sym
) = error_type (&p
);
699 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
700 add_symbol_to_list (sym
, &file_symbols
);
704 /* The name of a caught exception. */
705 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
706 SYMBOL_CLASS (sym
) = LOC_LABEL
;
707 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
708 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
709 add_symbol_to_list (sym
, &local_symbols
);
713 /* A static function definition. */
714 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
715 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
716 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
717 add_symbol_to_list (sym
, &file_symbols
);
718 /* fall into process_function_types. */
720 process_function_types
:
721 /* Function result types are described as the result type in stabs.
722 We need to convert this to the function-returning-type-X type
723 in GDB. E.g. "int" is converted to "function returning int". */
724 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
727 /* This code doesn't work -- it needs to realloc and can't. */
728 /* Attempt to set up to record a function prototype... */
729 struct type
*new = alloc_type (objfile
);
731 /* Generate a template for the type of this function. The
732 types of the arguments will be added as we read the symbol
734 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
735 SYMBOL_TYPE(sym
) = new;
736 TYPE_OBJFILE (new) = objfile
;
737 in_function_type
= new;
739 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
742 /* fall into process_prototype_types */
744 process_prototype_types
:
745 /* Sun acc puts declared types of arguments here. We don't care
746 about their actual types (FIXME -- we should remember the whole
747 function prototype), but the list may define some new types
748 that we have to remember, so we must scan it now. */
751 read_type (&p
, objfile
);
756 /* A global function definition. */
757 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
758 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
759 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
760 add_symbol_to_list (sym
, &global_symbols
);
761 goto process_function_types
;
764 /* For a class G (global) symbol, it appears that the
765 value is not correct. It is necessary to search for the
766 corresponding linker definition to find the value.
767 These definitions appear at the end of the namelist. */
768 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
769 i
= hashname (SYMBOL_NAME (sym
));
770 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
771 global_sym_chain
[i
] = sym
;
772 SYMBOL_CLASS (sym
) = LOC_STATIC
;
773 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
774 add_symbol_to_list (sym
, &global_symbols
);
777 /* This case is faked by a conditional above,
778 when there is no code letter in the dbx data.
779 Dbx data never actually contains 'l'. */
781 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
782 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
783 SYMBOL_VALUE (sym
) = valu
;
784 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
785 add_symbol_to_list (sym
, &local_symbols
);
790 /* pF is a two-letter code that means a function parameter in Fortran.
791 The type-number specifies the type of the return value.
792 Translate it into a pointer-to-function type. */
796 = lookup_pointer_type
797 (lookup_function_type (read_type (&p
, objfile
)));
800 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
802 /* Normally this is a parameter, a LOC_ARG. On the i960, it
803 can also be a LOC_LOCAL_ARG depending on symbol type. */
804 #ifndef DBX_PARM_SYMBOL_CLASS
805 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
808 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
809 SYMBOL_VALUE (sym
) = valu
;
810 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
812 /* This doesn't work yet. */
813 add_param_to_type (&in_function_type
, sym
);
815 add_symbol_to_list (sym
, &local_symbols
);
817 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
818 /* On little-endian machines, this crud is never necessary, and,
819 if the extra bytes contain garbage, is harmful. */
821 #else /* Big endian. */
822 /* If it's gcc-compiled, if it says `short', believe it. */
823 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
826 #if !BELIEVE_PCC_PROMOTION
828 /* This is the signed type which arguments get promoted to. */
829 static struct type
*pcc_promotion_type
;
830 /* This is the unsigned type which arguments get promoted to. */
831 static struct type
*pcc_unsigned_promotion_type
;
833 /* Call it "int" because this is mainly C lossage. */
834 if (pcc_promotion_type
== NULL
)
836 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
839 if (pcc_unsigned_promotion_type
== NULL
)
840 pcc_unsigned_promotion_type
=
841 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
842 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
844 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
845 /* This macro is defined on machines (e.g. sparc) where
846 we should believe the type of a PCC 'short' argument,
847 but shouldn't believe the address (the address is
848 the address of the corresponding int).
850 My guess is that this correction, as opposed to changing
851 the parameter to an 'int' (as done below, for PCC
852 on most machines), is the right thing to do
853 on all machines, but I don't want to risk breaking
854 something that already works. On most PCC machines,
855 the sparc problem doesn't come up because the calling
856 function has to zero the top bytes (not knowing whether
857 the called function wants an int or a short), so there
858 is little practical difference between an int and a short
859 (except perhaps what happens when the GDB user types
860 "print short_arg = 0x10000;").
862 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
863 actually produces the correct address (we don't need to fix it
864 up). I made this code adapt so that it will offset the symbol
865 if it was pointing at an int-aligned location and not
866 otherwise. This way you can use the same gdb for 4.0.x and
869 If the parameter is shorter than an int, and is integral
870 (e.g. char, short, or unsigned equivalent), and is claimed to
871 be passed on an integer boundary, don't believe it! Offset the
872 parameter's address to the tail-end of that integer. */
874 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
875 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
876 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
878 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
879 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
883 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
885 /* If PCC says a parameter is a short or a char,
886 it is really an int. */
887 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
888 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
891 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
892 ? pcc_unsigned_promotion_type
893 : pcc_promotion_type
;
897 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
899 #endif /* !BELIEVE_PCC_PROMOTION. */
900 #endif /* Big endian. */
903 /* acc seems to use P to delare the prototypes of functions that
904 are referenced by this file. gdb is not prepared to deal
905 with this extra information. FIXME, it ought to. */
908 read_type (&p
, objfile
);
909 goto process_prototype_types
;
914 /* Parameter which is in a register. */
915 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
916 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
917 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
918 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
920 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
921 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
923 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
924 add_symbol_to_list (sym
, &local_symbols
);
928 /* Register variable (either global or local). */
929 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
930 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
931 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
932 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
934 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
935 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
937 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
940 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
941 name to represent an argument passed in a register.
942 GCC uses 'P' for the same case. So if we find such a symbol pair
943 we combine it into one 'P' symbol.
944 Note that this code illegally combines
945 main(argc) int argc; { register int argc = 1; }
946 but this case is considered pathological and causes a warning
947 from a decent compiler. */
949 && local_symbols
->nsyms
> 0)
951 struct symbol
*prev_sym
;
952 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
953 if (SYMBOL_CLASS (prev_sym
) == LOC_ARG
954 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
956 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
957 /* Use the type from the LOC_REGISTER; that is the type
958 that is actually in that register. */
959 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
960 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
965 add_symbol_to_list (sym
, &local_symbols
);
968 add_symbol_to_list (sym
, &file_symbols
);
972 /* Static symbol at top level of file */
973 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
974 SYMBOL_CLASS (sym
) = LOC_STATIC
;
975 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
976 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
977 add_symbol_to_list (sym
, &file_symbols
);
981 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
983 /* For a nameless type, we don't want a create a symbol, thus we
984 did not use `sym'. Return without further processing. */
985 if (nameless
) return NULL
;
987 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
988 SYMBOL_VALUE (sym
) = valu
;
989 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
990 /* C++ vagaries: we may have a type which is derived from
991 a base type which did not have its name defined when the
992 derived class was output. We fill in the derived class's
993 base part member's name here in that case. */
994 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
995 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
996 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
997 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1000 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1001 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1002 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1003 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1006 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1008 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1009 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1011 /* If we are giving a name to a type such as "pointer to
1012 foo" or "function returning foo", we better not set
1013 the TYPE_NAME. If the program contains "typedef char
1014 *caddr_t;", we don't want all variables of type char
1015 * to print as caddr_t. This is not just a
1016 consequence of GDB's type management; PCC and GCC (at
1017 least through version 2.4) both output variables of
1018 either type char * or caddr_t with the type number
1019 defined in the 't' symbol for caddr_t. If a future
1020 compiler cleans this up it GDB is not ready for it
1021 yet, but if it becomes ready we somehow need to
1022 disable this check (without breaking the PCC/GCC2.4
1027 Fortunately, this check seems not to be necessary
1028 for anything except pointers or functions. */
1031 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1034 add_symbol_to_list (sym
, &file_symbols
);
1038 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1039 by 't' which means we are typedef'ing it as well. */
1040 synonym
= *p
== 't';
1045 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1046 strlen (SYMBOL_NAME (sym
)),
1047 &objfile
-> symbol_obstack
);
1049 /* The semantics of C++ state that "struct foo { ... }" also defines
1050 a typedef for "foo". Unfortunately, cfront never makes the typedef
1051 when translating C++ into C. We make the typedef here so that
1052 "ptype foo" works as expected for cfront translated code. */
1053 else if (current_subfile
->language
== language_cplus
)
1056 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1057 strlen (SYMBOL_NAME (sym
)),
1058 &objfile
-> symbol_obstack
);
1061 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1063 /* For a nameless type, we don't want a create a symbol, thus we
1064 did not use `sym'. Return without further processing. */
1065 if (nameless
) return NULL
;
1067 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1068 SYMBOL_VALUE (sym
) = valu
;
1069 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1070 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1071 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1072 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1073 add_symbol_to_list (sym
, &file_symbols
);
1077 /* Clone the sym and then modify it. */
1078 register struct symbol
*typedef_sym
= (struct symbol
*)
1079 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1080 *typedef_sym
= *sym
;
1081 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1082 SYMBOL_VALUE (typedef_sym
) = valu
;
1083 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1084 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1085 TYPE_NAME (SYMBOL_TYPE (sym
))
1086 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1087 add_symbol_to_list (typedef_sym
, &file_symbols
);
1092 /* Static symbol of local scope */
1093 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1094 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1095 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1096 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1097 add_symbol_to_list (sym
, &local_symbols
);
1101 /* Reference parameter */
1102 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1103 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1104 SYMBOL_VALUE (sym
) = valu
;
1105 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1106 add_symbol_to_list (sym
, &local_symbols
);
1110 /* This is used by Sun FORTRAN for "function result value".
1111 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1112 that Pascal uses it too, but when I tried it Pascal used
1113 "x:3" (local symbol) instead. */
1114 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1115 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1116 SYMBOL_VALUE (sym
) = valu
;
1117 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1118 add_symbol_to_list (sym
, &local_symbols
);
1122 SYMBOL_TYPE (sym
) = error_type (&p
);
1123 SYMBOL_CLASS (sym
) = LOC_CONST
;
1124 SYMBOL_VALUE (sym
) = 0;
1125 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1126 add_symbol_to_list (sym
, &file_symbols
);
1130 /* When passing structures to a function, some systems sometimes pass
1131 the address in a register, not the structure itself.
1133 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1134 to LOC_REGPARM_ADDR for structures and unions. */
1136 #if !defined (REG_STRUCT_HAS_ADDR)
1137 #define REG_STRUCT_HAS_ADDR(gcc_p) 0
1140 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1141 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
)
1142 && ( (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1143 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1144 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1150 /* Skip rest of this symbol and return an error type.
1152 General notes on error recovery: error_type always skips to the
1153 end of the symbol (modulo cretinous dbx symbol name continuation).
1154 Thus code like this:
1156 if (*(*pp)++ != ';')
1157 return error_type (pp);
1159 is wrong because if *pp starts out pointing at '\0' (typically as the
1160 result of an earlier error), it will be incremented to point to the
1161 start of the next symbol, which might produce strange results, at least
1162 if you run off the end of the string table. Instead use
1165 return error_type (pp);
1171 foo = error_type (pp);
1175 And in case it isn't obvious, the point of all this hair is so the compiler
1176 can define new types and new syntaxes, and old versions of the
1177 debugger will be able to read the new symbol tables. */
1179 static struct type
*
1183 complain (&error_type_complaint
);
1186 /* Skip to end of symbol. */
1187 while (**pp
!= '\0')
1192 /* Check for and handle cretinous dbx symbol name continuation! */
1193 if ((*pp
)[-1] == '\\')
1195 *pp
= next_symbol_text ();
1202 return (builtin_type_error
);
1206 /* Read type information or a type definition; return the type. Even
1207 though this routine accepts either type information or a type
1208 definition, the distinction is relevant--some parts of stabsread.c
1209 assume that type information starts with a digit, '-', or '(' in
1210 deciding whether to call read_type. */
1213 read_type (pp
, objfile
)
1215 struct objfile
*objfile
;
1217 register struct type
*type
= 0;
1221 char type_descriptor
;
1223 /* Size in bits of type if specified by a type attribute, or -1 if
1224 there is no size attribute. */
1227 /* Read type number if present. The type number may be omitted.
1228 for instance in a two-dimensional array declared with type
1229 "ar1;1;10;ar1;1;10;4". */
1230 if ((**pp
>= '0' && **pp
<= '9')
1234 if (read_type_number (pp
, typenums
) != 0)
1235 return error_type (pp
);
1237 /* Type is not being defined here. Either it already exists,
1238 or this is a forward reference to it. dbx_alloc_type handles
1241 return dbx_alloc_type (typenums
, objfile
);
1243 /* Type is being defined here. */
1250 /* It might be a type attribute or a member type. */
1251 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1256 /* Type attributes. */
1259 /* Skip to the semicolon. */
1260 while (*p
!= ';' && *p
!= '\0')
1264 return error_type (pp
);
1266 /* Skip the semicolon. */
1272 type_size
= atoi (attr
+ 1);
1277 /* Ignore unrecognized type attributes, so future compilers
1278 can invent new ones. */
1283 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1288 /* 'typenums=' not present, type is anonymous. Read and return
1289 the definition, but don't put it in the type vector. */
1290 typenums
[0] = typenums
[1] = -1;
1294 type_descriptor
= (*pp
)[-1];
1295 switch (type_descriptor
)
1299 enum type_code code
;
1301 /* Used to index through file_symbols. */
1302 struct pending
*ppt
;
1305 /* Name including "struct", etc. */
1309 char *from
, *to
, *p
;
1311 /* Set the type code according to the following letter. */
1315 code
= TYPE_CODE_STRUCT
;
1318 code
= TYPE_CODE_UNION
;
1321 code
= TYPE_CODE_ENUM
;
1324 return error_type (pp
);
1327 p
= strchr(*pp
, ':');
1334 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1336 /* Copy the name. */
1342 /* Set the pointer ahead of the name which we just read. */
1346 /* Now check to see whether the type has already been declared. */
1347 /* This is necessary at least in the case where the
1348 program says something like
1350 The compiler puts out a cross-reference; we better find
1351 set the length of the structure correctly so we can
1352 set the length of the array. */
1353 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1354 for (i
= 0; i
< ppt
->nsyms
; i
++)
1356 struct symbol
*sym
= ppt
->symbol
[i
];
1358 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1359 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1360 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1361 && STREQ (SYMBOL_NAME (sym
), type_name
))
1363 obstack_free (&objfile
-> type_obstack
, type_name
);
1364 type
= SYMBOL_TYPE (sym
);
1369 /* Didn't find the type to which this refers, so we must
1370 be dealing with a forward reference. Allocate a type
1371 structure for it, and keep track of it so we can
1372 fill in the rest of the fields when we get the full
1374 type
= dbx_alloc_type (typenums
, objfile
);
1375 TYPE_CODE (type
) = code
;
1376 TYPE_TAG_NAME (type
) = type_name
;
1377 INIT_CPLUS_SPECIFIC(type
);
1378 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1380 add_undefined_type (type
);
1384 case '-': /* RS/6000 built-in type */
1398 if (read_type_number (pp
, xtypenums
) != 0)
1399 return error_type (pp
);
1401 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1402 /* It's being defined as itself. That means it is "void". */
1403 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
1406 struct type
*xtype
= *dbx_lookup_type (xtypenums
);
1408 /* This can happen if we had '-' followed by a garbage character,
1411 return error_type (pp
);
1413 /* The type is being defined to another type. So we copy the type.
1414 This loses if we copy a C++ class and so we lose track of how
1415 the names are mangled (but g++ doesn't output stabs like this
1418 type
= alloc_type (objfile
);
1419 memcpy (type
, xtype
, sizeof (struct type
));
1421 /* The idea behind clearing the names is that the only purpose
1422 for defining a type to another type is so that the name of
1423 one can be different. So we probably don't need to worry much
1424 about the case where the compiler doesn't give a name to the
1426 TYPE_NAME (type
) = NULL
;
1427 TYPE_TAG_NAME (type
) = NULL
;
1429 if (typenums
[0] != -1)
1430 *dbx_lookup_type (typenums
) = type
;
1433 /* In the following types, we must be sure to overwrite any existing
1434 type that the typenums refer to, rather than allocating a new one
1435 and making the typenums point to the new one. This is because there
1436 may already be pointers to the existing type (if it had been
1437 forward-referenced), and we must change it to a pointer, function,
1438 reference, or whatever, *in-place*. */
1441 type1
= read_type (pp
, objfile
);
1442 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1445 case '&': /* Reference to another type */
1446 type1
= read_type (pp
, objfile
);
1447 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1450 case 'f': /* Function returning another type */
1451 type1
= read_type (pp
, objfile
);
1452 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1455 case 'k': /* Const qualifier on some type (Sun) */
1456 type
= read_type (pp
, objfile
);
1457 /* FIXME! For now, we ignore const and volatile qualifiers. */
1460 case 'B': /* Volatile qual on some type (Sun) */
1461 type
= read_type (pp
, objfile
);
1462 /* FIXME! For now, we ignore const and volatile qualifiers. */
1465 /* FIXME -- we should be doing smash_to_XXX types here. */
1466 case '@': /* Member (class & variable) type */
1468 struct type
*domain
= read_type (pp
, objfile
);
1469 struct type
*memtype
;
1472 /* Invalid member type data format. */
1473 return error_type (pp
);
1476 memtype
= read_type (pp
, objfile
);
1477 type
= dbx_alloc_type (typenums
, objfile
);
1478 smash_to_member_type (type
, domain
, memtype
);
1482 case '#': /* Method (class & fn) type */
1483 if ((*pp
)[0] == '#')
1485 /* We'll get the parameter types from the name. */
1486 struct type
*return_type
;
1489 return_type
= read_type (pp
, objfile
);
1490 if (*(*pp
)++ != ';')
1491 complain (&invalid_member_complaint
, symnum
);
1492 type
= allocate_stub_method (return_type
);
1493 if (typenums
[0] != -1)
1494 *dbx_lookup_type (typenums
) = type
;
1498 struct type
*domain
= read_type (pp
, objfile
);
1499 struct type
*return_type
;
1503 /* Invalid member type data format. */
1504 return error_type (pp
);
1508 return_type
= read_type (pp
, objfile
);
1509 args
= read_args (pp
, ';', objfile
);
1510 type
= dbx_alloc_type (typenums
, objfile
);
1511 smash_to_method_type (type
, domain
, return_type
, args
);
1515 case 'r': /* Range type */
1516 type
= read_range_type (pp
, typenums
, objfile
);
1517 if (typenums
[0] != -1)
1518 *dbx_lookup_type (typenums
) = type
;
1521 case 'b': /* Sun ACC builtin int type */
1522 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1523 if (typenums
[0] != -1)
1524 *dbx_lookup_type (typenums
) = type
;
1527 case 'R': /* Sun ACC builtin float type */
1528 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1529 if (typenums
[0] != -1)
1530 *dbx_lookup_type (typenums
) = type
;
1533 case 'e': /* Enumeration type */
1534 type
= dbx_alloc_type (typenums
, objfile
);
1535 type
= read_enum_type (pp
, type
, objfile
);
1536 if (typenums
[0] != -1)
1537 *dbx_lookup_type (typenums
) = type
;
1540 case 's': /* Struct type */
1541 case 'u': /* Union type */
1542 type
= dbx_alloc_type (typenums
, objfile
);
1543 if (!TYPE_NAME (type
))
1545 TYPE_NAME (type
) = type_synonym_name
;
1547 type_synonym_name
= NULL
;
1548 switch (type_descriptor
)
1551 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1554 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1557 type
= read_struct_type (pp
, type
, objfile
);
1560 case 'a': /* Array type */
1562 return error_type (pp
);
1565 type
= dbx_alloc_type (typenums
, objfile
);
1566 type
= read_array_type (pp
, type
, objfile
);
1570 --*pp
; /* Go back to the symbol in error */
1571 /* Particularly important if it was \0! */
1572 return error_type (pp
);
1577 warning ("GDB internal error, type is NULL in stabsread.c\n");
1578 return error_type (pp
);
1581 /* Size specified in a type attribute overrides any other size. */
1582 if (type_size
!= -1)
1583 TYPE_LENGTH (type
) = type_size
/ TARGET_CHAR_BIT
;
1588 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1589 Return the proper type node for a given builtin type number. */
1591 static struct type
*
1592 rs6000_builtin_type (typenum
)
1595 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1596 #define NUMBER_RECOGNIZED 30
1597 /* This includes an empty slot for type number -0. */
1598 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1599 struct type
*rettype
= NULL
;
1601 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1603 complain (&rs6000_builtin_complaint
, typenum
);
1604 return builtin_type_error
;
1606 if (negative_types
[-typenum
] != NULL
)
1607 return negative_types
[-typenum
];
1609 #if TARGET_CHAR_BIT != 8
1610 #error This code wrong for TARGET_CHAR_BIT not 8
1611 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1612 that if that ever becomes not true, the correct fix will be to
1613 make the size in the struct type to be in bits, not in units of
1620 /* The size of this and all the other types are fixed, defined
1621 by the debugging format. If there is a type called "int" which
1622 is other than 32 bits, then it should use a new negative type
1623 number (or avoid negative type numbers for that case).
1624 See stabs.texinfo. */
1625 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1628 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1631 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1634 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1637 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1638 "unsigned char", NULL
);
1641 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1644 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1645 "unsigned short", NULL
);
1648 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1649 "unsigned int", NULL
);
1652 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1655 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1656 "unsigned long", NULL
);
1659 rettype
= init_type (TYPE_CODE_VOID
, 0, 0, "void", NULL
);
1662 /* IEEE single precision (32 bit). */
1663 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1666 /* IEEE double precision (64 bit). */
1667 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1670 /* This is an IEEE double on the RS/6000, and different machines with
1671 different sizes for "long double" should use different negative
1672 type numbers. See stabs.texinfo. */
1673 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1676 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1679 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1682 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1685 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1688 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1691 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1695 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1699 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1703 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1707 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1711 /* Complex type consisting of two IEEE single precision values. */
1712 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1715 /* Complex type consisting of two IEEE double precision values. */
1716 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1719 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1722 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1725 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1728 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1731 negative_types
[-typenum
] = rettype
;
1735 /* This page contains subroutines of read_type. */
1737 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1738 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1739 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1740 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1742 /* Read member function stabs info for C++ classes. The form of each member
1745 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1747 An example with two member functions is:
1749 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1751 For the case of overloaded operators, the format is op$::*.funcs, where
1752 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1753 name (such as `+=') and `.' marks the end of the operator name.
1755 Returns 1 for success, 0 for failure. */
1758 read_member_functions (fip
, pp
, type
, objfile
)
1759 struct field_info
*fip
;
1762 struct objfile
*objfile
;
1766 /* Total number of member functions defined in this class. If the class
1767 defines two `f' functions, and one `g' function, then this will have
1769 int total_length
= 0;
1773 struct next_fnfield
*next
;
1774 struct fn_field fn_field
;
1776 struct type
*look_ahead_type
;
1777 struct next_fnfieldlist
*new_fnlist
;
1778 struct next_fnfield
*new_sublist
;
1782 /* Process each list until we find something that is not a member function
1783 or find the end of the functions. */
1787 /* We should be positioned at the start of the function name.
1788 Scan forward to find the first ':' and if it is not the
1789 first of a "::" delimiter, then this is not a member function. */
1801 look_ahead_type
= NULL
;
1804 new_fnlist
= (struct next_fnfieldlist
*)
1805 xmalloc (sizeof (struct next_fnfieldlist
));
1806 make_cleanup (free
, new_fnlist
);
1807 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1809 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1811 /* This is a completely wierd case. In order to stuff in the
1812 names that might contain colons (the usual name delimiter),
1813 Mike Tiemann defined a different name format which is
1814 signalled if the identifier is "op$". In that case, the
1815 format is "op$::XXXX." where XXXX is the name. This is
1816 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1817 /* This lets the user type "break operator+".
1818 We could just put in "+" as the name, but that wouldn't
1820 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1821 char *o
= opname
+ 3;
1823 /* Skip past '::'. */
1826 STABS_CONTINUE (pp
);
1832 main_fn_name
= savestring (opname
, o
- opname
);
1838 main_fn_name
= savestring (*pp
, p
- *pp
);
1839 /* Skip past '::'. */
1842 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1847 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1848 make_cleanup (free
, new_sublist
);
1849 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1851 /* Check for and handle cretinous dbx symbol name continuation! */
1852 if (look_ahead_type
== NULL
)
1855 STABS_CONTINUE (pp
);
1857 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1860 /* Invalid symtab info for member function. */
1866 /* g++ version 1 kludge */
1867 new_sublist
-> fn_field
.type
= look_ahead_type
;
1868 look_ahead_type
= NULL
;
1878 /* If this is just a stub, then we don't have the real name here. */
1880 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1882 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
1883 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
1884 new_sublist
-> fn_field
.is_stub
= 1;
1886 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1889 /* Set this member function's visibility fields. */
1892 case VISIBILITY_PRIVATE
:
1893 new_sublist
-> fn_field
.is_private
= 1;
1895 case VISIBILITY_PROTECTED
:
1896 new_sublist
-> fn_field
.is_protected
= 1;
1900 STABS_CONTINUE (pp
);
1903 case 'A': /* Normal functions. */
1904 new_sublist
-> fn_field
.is_const
= 0;
1905 new_sublist
-> fn_field
.is_volatile
= 0;
1908 case 'B': /* `const' member functions. */
1909 new_sublist
-> fn_field
.is_const
= 1;
1910 new_sublist
-> fn_field
.is_volatile
= 0;
1913 case 'C': /* `volatile' member function. */
1914 new_sublist
-> fn_field
.is_const
= 0;
1915 new_sublist
-> fn_field
.is_volatile
= 1;
1918 case 'D': /* `const volatile' member function. */
1919 new_sublist
-> fn_field
.is_const
= 1;
1920 new_sublist
-> fn_field
.is_volatile
= 1;
1923 case '*': /* File compiled with g++ version 1 -- no info */
1928 complain (&const_vol_complaint
, **pp
);
1937 /* virtual member function, followed by index.
1938 The sign bit is set to distinguish pointers-to-methods
1939 from virtual function indicies. Since the array is
1940 in words, the quantity must be shifted left by 1
1941 on 16 bit machine, and by 2 on 32 bit machine, forcing
1942 the sign bit out, and usable as a valid index into
1943 the array. Remove the sign bit here. */
1944 new_sublist
-> fn_field
.voffset
=
1945 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
1949 STABS_CONTINUE (pp
);
1950 if (**pp
== ';' || **pp
== '\0')
1952 /* Must be g++ version 1. */
1953 new_sublist
-> fn_field
.fcontext
= 0;
1957 /* Figure out from whence this virtual function came.
1958 It may belong to virtual function table of
1959 one of its baseclasses. */
1960 look_ahead_type
= read_type (pp
, objfile
);
1963 /* g++ version 1 overloaded methods. */
1967 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1976 look_ahead_type
= NULL
;
1982 /* static member function. */
1983 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
1984 if (strncmp (new_sublist
-> fn_field
.physname
,
1985 main_fn_name
, strlen (main_fn_name
)))
1987 new_sublist
-> fn_field
.is_stub
= 1;
1993 complain (&member_fn_complaint
, (*pp
)[-1]);
1994 /* Fall through into normal member function. */
1997 /* normal member function. */
1998 new_sublist
-> fn_field
.voffset
= 0;
1999 new_sublist
-> fn_field
.fcontext
= 0;
2003 new_sublist
-> next
= sublist
;
2004 sublist
= new_sublist
;
2006 STABS_CONTINUE (pp
);
2008 while (**pp
!= ';' && **pp
!= '\0');
2012 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2013 obstack_alloc (&objfile
-> type_obstack
,
2014 sizeof (struct fn_field
) * length
);
2015 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2016 sizeof (struct fn_field
) * length
);
2017 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2019 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2022 new_fnlist
-> fn_fieldlist
.length
= length
;
2023 new_fnlist
-> next
= fip
-> fnlist
;
2024 fip
-> fnlist
= new_fnlist
;
2026 total_length
+= length
;
2027 STABS_CONTINUE (pp
);
2032 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2033 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2034 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2035 memset (TYPE_FN_FIELDLISTS (type
), 0,
2036 sizeof (struct fn_fieldlist
) * nfn_fields
);
2037 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2038 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2044 /* Special GNU C++ name.
2046 Returns 1 for success, 0 for failure. "failure" means that we can't
2047 keep parsing and it's time for error_type(). */
2050 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2051 struct field_info
*fip
;
2054 struct objfile
*objfile
;
2059 struct type
*context
;
2069 /* At this point, *pp points to something like "22:23=*22...",
2070 where the type number before the ':' is the "context" and
2071 everything after is a regular type definition. Lookup the
2072 type, find it's name, and construct the field name. */
2074 context
= read_type (pp
, objfile
);
2078 case 'f': /* $vf -- a virtual function table pointer */
2079 fip
->list
->field
.name
=
2080 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2083 case 'b': /* $vb -- a virtual bsomethingorother */
2084 name
= type_name_no_tag (context
);
2087 complain (&invalid_cpp_type_complaint
, symnum
);
2090 fip
->list
->field
.name
=
2091 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2095 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2096 fip
->list
->field
.name
=
2097 obconcat (&objfile
->type_obstack
,
2098 "INVALID_CPLUSPLUS_ABBREV", "", "");
2102 /* At this point, *pp points to the ':'. Skip it and read the
2108 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2111 fip
->list
->field
.type
= read_type (pp
, objfile
);
2113 (*pp
)++; /* Skip the comma. */
2119 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2123 /* This field is unpacked. */
2124 fip
->list
->field
.bitsize
= 0;
2125 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2129 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2130 /* We have no idea what syntax an unrecognized abbrev would have, so
2131 better return 0. If we returned 1, we would need to at least advance
2132 *pp to avoid an infinite loop. */
2139 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2140 struct field_info
*fip
;
2144 struct objfile
*objfile
;
2146 fip
-> list
-> field
.name
=
2147 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2150 /* This means we have a visibility for a field coming. */
2154 fip
-> list
-> visibility
= *(*pp
)++;
2158 /* normal dbx-style format, no explicit visibility */
2159 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2162 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2167 /* Possible future hook for nested types. */
2170 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2176 /* Static class member. */
2177 fip
-> list
-> field
.bitpos
= (long) -1;
2183 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2187 else if (**pp
!= ',')
2189 /* Bad structure-type format. */
2190 complain (&stabs_general_complaint
, "bad structure-type format");
2194 (*pp
)++; /* Skip the comma. */
2198 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2201 complain (&stabs_general_complaint
, "bad structure-type format");
2204 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2207 complain (&stabs_general_complaint
, "bad structure-type format");
2212 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2214 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2215 it is a field which has been optimized out. The correct stab for
2216 this case is to use VISIBILITY_IGNORE, but that is a recent
2217 invention. (2) It is a 0-size array. For example
2218 union { int num; char str[0]; } foo. Printing "<no value>" for
2219 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2220 will continue to work, and a 0-size array as a whole doesn't
2221 have any contents to print.
2223 I suspect this probably could also happen with gcc -gstabs (not
2224 -gstabs+) for static fields, and perhaps other C++ extensions.
2225 Hopefully few people use -gstabs with gdb, since it is intended
2226 for dbx compatibility. */
2228 /* Ignore this field. */
2229 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2233 /* Detect an unpacked field and mark it as such.
2234 dbx gives a bit size for all fields.
2235 Note that forward refs cannot be packed,
2236 and treat enums as if they had the width of ints. */
2238 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2239 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2241 fip
-> list
-> field
.bitsize
= 0;
2243 if ((fip
-> list
-> field
.bitsize
2244 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2245 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2246 && (fip
-> list
-> field
.bitsize
2251 fip
-> list
-> field
.bitpos
% 8 == 0)
2253 fip
-> list
-> field
.bitsize
= 0;
2259 /* Read struct or class data fields. They have the form:
2261 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2263 At the end, we see a semicolon instead of a field.
2265 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2268 The optional VISIBILITY is one of:
2270 '/0' (VISIBILITY_PRIVATE)
2271 '/1' (VISIBILITY_PROTECTED)
2272 '/2' (VISIBILITY_PUBLIC)
2273 '/9' (VISIBILITY_IGNORE)
2275 or nothing, for C style fields with public visibility.
2277 Returns 1 for success, 0 for failure. */
2280 read_struct_fields (fip
, pp
, type
, objfile
)
2281 struct field_info
*fip
;
2284 struct objfile
*objfile
;
2287 struct nextfield
*new;
2289 /* We better set p right now, in case there are no fields at all... */
2293 /* Read each data member type until we find the terminating ';' at the end of
2294 the data member list, or break for some other reason such as finding the
2295 start of the member function list. */
2299 STABS_CONTINUE (pp
);
2300 /* Get space to record the next field's data. */
2301 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2302 make_cleanup (free
, new);
2303 memset (new, 0, sizeof (struct nextfield
));
2304 new -> next
= fip
-> list
;
2307 /* Get the field name. */
2310 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2311 unless the CPLUS_MARKER is followed by an underscore, in
2312 which case it is just the name of an anonymous type, which we
2313 should handle like any other type name. We accept either '$'
2314 or '.', because a field name can never contain one of these
2315 characters except as a CPLUS_MARKER (we probably should be
2316 doing that in most parts of GDB). */
2318 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2320 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2325 /* Look for the ':' that separates the field name from the field
2326 values. Data members are delimited by a single ':', while member
2327 functions are delimited by a pair of ':'s. When we hit the member
2328 functions (if any), terminate scan loop and return. */
2330 while (*p
!= ':' && *p
!= '\0')
2337 /* Check to see if we have hit the member functions yet. */
2342 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2346 /* chill the list of fields: the last entry (at the head) is a
2347 partially constructed entry which we now scrub. */
2348 fip
-> list
= fip
-> list
-> next
;
2353 /* The stabs for C++ derived classes contain baseclass information which
2354 is marked by a '!' character after the total size. This function is
2355 called when we encounter the baseclass marker, and slurps up all the
2356 baseclass information.
2358 Immediately following the '!' marker is the number of base classes that
2359 the class is derived from, followed by information for each base class.
2360 For each base class, there are two visibility specifiers, a bit offset
2361 to the base class information within the derived class, a reference to
2362 the type for the base class, and a terminating semicolon.
2364 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2366 Baseclass information marker __________________|| | | | | | |
2367 Number of baseclasses __________________________| | | | | | |
2368 Visibility specifiers (2) ________________________| | | | | |
2369 Offset in bits from start of class _________________| | | | |
2370 Type number for base class ___________________________| | | |
2371 Visibility specifiers (2) _______________________________| | |
2372 Offset in bits from start of class ________________________| |
2373 Type number of base class ____________________________________|
2375 Return 1 for success, 0 for (error-type-inducing) failure. */
2378 read_baseclasses (fip
, pp
, type
, objfile
)
2379 struct field_info
*fip
;
2382 struct objfile
*objfile
;
2385 struct nextfield
*new;
2393 /* Skip the '!' baseclass information marker. */
2397 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2400 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2406 /* Some stupid compilers have trouble with the following, so break
2407 it up into simpler expressions. */
2408 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2409 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2412 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2415 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2416 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2420 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2422 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2424 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2425 make_cleanup (free
, new);
2426 memset (new, 0, sizeof (struct nextfield
));
2427 new -> next
= fip
-> list
;
2429 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2431 STABS_CONTINUE (pp
);
2435 /* Nothing to do. */
2438 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2441 /* Unknown character. Complain and treat it as non-virtual. */
2443 static struct complaint msg
= {
2444 "Unknown virtual character `%c' for baseclass", 0, 0};
2445 complain (&msg
, **pp
);
2450 new -> visibility
= *(*pp
)++;
2451 switch (new -> visibility
)
2453 case VISIBILITY_PRIVATE
:
2454 case VISIBILITY_PROTECTED
:
2455 case VISIBILITY_PUBLIC
:
2458 /* Bad visibility format. Complain and treat it as
2461 static struct complaint msg
= {
2462 "Unknown visibility `%c' for baseclass", 0, 0};
2463 complain (&msg
, new -> visibility
);
2464 new -> visibility
= VISIBILITY_PUBLIC
;
2471 /* The remaining value is the bit offset of the portion of the object
2472 corresponding to this baseclass. Always zero in the absence of
2473 multiple inheritance. */
2475 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2480 /* The last piece of baseclass information is the type of the
2481 base class. Read it, and remember it's type name as this
2484 new -> field
.type
= read_type (pp
, objfile
);
2485 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2487 /* skip trailing ';' and bump count of number of fields seen */
2496 /* The tail end of stabs for C++ classes that contain a virtual function
2497 pointer contains a tilde, a %, and a type number.
2498 The type number refers to the base class (possibly this class itself) which
2499 contains the vtable pointer for the current class.
2501 This function is called when we have parsed all the method declarations,
2502 so we can look for the vptr base class info. */
2505 read_tilde_fields (fip
, pp
, type
, objfile
)
2506 struct field_info
*fip
;
2509 struct objfile
*objfile
;
2513 STABS_CONTINUE (pp
);
2515 /* If we are positioned at a ';', then skip it. */
2525 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2527 /* Obsolete flags that used to indicate the presence
2528 of constructors and/or destructors. */
2532 /* Read either a '%' or the final ';'. */
2533 if (*(*pp
)++ == '%')
2535 /* The next number is the type number of the base class
2536 (possibly our own class) which supplies the vtable for
2537 this class. Parse it out, and search that class to find
2538 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2539 and TYPE_VPTR_FIELDNO. */
2544 t
= read_type (pp
, objfile
);
2546 while (*p
!= '\0' && *p
!= ';')
2552 /* Premature end of symbol. */
2556 TYPE_VPTR_BASETYPE (type
) = t
;
2557 if (type
== t
) /* Our own class provides vtbl ptr */
2559 for (i
= TYPE_NFIELDS (t
) - 1;
2560 i
>= TYPE_N_BASECLASSES (t
);
2563 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2564 sizeof (vptr_name
) - 1))
2566 TYPE_VPTR_FIELDNO (type
) = i
;
2570 /* Virtual function table field not found. */
2571 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2576 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2587 attach_fn_fields_to_type (fip
, type
)
2588 struct field_info
*fip
;
2589 register struct type
*type
;
2593 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2595 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2597 /* @@ Memory leak on objfile -> type_obstack? */
2600 TYPE_NFN_FIELDS_TOTAL (type
) +=
2601 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2604 for (n
= TYPE_NFN_FIELDS (type
);
2605 fip
-> fnlist
!= NULL
;
2606 fip
-> fnlist
= fip
-> fnlist
-> next
)
2608 --n
; /* Circumvent Sun3 compiler bug */
2609 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2614 /* Create the vector of fields, and record how big it is.
2615 We need this info to record proper virtual function table information
2616 for this class's virtual functions. */
2619 attach_fields_to_type (fip
, type
, objfile
)
2620 struct field_info
*fip
;
2621 register struct type
*type
;
2622 struct objfile
*objfile
;
2624 register int nfields
= 0;
2625 register int non_public_fields
= 0;
2626 register struct nextfield
*scan
;
2628 /* Count up the number of fields that we have, as well as taking note of
2629 whether or not there are any non-public fields, which requires us to
2630 allocate and build the private_field_bits and protected_field_bits
2633 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2636 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2638 non_public_fields
++;
2642 /* Now we know how many fields there are, and whether or not there are any
2643 non-public fields. Record the field count, allocate space for the
2644 array of fields, and create blank visibility bitfields if necessary. */
2646 TYPE_NFIELDS (type
) = nfields
;
2647 TYPE_FIELDS (type
) = (struct field
*)
2648 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2649 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2651 if (non_public_fields
)
2653 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2655 TYPE_FIELD_PRIVATE_BITS (type
) =
2656 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2657 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2659 TYPE_FIELD_PROTECTED_BITS (type
) =
2660 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2661 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2663 TYPE_FIELD_IGNORE_BITS (type
) =
2664 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2665 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2668 /* Copy the saved-up fields into the field vector. Start from the head
2669 of the list, adding to the tail of the field array, so that they end
2670 up in the same order in the array in which they were added to the list. */
2672 while (nfields
-- > 0)
2674 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2675 switch (fip
-> list
-> visibility
)
2677 case VISIBILITY_PRIVATE
:
2678 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2681 case VISIBILITY_PROTECTED
:
2682 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2685 case VISIBILITY_IGNORE
:
2686 SET_TYPE_FIELD_IGNORE (type
, nfields
);
2689 case VISIBILITY_PUBLIC
:
2693 /* Unknown visibility. Complain and treat it as public. */
2695 static struct complaint msg
= {
2696 "Unknown visibility `%c' for field", 0, 0};
2697 complain (&msg
, fip
-> list
-> visibility
);
2701 fip
-> list
= fip
-> list
-> next
;
2706 /* Read the description of a structure (or union type) and return an object
2707 describing the type.
2709 PP points to a character pointer that points to the next unconsumed token
2710 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2711 *PP will point to "4a:1,0,32;;".
2713 TYPE points to an incomplete type that needs to be filled in.
2715 OBJFILE points to the current objfile from which the stabs information is
2716 being read. (Note that it is redundant in that TYPE also contains a pointer
2717 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2720 static struct type
*
2721 read_struct_type (pp
, type
, objfile
)
2724 struct objfile
*objfile
;
2726 struct cleanup
*back_to
;
2727 struct field_info fi
;
2732 back_to
= make_cleanup (null_cleanup
, 0);
2734 INIT_CPLUS_SPECIFIC (type
);
2735 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2737 /* First comes the total size in bytes. */
2741 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2743 return error_type (pp
);
2746 /* Now read the baseclasses, if any, read the regular C struct or C++
2747 class member fields, attach the fields to the type, read the C++
2748 member functions, attach them to the type, and then read any tilde
2749 field (baseclass specifier for the class holding the main vtable). */
2751 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2752 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2753 || !attach_fields_to_type (&fi
, type
, objfile
)
2754 || !read_member_functions (&fi
, pp
, type
, objfile
)
2755 || !attach_fn_fields_to_type (&fi
, type
)
2756 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2758 do_cleanups (back_to
);
2759 return (error_type (pp
));
2762 do_cleanups (back_to
);
2766 /* Read a definition of an array type,
2767 and create and return a suitable type object.
2768 Also creates a range type which represents the bounds of that
2771 static struct type
*
2772 read_array_type (pp
, type
, objfile
)
2774 register struct type
*type
;
2775 struct objfile
*objfile
;
2777 struct type
*index_type
, *element_type
, *range_type
;
2782 /* Format of an array type:
2783 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2786 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2787 for these, produce a type like float[][]. */
2789 index_type
= read_type (pp
, objfile
);
2791 /* Improper format of array type decl. */
2792 return error_type (pp
);
2795 if (!(**pp
>= '0' && **pp
<= '9'))
2800 lower
= read_huge_number (pp
, ';', &nbits
);
2802 return error_type (pp
);
2804 if (!(**pp
>= '0' && **pp
<= '9'))
2809 upper
= read_huge_number (pp
, ';', &nbits
);
2811 return error_type (pp
);
2813 element_type
= read_type (pp
, objfile
);
2822 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2823 type
= create_array_type (type
, element_type
, range_type
);
2825 /* If we have an array whose element type is not yet known, but whose
2826 bounds *are* known, record it to be adjusted at the end of the file. */
2828 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2830 add_undefined_type (type
);
2837 /* Read a definition of an enumeration type,
2838 and create and return a suitable type object.
2839 Also defines the symbols that represent the values of the type. */
2841 static struct type
*
2842 read_enum_type (pp
, type
, objfile
)
2844 register struct type
*type
;
2845 struct objfile
*objfile
;
2850 register struct symbol
*sym
;
2852 struct pending
**symlist
;
2853 struct pending
*osyms
, *syms
;
2857 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2858 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2859 to do? For now, force all enum values to file scope. */
2860 if (within_function
)
2861 symlist
= &local_symbols
;
2864 symlist
= &file_symbols
;
2866 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2868 /* Read the value-names and their values.
2869 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2870 A semicolon or comma instead of a NAME means the end. */
2871 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2874 STABS_CONTINUE (pp
);
2876 while (*p
!= ':') p
++;
2877 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2879 n
= read_huge_number (pp
, ',', &nbits
);
2881 return error_type (pp
);
2883 sym
= (struct symbol
*)
2884 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2885 memset (sym
, 0, sizeof (struct symbol
));
2886 SYMBOL_NAME (sym
) = name
;
2887 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
2888 SYMBOL_CLASS (sym
) = LOC_CONST
;
2889 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2890 SYMBOL_VALUE (sym
) = n
;
2891 add_symbol_to_list (sym
, symlist
);
2896 (*pp
)++; /* Skip the semicolon. */
2898 /* Now fill in the fields of the type-structure. */
2900 TYPE_LENGTH (type
) = sizeof (int);
2901 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2902 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2903 TYPE_NFIELDS (type
) = nsyms
;
2904 TYPE_FIELDS (type
) = (struct field
*)
2905 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2906 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2908 /* Find the symbols for the values and put them into the type.
2909 The symbols can be found in the symlist that we put them on
2910 to cause them to be defined. osyms contains the old value
2911 of that symlist; everything up to there was defined by us. */
2912 /* Note that we preserve the order of the enum constants, so
2913 that in something like "enum {FOO, LAST_THING=FOO}" we print
2914 FOO, not LAST_THING. */
2916 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2921 for (; j
< syms
->nsyms
; j
++,n
++)
2923 struct symbol
*xsym
= syms
->symbol
[j
];
2924 SYMBOL_TYPE (xsym
) = type
;
2925 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2926 TYPE_FIELD_VALUE (type
, n
) = 0;
2927 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2928 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2935 /* This screws up perfectly good C programs with enums. FIXME. */
2936 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2937 if(TYPE_NFIELDS(type
) == 2 &&
2938 ((STREQ(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2939 STREQ(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2940 (STREQ(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2941 STREQ(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2942 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2948 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2949 typedefs in every file (for int, long, etc):
2951 type = b <signed> <width>; <offset>; <nbits>
2952 signed = u or s. Possible c in addition to u or s (for char?).
2953 offset = offset from high order bit to start bit of type.
2954 width is # bytes in object of this type, nbits is # bits in type.
2956 The width/offset stuff appears to be for small objects stored in
2957 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2960 static struct type
*
2961 read_sun_builtin_type (pp
, typenums
, objfile
)
2964 struct objfile
*objfile
;
2979 return error_type (pp
);
2983 /* For some odd reason, all forms of char put a c here. This is strange
2984 because no other type has this honor. We can safely ignore this because
2985 we actually determine 'char'acterness by the number of bits specified in
2991 /* The first number appears to be the number of bytes occupied
2992 by this type, except that unsigned short is 4 instead of 2.
2993 Since this information is redundant with the third number,
2994 we will ignore it. */
2995 read_huge_number (pp
, ';', &nbits
);
2997 return error_type (pp
);
2999 /* The second number is always 0, so ignore it too. */
3000 read_huge_number (pp
, ';', &nbits
);
3002 return error_type (pp
);
3004 /* The third number is the number of bits for this type. */
3005 type_bits
= read_huge_number (pp
, 0, &nbits
);
3007 return error_type (pp
);
3009 return init_type (type_bits
== 0 ? TYPE_CODE_VOID
: TYPE_CODE_INT
,
3010 type_bits
/ TARGET_CHAR_BIT
,
3011 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3015 static struct type
*
3016 read_sun_floating_type (pp
, typenums
, objfile
)
3019 struct objfile
*objfile
;
3025 /* The first number has more details about the type, for example
3027 details
= read_huge_number (pp
, ';', &nbits
);
3029 return error_type (pp
);
3031 /* The second number is the number of bytes occupied by this type */
3032 nbytes
= read_huge_number (pp
, ';', &nbits
);
3034 return error_type (pp
);
3036 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3037 || details
== NF_COMPLEX32
)
3038 /* This is a type we can't handle, but we do know the size.
3039 We also will be able to give it a name. */
3040 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3042 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3045 /* Read a number from the string pointed to by *PP.
3046 The value of *PP is advanced over the number.
3047 If END is nonzero, the character that ends the
3048 number must match END, or an error happens;
3049 and that character is skipped if it does match.
3050 If END is zero, *PP is left pointing to that character.
3052 If the number fits in a long, set *BITS to 0 and return the value.
3053 If not, set *BITS to be the number of bits in the number and return 0.
3055 If encounter garbage, set *BITS to -1 and return 0. */
3058 read_huge_number (pp
, end
, bits
)
3078 /* Leading zero means octal. GCC uses this to output values larger
3079 than an int (because that would be hard in decimal). */
3086 upper_limit
= LONG_MAX
/ radix
;
3087 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3089 if (n
<= upper_limit
)
3092 n
+= c
- '0'; /* FIXME this overflows anyway */
3097 /* This depends on large values being output in octal, which is
3104 /* Ignore leading zeroes. */
3108 else if (c
== '2' || c
== '3')
3134 /* Large decimal constants are an error (because it is hard to
3135 count how many bits are in them). */
3141 /* -0x7f is the same as 0x80. So deal with it by adding one to
3142 the number of bits. */
3154 /* It's *BITS which has the interesting information. */
3158 static struct type
*
3159 read_range_type (pp
, typenums
, objfile
)
3162 struct objfile
*objfile
;
3168 struct type
*result_type
;
3169 struct type
*index_type
;
3171 /* First comes a type we are a subrange of.
3172 In C it is usually 0, 1 or the type being defined. */
3173 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3174 not just a type number. */
3175 if (read_type_number (pp
, rangenums
) != 0)
3176 return error_type (pp
);
3177 self_subrange
= (rangenums
[0] == typenums
[0] &&
3178 rangenums
[1] == typenums
[1]);
3180 /* A semicolon should now follow; skip it. */
3184 /* The remaining two operands are usually lower and upper bounds
3185 of the range. But in some special cases they mean something else. */
3186 n2
= read_huge_number (pp
, ';', &n2bits
);
3187 n3
= read_huge_number (pp
, ';', &n3bits
);
3189 if (n2bits
== -1 || n3bits
== -1)
3190 return error_type (pp
);
3192 /* If limits are huge, must be large integral type. */
3193 if (n2bits
!= 0 || n3bits
!= 0)
3195 char got_signed
= 0;
3196 char got_unsigned
= 0;
3197 /* Number of bits in the type. */
3200 /* Range from 0 to <large number> is an unsigned large integral type. */
3201 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3206 /* Range from <large number> to <large number>-1 is a large signed
3207 integral type. Take care of the case where <large number> doesn't
3208 fit in a long but <large number>-1 does. */
3209 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3210 || (n2bits
!= 0 && n3bits
== 0
3211 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3218 if (got_signed
|| got_unsigned
)
3220 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3221 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3225 return error_type (pp
);
3228 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3229 if (self_subrange
&& n2
== 0 && n3
== 0)
3230 return init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
3232 /* If n3 is zero and n2 is not, we want a floating type,
3233 and n2 is the width in bytes.
3235 Fortran programs appear to use this for complex types also,
3236 and they give no way to distinguish between double and single-complex!
3238 GDB does not have complex types.
3240 Just return the complex as a float of that size. It won't work right
3241 for the complex values, but at least it makes the file loadable. */
3243 if (n3
== 0 && n2
> 0)
3245 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3248 /* If the upper bound is -1, it must really be an unsigned int. */
3250 else if (n2
== 0 && n3
== -1)
3252 /* It is unsigned int or unsigned long. */
3253 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3254 compatibility hack. */
3255 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3256 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3259 /* Special case: char is defined (Who knows why) as a subrange of
3260 itself with range 0-127. */
3261 else if (self_subrange
&& n2
== 0 && n3
== 127)
3262 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3264 /* We used to do this only for subrange of self or subrange of int. */
3268 /* n3 actually gives the size. */
3269 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3272 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3274 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3276 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3277 "unsigned long", and we already checked for that,
3278 so don't need to test for it here. */
3280 /* I think this is for Convex "long long". Since I don't know whether
3281 Convex sets self_subrange, I also accept that particular size regardless
3282 of self_subrange. */
3283 else if (n3
== 0 && n2
< 0
3285 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3286 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3287 else if (n2
== -n3
-1)
3290 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3292 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3293 if (n3
== 0x7fffffff)
3294 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3297 /* We have a real range type on our hands. Allocate space and
3298 return a real pointer. */
3300 /* At this point I don't have the faintest idea how to deal with
3301 a self_subrange type; I'm going to assume that this is used
3302 as an idiom, and that all of them are special cases. So . . . */
3304 return error_type (pp
);
3306 index_type
= *dbx_lookup_type (rangenums
);
3307 if (index_type
== NULL
)
3309 /* Does this actually ever happen? Is that why we are worrying
3310 about dealing with it rather than just calling error_type? */
3312 static struct type
*range_type_index
;
3314 complain (&range_type_base_complaint
, rangenums
[1]);
3315 if (range_type_index
== NULL
)
3317 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3318 0, "range type index type", NULL
);
3319 index_type
= range_type_index
;
3322 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3323 return (result_type
);
3326 /* Read in an argument list. This is a list of types, separated by commas
3327 and terminated with END. Return the list of types read in, or (struct type
3328 **)-1 if there is an error. */
3330 static struct type
**
3331 read_args (pp
, end
, objfile
)
3334 struct objfile
*objfile
;
3336 /* FIXME! Remove this arbitrary limit! */
3337 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3343 /* Invalid argument list: no ','. */
3344 return (struct type
**)-1;
3346 STABS_CONTINUE (pp
);
3347 types
[n
++] = read_type (pp
, objfile
);
3349 (*pp
)++; /* get past `end' (the ':' character) */
3353 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3355 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3357 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3358 memset (rval
+ n
, 0, sizeof (struct type
*));
3362 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3364 memcpy (rval
, types
, n
* sizeof (struct type
*));
3368 /* Common block handling. */
3370 /* List of symbols declared since the last BCOMM. This list is a tail
3371 of local_symbols. When ECOMM is seen, the symbols on the list
3372 are noted so their proper addresses can be filled in later,
3373 using the common block base address gotten from the assembler
3376 static struct pending
*common_block
;
3377 static int common_block_i
;
3379 /* Name of the current common block. We get it from the BCOMM instead of the
3380 ECOMM to match IBM documentation (even though IBM puts the name both places
3381 like everyone else). */
3382 static char *common_block_name
;
3384 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3385 to remain after this function returns. */
3388 common_block_start (name
, objfile
)
3390 struct objfile
*objfile
;
3392 if (common_block_name
!= NULL
)
3394 static struct complaint msg
= {
3395 "Invalid symbol data: common block within common block",
3399 common_block
= local_symbols
;
3400 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3401 common_block_name
= obsavestring (name
, strlen (name
),
3402 &objfile
-> symbol_obstack
);
3405 /* Process a N_ECOMM symbol. */
3408 common_block_end (objfile
)
3409 struct objfile
*objfile
;
3411 /* Symbols declared since the BCOMM are to have the common block
3412 start address added in when we know it. common_block and
3413 common_block_i point to the first symbol after the BCOMM in
3414 the local_symbols list; copy the list and hang it off the
3415 symbol for the common block name for later fixup. */
3418 struct pending
*new = 0;
3419 struct pending
*next
;
3422 if (common_block_name
== NULL
)
3424 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
3429 sym
= (struct symbol
*)
3430 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3431 memset (sym
, 0, sizeof (struct symbol
));
3432 SYMBOL_NAME (sym
) = common_block_name
;
3433 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3435 /* Now we copy all the symbols which have been defined since the BCOMM. */
3437 /* Copy all the struct pendings before common_block. */
3438 for (next
= local_symbols
;
3439 next
!= NULL
&& next
!= common_block
;
3442 for (j
= 0; j
< next
->nsyms
; j
++)
3443 add_symbol_to_list (next
->symbol
[j
], &new);
3446 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3447 NULL, it means copy all the local symbols (which we already did
3450 if (common_block
!= NULL
)
3451 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
3452 add_symbol_to_list (common_block
->symbol
[j
], &new);
3454 SYMBOL_NAMESPACE (sym
) = (enum namespace)((long) new);
3456 /* Should we be putting local_symbols back to what it was?
3459 i
= hashname (SYMBOL_NAME (sym
));
3460 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3461 global_sym_chain
[i
] = sym
;
3462 common_block_name
= NULL
;
3465 /* Add a common block's start address to the offset of each symbol
3466 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3467 the common block name). */
3470 fix_common_block (sym
, valu
)
3474 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3475 for ( ; next
; next
= next
->next
)
3478 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3479 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3485 /* What about types defined as forward references inside of a small lexical
3487 /* Add a type to the list of undefined types to be checked through
3488 once this file has been read in. */
3491 add_undefined_type (type
)
3494 if (undef_types_length
== undef_types_allocated
)
3496 undef_types_allocated
*= 2;
3497 undef_types
= (struct type
**)
3498 xrealloc ((char *) undef_types
,
3499 undef_types_allocated
* sizeof (struct type
*));
3501 undef_types
[undef_types_length
++] = type
;
3504 /* Go through each undefined type, see if it's still undefined, and fix it
3505 up if possible. We have two kinds of undefined types:
3507 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3508 Fix: update array length using the element bounds
3509 and the target type's length.
3510 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3511 yet defined at the time a pointer to it was made.
3512 Fix: Do a full lookup on the struct/union tag. */
3514 cleanup_undefined_types ()
3518 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3520 switch (TYPE_CODE (*type
))
3523 case TYPE_CODE_STRUCT
:
3524 case TYPE_CODE_UNION
:
3525 case TYPE_CODE_ENUM
:
3527 /* Check if it has been defined since. */
3528 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3530 struct pending
*ppt
;
3532 /* Name of the type, without "struct" or "union" */
3533 char *typename
= TYPE_TAG_NAME (*type
);
3535 if (typename
== NULL
)
3537 static struct complaint msg
= {"need a type name", 0, 0};
3541 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3543 for (i
= 0; i
< ppt
->nsyms
; i
++)
3545 struct symbol
*sym
= ppt
->symbol
[i
];
3547 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3548 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3549 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3551 && STREQ (SYMBOL_NAME (sym
), typename
))
3553 memcpy (*type
, SYMBOL_TYPE (sym
),
3554 sizeof (struct type
));
3562 case TYPE_CODE_ARRAY
:
3564 struct type
*range_type
;
3567 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3569 if (TYPE_NFIELDS (*type
) != 1)
3571 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3572 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3575 /* Now recompute the length of the array type, based on its
3576 number of elements and the target type's length. */
3577 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3578 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3579 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3580 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3587 static struct complaint msg
= {"\
3588 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3589 complain (&msg
, TYPE_CODE (*type
));
3594 undef_types_length
= 0;
3597 /* Scan through all of the global symbols defined in the object file,
3598 assigning values to the debugging symbols that need to be assigned
3599 to. Get these symbols from the minimal symbol table. */
3602 scan_file_globals (objfile
)
3603 struct objfile
*objfile
;
3606 struct minimal_symbol
*msymbol
;
3607 struct symbol
*sym
, *prev
;
3609 if (objfile
->msymbols
== 0) /* Beware the null file. */
3612 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3618 /* Get the hash index and check all the symbols
3619 under that hash index. */
3621 hash
= hashname (SYMBOL_NAME (msymbol
));
3623 for (sym
= global_sym_chain
[hash
]; sym
;)
3625 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3626 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3628 /* Splice this symbol out of the hash chain and
3629 assign the value we have to it. */
3632 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3636 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3639 /* Check to see whether we need to fix up a common block. */
3640 /* Note: this code might be executed several times for
3641 the same symbol if there are multiple references. */
3643 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3645 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3649 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3654 sym
= SYMBOL_VALUE_CHAIN (prev
);
3658 sym
= global_sym_chain
[hash
];
3664 sym
= SYMBOL_VALUE_CHAIN (sym
);
3670 /* Initialize anything that needs initializing when starting to read
3671 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3679 /* Initialize anything that needs initializing when a completely new
3680 symbol file is specified (not just adding some symbols from another
3681 file, e.g. a shared library). */
3684 stabsread_new_init ()
3686 /* Empty the hash table of global syms looking for values. */
3687 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3690 /* Initialize anything that needs initializing at the same time as
3691 start_symtab() is called. */
3695 global_stabs
= NULL
; /* AIX COFF */
3696 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3697 n_this_object_header_files
= 1;
3698 type_vector_length
= 0;
3699 type_vector
= (struct type
**) 0;
3701 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3702 common_block_name
= NULL
;
3705 /* Call after end_symtab() */
3711 free ((char *) type_vector
);
3714 type_vector_length
= 0;
3715 previous_stab_code
= 0;
3719 finish_global_stabs (objfile
)
3720 struct objfile
*objfile
;
3724 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3725 free ((PTR
) global_stabs
);
3726 global_stabs
= NULL
;
3730 /* Initializer for this module */
3733 _initialize_stabsread ()
3735 undef_types_allocated
= 20;
3736 undef_types_length
= 0;
3737 undef_types
= (struct type
**)
3738 xmalloc (undef_types_allocated
* sizeof (struct type
*));