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
152 struct complaint invalid_cpp_abbrev_complaint
=
153 {"invalid C++ abbreviation `%s'", 0, 0};
155 struct complaint invalid_cpp_type_complaint
=
156 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
158 struct complaint member_fn_complaint
=
159 {"member function type missing, got '%c'", 0, 0};
161 struct complaint const_vol_complaint
=
162 {"const/volatile indicator missing, got '%c'", 0, 0};
164 struct complaint error_type_complaint
=
165 {"debug info mismatch between compiler and debugger", 0, 0};
167 struct complaint invalid_member_complaint
=
168 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
170 struct complaint range_type_base_complaint
=
171 {"base type %d of range type is not defined", 0, 0};
173 struct complaint reg_value_complaint
=
174 {"register number too large in symbol %s", 0, 0};
176 struct complaint vtbl_notfound_complaint
=
177 {"virtual function table pointer not found when defining class `%s'", 0, 0};
179 struct complaint unrecognized_cplus_name_complaint
=
180 {"Unknown C++ symbol name `%s'", 0, 0};
182 struct complaint rs6000_builtin_complaint
=
183 {"Unknown builtin type %d", 0, 0};
185 struct complaint stabs_general_complaint
=
188 /* Make a list of forward references which haven't been defined. */
190 static struct type
**undef_types
;
191 static int undef_types_allocated
;
192 static int undef_types_length
;
194 /* Check for and handle cretinous stabs symbol name continuation! */
195 #define STABS_CONTINUE(pp) \
197 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
201 /* Look up a dbx type-number pair. Return the address of the slot
202 where the type for that number-pair is stored.
203 The number-pair is in TYPENUMS.
205 This can be used for finding the type associated with that pair
206 or for associating a new type with the pair. */
209 dbx_lookup_type (typenums
)
212 register int filenum
= typenums
[0];
213 register int index
= typenums
[1];
215 register int real_filenum
;
216 register struct header_file
*f
;
219 if (filenum
== -1) /* -1,-1 is for temporary types. */
222 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
224 static struct complaint msg
= {"\
225 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
227 complain (&msg
, filenum
, index
, symnum
);
235 /* Caller wants address of address of type. We think
236 that negative (rs6k builtin) types will never appear as
237 "lvalues", (nor should they), so we stuff the real type
238 pointer into a temp, and return its address. If referenced,
239 this will do the right thing. */
240 static struct type
*temp_type
;
242 temp_type
= rs6000_builtin_type(index
);
246 /* Type is defined outside of header files.
247 Find it in this object file's type vector. */
248 if (index
>= type_vector_length
)
250 old_len
= type_vector_length
;
253 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
254 type_vector
= (struct type
**)
255 malloc (type_vector_length
* sizeof (struct type
*));
257 while (index
>= type_vector_length
)
259 type_vector_length
*= 2;
261 type_vector
= (struct type
**)
262 xrealloc ((char *) type_vector
,
263 (type_vector_length
* sizeof (struct type
*)));
264 memset (&type_vector
[old_len
], 0,
265 (type_vector_length
- old_len
) * sizeof (struct type
*));
267 return (&type_vector
[index
]);
271 real_filenum
= this_object_header_files
[filenum
];
273 if (real_filenum
>= n_header_files
)
275 struct type
*temp_type
;
276 struct type
**temp_type_p
;
278 warning ("GDB internal error: bad real_filenum");
281 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
282 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
283 *temp_type_p
= temp_type
;
287 f
= &header_files
[real_filenum
];
289 f_orig_length
= f
->length
;
290 if (index
>= f_orig_length
)
292 while (index
>= f
->length
)
296 f
->vector
= (struct type
**)
297 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
298 memset (&f
->vector
[f_orig_length
], 0,
299 (f
->length
- f_orig_length
) * sizeof (struct type
*));
301 return (&f
->vector
[index
]);
305 /* Make sure there is a type allocated for type numbers TYPENUMS
306 and return the type object.
307 This can create an empty (zeroed) type object.
308 TYPENUMS may be (-1, -1) to return a new type object that is not
309 put into the type vector, and so may not be referred to by number. */
312 dbx_alloc_type (typenums
, objfile
)
314 struct objfile
*objfile
;
316 register struct type
**type_addr
;
318 if (typenums
[0] == -1)
320 return (alloc_type (objfile
));
323 type_addr
= dbx_lookup_type (typenums
);
325 /* If we are referring to a type not known at all yet,
326 allocate an empty type for it.
327 We will fill it in later if we find out how. */
330 *type_addr
= alloc_type (objfile
);
336 /* for all the stabs in a given stab vector, build appropriate types
337 and fix their symbols in given symbol vector. */
340 patch_block_stabs (symbols
, stabs
, objfile
)
341 struct pending
*symbols
;
342 struct pending_stabs
*stabs
;
343 struct objfile
*objfile
;
353 /* for all the stab entries, find their corresponding symbols and
354 patch their types! */
356 for (ii
= 0; ii
< stabs
->count
; ++ii
)
358 name
= stabs
->stab
[ii
];
359 pp
= (char*) strchr (name
, ':');
363 pp
= (char *)strchr(pp
, ':');
365 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
368 /* On xcoff, if a global is defined and never referenced,
369 ld will remove it from the executable. There is then
370 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
371 sym
= (struct symbol
*)
372 obstack_alloc (&objfile
->symbol_obstack
,
373 sizeof (struct symbol
));
375 memset (sym
, 0, sizeof (struct symbol
));
376 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
377 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
379 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
381 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
383 /* I don't think the linker does this with functions,
384 so as far as I know this is never executed.
385 But it doesn't hurt to check. */
387 lookup_function_type (read_type (&pp
, objfile
));
391 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
393 add_symbol_to_list (sym
, &global_symbols
);
398 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
401 lookup_function_type (read_type (&pp
, objfile
));
405 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
413 /* Read a number by which a type is referred to in dbx data,
414 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
415 Just a single number N is equivalent to (0,N).
416 Return the two numbers by storing them in the vector TYPENUMS.
417 TYPENUMS will then be used as an argument to dbx_lookup_type.
419 Returns 0 for success, -1 for error. */
422 read_type_number (pp
, typenums
)
424 register int *typenums
;
430 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
431 if (nbits
!= 0) return -1;
432 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
433 if (nbits
!= 0) return -1;
438 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
439 if (nbits
!= 0) return -1;
445 /* To handle GNU C++ typename abbreviation, we need to be able to
446 fill in a type's name as soon as space for that type is allocated.
447 `type_synonym_name' is the name of the type being allocated.
448 It is cleared as soon as it is used (lest all allocated types
451 static char *type_synonym_name
;
455 define_symbol (valu
, string
, desc
, type
, objfile
)
460 struct objfile
*objfile
;
462 register struct symbol
*sym
;
463 char *p
= (char *) strchr (string
, ':');
468 /* We would like to eliminate nameless symbols, but keep their types.
469 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
470 to type 2, but, should not create a symbol to address that type. Since
471 the symbol will be nameless, there is no way any user can refer to it. */
475 /* Ignore syms with empty names. */
479 /* Ignore old-style symbols from cc -go */
489 /* If a nameless stab entry, all we need is the type, not the symbol.
490 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
491 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
493 sym
= (struct symbol
*)
494 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
495 memset (sym
, 0, sizeof (struct symbol
));
497 if (processing_gcc_compilation
)
499 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
500 number of bytes occupied by a type or object, which we ignore. */
501 SYMBOL_LINE(sym
) = desc
;
505 SYMBOL_LINE(sym
) = 0; /* unknown */
508 if (string
[0] == CPLUS_MARKER
)
510 /* Special GNU C++ names. */
514 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
515 &objfile
-> symbol_obstack
);
518 case 'v': /* $vtbl_ptr_type */
519 /* Was: SYMBOL_NAME (sym) = "vptr"; */
523 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
524 &objfile
-> symbol_obstack
);
528 /* This was an anonymous type that was never fixed up. */
532 complain (&unrecognized_cplus_name_complaint
, string
);
533 goto normal
; /* Do *something* with it */
539 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
540 SYMBOL_NAME (sym
) = (char *)
541 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
542 /* Open-coded memcpy--saves function call time. */
543 /* FIXME: Does it really? Try replacing with simple strcpy and
544 try it on an executable with a large symbol table. */
545 /* FIXME: considering that gcc can open code memcpy anyway, I
546 doubt it. xoxorich. */
548 register char *p1
= string
;
549 register char *p2
= SYMBOL_NAME (sym
);
557 /* If this symbol is from a C++ compilation, then attempt to cache the
558 demangled form for future reference. This is a typical time versus
559 space tradeoff, that was decided in favor of time because it sped up
560 C++ symbol lookups by a factor of about 20. */
562 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
566 /* Determine the type of name being defined. */
568 /* Getting GDB to correctly skip the symbol on an undefined symbol
569 descriptor and not ever dump core is a very dodgy proposition if
570 we do things this way. I say the acorn RISC machine can just
571 fix their compiler. */
572 /* The Acorn RISC machine's compiler can put out locals that don't
573 start with "234=" or "(3,4)=", so assume anything other than the
574 deftypes we know how to handle is a local. */
575 if (!strchr ("cfFGpPrStTvVXCR", *p
))
577 if (isdigit (*p
) || *p
== '(' || *p
== '-')
586 /* c is a special case, not followed by a type-number.
587 SYMBOL:c=iVALUE for an integer constant symbol.
588 SYMBOL:c=rVALUE for a floating constant symbol.
589 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
590 e.g. "b:c=e6,0" for "const b = blob1"
591 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
594 SYMBOL_CLASS (sym
) = LOC_CONST
;
595 SYMBOL_TYPE (sym
) = error_type (&p
);
596 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
597 add_symbol_to_list (sym
, &file_symbols
);
608 /* FIXME-if-picky-about-floating-accuracy: Should be using
609 target arithmetic to get the value. real.c in GCC
610 probably has the necessary code. */
612 /* FIXME: lookup_fundamental_type is a hack. We should be
613 creating a type especially for the type of float constants.
614 Problem is, what type should it be?
616 Also, what should the name of this type be? Should we
617 be using 'S' constants (see stabs.texinfo) instead? */
619 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
622 obstack_alloc (&objfile
-> symbol_obstack
,
623 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
624 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
625 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
626 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
631 /* Defining integer constants this way is kind of silly,
632 since 'e' constants allows the compiler to give not
633 only the value, but the type as well. C has at least
634 int, long, unsigned int, and long long as constant
635 types; other languages probably should have at least
636 unsigned as well as signed constants. */
638 /* We just need one int constant type for all objfiles.
639 It doesn't depend on languages or anything (arguably its
640 name should be a language-specific name for a type of
641 that size, but I'm inclined to say that if the compiler
642 wants a nice name for the type, it can use 'e'). */
643 static struct type
*int_const_type
;
645 /* Yes, this is as long as a *host* int. That is because we
647 if (int_const_type
== NULL
)
649 init_type (TYPE_CODE_INT
,
650 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
652 (struct objfile
*)NULL
);
653 SYMBOL_TYPE (sym
) = int_const_type
;
654 SYMBOL_VALUE (sym
) = atoi (p
);
655 SYMBOL_CLASS (sym
) = LOC_CONST
;
659 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
660 can be represented as integral.
661 e.g. "b:c=e6,0" for "const b = blob1"
662 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
664 SYMBOL_CLASS (sym
) = LOC_CONST
;
665 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
669 SYMBOL_TYPE (sym
) = error_type (&p
);
674 /* If the value is too big to fit in an int (perhaps because
675 it is unsigned), or something like that, we silently get
676 a bogus value. The type and everything else about it is
677 correct. Ideally, we should be using whatever we have
678 available for parsing unsigned and long long values,
680 SYMBOL_VALUE (sym
) = atoi (p
);
685 SYMBOL_CLASS (sym
) = LOC_CONST
;
686 SYMBOL_TYPE (sym
) = error_type (&p
);
689 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
690 add_symbol_to_list (sym
, &file_symbols
);
694 /* The name of a caught exception. */
695 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
696 SYMBOL_CLASS (sym
) = LOC_LABEL
;
697 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
698 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
699 add_symbol_to_list (sym
, &local_symbols
);
703 /* A static function definition. */
704 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
705 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
706 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
707 add_symbol_to_list (sym
, &file_symbols
);
708 /* fall into process_function_types. */
710 process_function_types
:
711 /* Function result types are described as the result type in stabs.
712 We need to convert this to the function-returning-type-X type
713 in GDB. E.g. "int" is converted to "function returning int". */
714 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
717 /* This code doesn't work -- it needs to realloc and can't. */
718 /* Attempt to set up to record a function prototype... */
719 struct type
*new = alloc_type (objfile
);
721 /* Generate a template for the type of this function. The
722 types of the arguments will be added as we read the symbol
724 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
725 SYMBOL_TYPE(sym
) = new;
726 TYPE_OBJFILE (new) = objfile
;
727 in_function_type
= new;
729 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
732 /* fall into process_prototype_types */
734 process_prototype_types
:
735 /* Sun acc puts declared types of arguments here. We don't care
736 about their actual types (FIXME -- we should remember the whole
737 function prototype), but the list may define some new types
738 that we have to remember, so we must scan it now. */
741 read_type (&p
, objfile
);
746 /* A global function definition. */
747 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
748 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
749 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
750 add_symbol_to_list (sym
, &global_symbols
);
751 goto process_function_types
;
754 /* For a class G (global) symbol, it appears that the
755 value is not correct. It is necessary to search for the
756 corresponding linker definition to find the value.
757 These definitions appear at the end of the namelist. */
758 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
759 i
= hashname (SYMBOL_NAME (sym
));
760 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
761 global_sym_chain
[i
] = sym
;
762 SYMBOL_CLASS (sym
) = LOC_STATIC
;
763 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
764 add_symbol_to_list (sym
, &global_symbols
);
767 /* This case is faked by a conditional above,
768 when there is no code letter in the dbx data.
769 Dbx data never actually contains 'l'. */
771 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
772 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
773 SYMBOL_VALUE (sym
) = valu
;
774 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
775 add_symbol_to_list (sym
, &local_symbols
);
780 /* pF is a two-letter code that means a function parameter in Fortran.
781 The type-number specifies the type of the return value.
782 Translate it into a pointer-to-function type. */
786 = lookup_pointer_type
787 (lookup_function_type (read_type (&p
, objfile
)));
790 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
792 /* Normally this is a parameter, a LOC_ARG. On the i960, it
793 can also be a LOC_LOCAL_ARG depending on symbol type. */
794 #ifndef DBX_PARM_SYMBOL_CLASS
795 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
798 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
799 SYMBOL_VALUE (sym
) = valu
;
800 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
802 /* This doesn't work yet. */
803 add_param_to_type (&in_function_type
, sym
);
805 add_symbol_to_list (sym
, &local_symbols
);
807 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
808 /* On little-endian machines, this crud is never necessary, and,
809 if the extra bytes contain garbage, is harmful. */
811 #else /* Big endian. */
812 /* If it's gcc-compiled, if it says `short', believe it. */
813 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
816 #if !BELIEVE_PCC_PROMOTION
818 /* This is the signed type which arguments get promoted to. */
819 static struct type
*pcc_promotion_type
;
820 /* This is the unsigned type which arguments get promoted to. */
821 static struct type
*pcc_unsigned_promotion_type
;
823 /* Call it "int" because this is mainly C lossage. */
824 if (pcc_promotion_type
== NULL
)
826 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
829 if (pcc_unsigned_promotion_type
== NULL
)
830 pcc_unsigned_promotion_type
=
831 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
832 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
834 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
835 /* This macro is defined on machines (e.g. sparc) where
836 we should believe the type of a PCC 'short' argument,
837 but shouldn't believe the address (the address is
838 the address of the corresponding int).
840 My guess is that this correction, as opposed to changing
841 the parameter to an 'int' (as done below, for PCC
842 on most machines), is the right thing to do
843 on all machines, but I don't want to risk breaking
844 something that already works. On most PCC machines,
845 the sparc problem doesn't come up because the calling
846 function has to zero the top bytes (not knowing whether
847 the called function wants an int or a short), so there
848 is little practical difference between an int and a short
849 (except perhaps what happens when the GDB user types
850 "print short_arg = 0x10000;").
852 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
853 actually produces the correct address (we don't need to fix it
854 up). I made this code adapt so that it will offset the symbol
855 if it was pointing at an int-aligned location and not
856 otherwise. This way you can use the same gdb for 4.0.x and
859 If the parameter is shorter than an int, and is integral
860 (e.g. char, short, or unsigned equivalent), and is claimed to
861 be passed on an integer boundary, don't believe it! Offset the
862 parameter's address to the tail-end of that integer. */
864 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
865 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
866 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
868 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
869 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
873 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
875 /* If PCC says a parameter is a short or a char,
876 it is really an int. */
877 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
878 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
881 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
882 ? pcc_unsigned_promotion_type
883 : pcc_promotion_type
;
887 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
889 #endif /* !BELIEVE_PCC_PROMOTION. */
890 #endif /* Big endian. */
893 /* acc seems to use P to delare the prototypes of functions that
894 are referenced by this file. gdb is not prepared to deal
895 with this extra information. FIXME, it ought to. */
898 read_type (&p
, objfile
);
899 goto process_prototype_types
;
904 /* Parameter which is in a register. */
905 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
906 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
907 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
908 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
910 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
911 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
913 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
914 add_symbol_to_list (sym
, &local_symbols
);
918 /* Register variable (either global or local). */
919 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
920 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
921 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
922 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
924 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
925 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
927 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
930 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
931 name to represent an argument passed in a register.
932 GCC uses 'P' for the same case. So if we find such a symbol pair
933 we combine it into one 'P' symbol.
934 Note that this code illegally combines
935 main(argc) int argc; { register int argc = 1; }
936 but this case is considered pathological and causes a warning
937 from a decent compiler. */
939 && local_symbols
->nsyms
> 0)
941 struct symbol
*prev_sym
;
942 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
943 if (SYMBOL_CLASS (prev_sym
) == LOC_ARG
944 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
946 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
947 /* Use the type from the LOC_REGISTER; that is the type
948 that is actually in that register. */
949 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
950 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
955 add_symbol_to_list (sym
, &local_symbols
);
958 add_symbol_to_list (sym
, &file_symbols
);
962 /* Static symbol at top level of file */
963 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
964 SYMBOL_CLASS (sym
) = LOC_STATIC
;
965 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
966 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
967 add_symbol_to_list (sym
, &file_symbols
);
971 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
973 /* For a nameless type, we don't want a create a symbol, thus we
974 did not use `sym'. Return without further processing. */
975 if (nameless
) return NULL
;
977 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
978 SYMBOL_VALUE (sym
) = valu
;
979 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
980 /* C++ vagaries: we may have a type which is derived from
981 a base type which did not have its name defined when the
982 derived class was output. We fill in the derived class's
983 base part member's name here in that case. */
984 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
985 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
986 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
987 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
990 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
991 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
992 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
993 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
996 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
998 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
999 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1001 /* If we are giving a name to a type such as "pointer to
1002 foo" or "function returning foo", we better not set
1003 the TYPE_NAME. If the program contains "typedef char
1004 *caddr_t;", we don't want all variables of type char
1005 * to print as caddr_t. This is not just a
1006 consequence of GDB's type management; PCC and GCC (at
1007 least through version 2.4) both output variables of
1008 either type char * or caddr_t with the type number
1009 defined in the 't' symbol for caddr_t. If a future
1010 compiler cleans this up it GDB is not ready for it
1011 yet, but if it becomes ready we somehow need to
1012 disable this check (without breaking the PCC/GCC2.4
1017 Fortunately, this check seems not to be necessary
1018 for anything except pointers or functions. */
1021 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1024 add_symbol_to_list (sym
, &file_symbols
);
1028 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1029 by 't' which means we are typedef'ing it as well. */
1030 synonym
= *p
== 't';
1035 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1036 strlen (SYMBOL_NAME (sym
)),
1037 &objfile
-> symbol_obstack
);
1039 /* The semantics of C++ state that "struct foo { ... }" also defines
1040 a typedef for "foo". Unfortunately, cfront never makes the typedef
1041 when translating C++ into C. We make the typedef here so that
1042 "ptype foo" works as expected for cfront translated code. */
1043 else if (current_subfile
->language
== language_cplus
)
1046 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1047 strlen (SYMBOL_NAME (sym
)),
1048 &objfile
-> symbol_obstack
);
1051 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1053 /* For a nameless type, we don't want a create a symbol, thus we
1054 did not use `sym'. Return without further processing. */
1055 if (nameless
) return NULL
;
1057 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1058 SYMBOL_VALUE (sym
) = valu
;
1059 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1060 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1061 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1062 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1063 add_symbol_to_list (sym
, &file_symbols
);
1067 /* Clone the sym and then modify it. */
1068 register struct symbol
*typedef_sym
= (struct symbol
*)
1069 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1070 *typedef_sym
= *sym
;
1071 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1072 SYMBOL_VALUE (typedef_sym
) = valu
;
1073 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1074 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1075 TYPE_NAME (SYMBOL_TYPE (sym
))
1076 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1077 add_symbol_to_list (typedef_sym
, &file_symbols
);
1082 /* Static symbol of local scope */
1083 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1084 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1085 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1086 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1087 add_symbol_to_list (sym
, &local_symbols
);
1091 /* Reference parameter */
1092 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1093 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1094 SYMBOL_VALUE (sym
) = valu
;
1095 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1096 add_symbol_to_list (sym
, &local_symbols
);
1100 /* This is used by Sun FORTRAN for "function result value".
1101 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1102 that Pascal uses it too, but when I tried it Pascal used
1103 "x:3" (local symbol) instead. */
1104 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1105 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1106 SYMBOL_VALUE (sym
) = valu
;
1107 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1108 add_symbol_to_list (sym
, &local_symbols
);
1112 SYMBOL_TYPE (sym
) = error_type (&p
);
1113 SYMBOL_CLASS (sym
) = LOC_CONST
;
1114 SYMBOL_VALUE (sym
) = 0;
1115 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1116 add_symbol_to_list (sym
, &file_symbols
);
1120 /* When passing structures to a function, some systems sometimes pass
1121 the address in a register, not the structure itself.
1123 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1124 to LOC_REGPARM_ADDR for structures and unions. */
1126 #if !defined (REG_STRUCT_HAS_ADDR)
1127 #define REG_STRUCT_HAS_ADDR(gcc_p) 0
1130 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1131 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
)
1132 && ( (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1133 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1134 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1140 /* Skip rest of this symbol and return an error type.
1142 General notes on error recovery: error_type always skips to the
1143 end of the symbol (modulo cretinous dbx symbol name continuation).
1144 Thus code like this:
1146 if (*(*pp)++ != ';')
1147 return error_type (pp);
1149 is wrong because if *pp starts out pointing at '\0' (typically as the
1150 result of an earlier error), it will be incremented to point to the
1151 start of the next symbol, which might produce strange results, at least
1152 if you run off the end of the string table. Instead use
1155 return error_type (pp);
1161 foo = error_type (pp);
1165 And in case it isn't obvious, the point of all this hair is so the compiler
1166 can define new types and new syntaxes, and old versions of the
1167 debugger will be able to read the new symbol tables. */
1169 static struct type
*
1173 complain (&error_type_complaint
);
1176 /* Skip to end of symbol. */
1177 while (**pp
!= '\0')
1182 /* Check for and handle cretinous dbx symbol name continuation! */
1183 if ((*pp
)[-1] == '\\')
1185 *pp
= next_symbol_text ();
1192 return (builtin_type_error
);
1196 /* Read type information or a type definition; return the type. Even
1197 though this routine accepts either type information or a type
1198 definition, the distinction is relevant--some parts of stabsread.c
1199 assume that type information starts with a digit, '-', or '(' in
1200 deciding whether to call read_type. */
1203 read_type (pp
, objfile
)
1205 struct objfile
*objfile
;
1207 register struct type
*type
= 0;
1211 char type_descriptor
;
1213 /* Size in bits of type if specified by a type attribute, or -1 if
1214 there is no size attribute. */
1217 /* Used to distinguish string and bitstring from char-array and set. */
1220 /* Read type number if present. The type number may be omitted.
1221 for instance in a two-dimensional array declared with type
1222 "ar1;1;10;ar1;1;10;4". */
1223 if ((**pp
>= '0' && **pp
<= '9')
1227 if (read_type_number (pp
, typenums
) != 0)
1228 return error_type (pp
);
1230 /* Type is not being defined here. Either it already exists,
1231 or this is a forward reference to it. dbx_alloc_type handles
1234 return dbx_alloc_type (typenums
, objfile
);
1236 /* Type is being defined here. */
1243 /* It might be a type attribute or a member type. */
1244 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1249 /* Type attributes. */
1252 /* Skip to the semicolon. */
1253 while (*p
!= ';' && *p
!= '\0')
1257 return error_type (pp
);
1259 /* Skip the semicolon. */
1265 type_size
= atoi (attr
+ 1);
1275 /* Ignore unrecognized type attributes, so future compilers
1276 can invent new ones. */
1281 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1286 /* 'typenums=' not present, type is anonymous. Read and return
1287 the definition, but don't put it in the type vector. */
1288 typenums
[0] = typenums
[1] = -1;
1292 type_descriptor
= (*pp
)[-1];
1293 switch (type_descriptor
)
1297 enum type_code code
;
1299 /* Used to index through file_symbols. */
1300 struct pending
*ppt
;
1303 /* Name including "struct", etc. */
1307 char *from
, *to
, *p
;
1309 /* Set the type code according to the following letter. */
1313 code
= TYPE_CODE_STRUCT
;
1316 code
= TYPE_CODE_UNION
;
1319 code
= TYPE_CODE_ENUM
;
1323 /* Complain and keep going, so compilers can invent new
1324 cross-reference types. */
1325 static struct complaint msg
=
1326 {"Unrecognized cross-reference type `%c'", 0, 0};
1327 complain (&msg
, (*pp
)[0]);
1328 code
= TYPE_CODE_STRUCT
;
1333 p
= strchr(*pp
, ':');
1335 return error_type (pp
);
1341 return error_type (pp
);
1344 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1346 /* Copy the name. */
1352 /* Set the pointer ahead of the name which we just read, and
1357 /* Now check to see whether the type has already been
1358 declared. This was written for arrays of cross-referenced
1359 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1360 sure it is not necessary anymore. But it might be a good
1361 idea, to save a little memory. */
1363 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1364 for (i
= 0; i
< ppt
->nsyms
; i
++)
1366 struct symbol
*sym
= ppt
->symbol
[i
];
1368 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1369 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1370 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1371 && STREQ (SYMBOL_NAME (sym
), type_name
))
1373 obstack_free (&objfile
-> type_obstack
, type_name
);
1374 type
= SYMBOL_TYPE (sym
);
1379 /* Didn't find the type to which this refers, so we must
1380 be dealing with a forward reference. Allocate a type
1381 structure for it, and keep track of it so we can
1382 fill in the rest of the fields when we get the full
1384 type
= dbx_alloc_type (typenums
, objfile
);
1385 TYPE_CODE (type
) = code
;
1386 TYPE_TAG_NAME (type
) = type_name
;
1387 INIT_CPLUS_SPECIFIC(type
);
1388 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1390 add_undefined_type (type
);
1394 case '-': /* RS/6000 built-in type */
1408 if (read_type_number (pp
, xtypenums
) != 0)
1409 return error_type (pp
);
1411 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1412 /* It's being defined as itself. That means it is "void". */
1413 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
1416 struct type
*xtype
= *dbx_lookup_type (xtypenums
);
1418 /* This can happen if we had '-' followed by a garbage character,
1421 return error_type (pp
);
1423 /* The type is being defined to another type. So we copy the type.
1424 This loses if we copy a C++ class and so we lose track of how
1425 the names are mangled (but g++ doesn't output stabs like this
1428 type
= alloc_type (objfile
);
1429 memcpy (type
, xtype
, sizeof (struct type
));
1431 /* The idea behind clearing the names is that the only purpose
1432 for defining a type to another type is so that the name of
1433 one can be different. So we probably don't need to worry much
1434 about the case where the compiler doesn't give a name to the
1436 TYPE_NAME (type
) = NULL
;
1437 TYPE_TAG_NAME (type
) = NULL
;
1439 if (typenums
[0] != -1)
1440 *dbx_lookup_type (typenums
) = type
;
1443 /* In the following types, we must be sure to overwrite any existing
1444 type that the typenums refer to, rather than allocating a new one
1445 and making the typenums point to the new one. This is because there
1446 may already be pointers to the existing type (if it had been
1447 forward-referenced), and we must change it to a pointer, function,
1448 reference, or whatever, *in-place*. */
1451 type1
= read_type (pp
, objfile
);
1452 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1455 case '&': /* Reference to another type */
1456 type1
= read_type (pp
, objfile
);
1457 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1460 case 'f': /* Function returning another type */
1461 type1
= read_type (pp
, objfile
);
1462 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1465 case 'k': /* Const qualifier on some type (Sun) */
1466 type
= read_type (pp
, objfile
);
1467 /* FIXME! For now, we ignore const and volatile qualifiers. */
1470 case 'B': /* Volatile qual on some type (Sun) */
1471 type
= read_type (pp
, objfile
);
1472 /* FIXME! For now, we ignore const and volatile qualifiers. */
1475 /* FIXME -- we should be doing smash_to_XXX types here. */
1476 case '@': /* Member (class & variable) type */
1478 struct type
*domain
= read_type (pp
, objfile
);
1479 struct type
*memtype
;
1482 /* Invalid member type data format. */
1483 return error_type (pp
);
1486 memtype
= read_type (pp
, objfile
);
1487 type
= dbx_alloc_type (typenums
, objfile
);
1488 smash_to_member_type (type
, domain
, memtype
);
1492 case '#': /* Method (class & fn) type */
1493 if ((*pp
)[0] == '#')
1495 /* We'll get the parameter types from the name. */
1496 struct type
*return_type
;
1499 return_type
= read_type (pp
, objfile
);
1500 if (*(*pp
)++ != ';')
1501 complain (&invalid_member_complaint
, symnum
);
1502 type
= allocate_stub_method (return_type
);
1503 if (typenums
[0] != -1)
1504 *dbx_lookup_type (typenums
) = type
;
1508 struct type
*domain
= read_type (pp
, objfile
);
1509 struct type
*return_type
;
1513 /* Invalid member type data format. */
1514 return error_type (pp
);
1518 return_type
= read_type (pp
, objfile
);
1519 args
= read_args (pp
, ';', objfile
);
1520 type
= dbx_alloc_type (typenums
, objfile
);
1521 smash_to_method_type (type
, domain
, return_type
, args
);
1525 case 'r': /* Range type */
1526 type
= read_range_type (pp
, typenums
, objfile
);
1527 if (typenums
[0] != -1)
1528 *dbx_lookup_type (typenums
) = type
;
1531 case 'b': /* Sun ACC builtin int type */
1532 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1533 if (typenums
[0] != -1)
1534 *dbx_lookup_type (typenums
) = type
;
1537 case 'R': /* Sun ACC builtin float type */
1538 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1539 if (typenums
[0] != -1)
1540 *dbx_lookup_type (typenums
) = type
;
1543 case 'e': /* Enumeration type */
1544 type
= dbx_alloc_type (typenums
, objfile
);
1545 type
= read_enum_type (pp
, type
, objfile
);
1546 if (typenums
[0] != -1)
1547 *dbx_lookup_type (typenums
) = type
;
1550 case 's': /* Struct type */
1551 case 'u': /* Union type */
1552 type
= dbx_alloc_type (typenums
, objfile
);
1553 if (!TYPE_NAME (type
))
1555 TYPE_NAME (type
) = type_synonym_name
;
1557 type_synonym_name
= NULL
;
1558 switch (type_descriptor
)
1561 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1564 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1567 type
= read_struct_type (pp
, type
, objfile
);
1570 case 'a': /* Array type */
1572 return error_type (pp
);
1575 type
= dbx_alloc_type (typenums
, objfile
);
1576 type
= read_array_type (pp
, type
, objfile
);
1578 TYPE_CODE (type
) = TYPE_CODE_STRING
;
1582 type1
= read_type (pp
, objfile
);
1583 type
= create_set_type ((struct type
*) NULL
, type1
);
1585 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
1586 if (typenums
[0] != -1)
1587 *dbx_lookup_type (typenums
) = type
;
1591 --*pp
; /* Go back to the symbol in error */
1592 /* Particularly important if it was \0! */
1593 return error_type (pp
);
1598 warning ("GDB internal error, type is NULL in stabsread.c\n");
1599 return error_type (pp
);
1602 /* Size specified in a type attribute overrides any other size. */
1603 if (type_size
!= -1)
1604 TYPE_LENGTH (type
) = type_size
/ TARGET_CHAR_BIT
;
1609 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1610 Return the proper type node for a given builtin type number. */
1612 static struct type
*
1613 rs6000_builtin_type (typenum
)
1616 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1617 #define NUMBER_RECOGNIZED 30
1618 /* This includes an empty slot for type number -0. */
1619 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1620 struct type
*rettype
= NULL
;
1622 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1624 complain (&rs6000_builtin_complaint
, typenum
);
1625 return builtin_type_error
;
1627 if (negative_types
[-typenum
] != NULL
)
1628 return negative_types
[-typenum
];
1630 #if TARGET_CHAR_BIT != 8
1631 #error This code wrong for TARGET_CHAR_BIT not 8
1632 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1633 that if that ever becomes not true, the correct fix will be to
1634 make the size in the struct type to be in bits, not in units of
1641 /* The size of this and all the other types are fixed, defined
1642 by the debugging format. If there is a type called "int" which
1643 is other than 32 bits, then it should use a new negative type
1644 number (or avoid negative type numbers for that case).
1645 See stabs.texinfo. */
1646 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1649 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1652 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1655 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1658 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1659 "unsigned char", NULL
);
1662 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1665 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1666 "unsigned short", NULL
);
1669 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1670 "unsigned int", NULL
);
1673 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1676 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1677 "unsigned long", NULL
);
1680 rettype
= init_type (TYPE_CODE_VOID
, 0, 0, "void", NULL
);
1683 /* IEEE single precision (32 bit). */
1684 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1687 /* IEEE double precision (64 bit). */
1688 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1691 /* This is an IEEE double on the RS/6000, and different machines with
1692 different sizes for "long double" should use different negative
1693 type numbers. See stabs.texinfo. */
1694 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1697 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1700 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1703 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1706 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1709 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1712 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1716 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1720 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1724 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1728 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1732 /* Complex type consisting of two IEEE single precision values. */
1733 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1736 /* Complex type consisting of two IEEE double precision values. */
1737 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1740 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1743 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1746 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1749 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1752 negative_types
[-typenum
] = rettype
;
1756 /* This page contains subroutines of read_type. */
1758 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1759 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1760 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1761 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1763 /* Read member function stabs info for C++ classes. The form of each member
1766 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1768 An example with two member functions is:
1770 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1772 For the case of overloaded operators, the format is op$::*.funcs, where
1773 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1774 name (such as `+=') and `.' marks the end of the operator name.
1776 Returns 1 for success, 0 for failure. */
1779 read_member_functions (fip
, pp
, type
, objfile
)
1780 struct field_info
*fip
;
1783 struct objfile
*objfile
;
1787 /* Total number of member functions defined in this class. If the class
1788 defines two `f' functions, and one `g' function, then this will have
1790 int total_length
= 0;
1794 struct next_fnfield
*next
;
1795 struct fn_field fn_field
;
1797 struct type
*look_ahead_type
;
1798 struct next_fnfieldlist
*new_fnlist
;
1799 struct next_fnfield
*new_sublist
;
1803 /* Process each list until we find something that is not a member function
1804 or find the end of the functions. */
1808 /* We should be positioned at the start of the function name.
1809 Scan forward to find the first ':' and if it is not the
1810 first of a "::" delimiter, then this is not a member function. */
1822 look_ahead_type
= NULL
;
1825 new_fnlist
= (struct next_fnfieldlist
*)
1826 xmalloc (sizeof (struct next_fnfieldlist
));
1827 make_cleanup (free
, new_fnlist
);
1828 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1830 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1832 /* This is a completely wierd case. In order to stuff in the
1833 names that might contain colons (the usual name delimiter),
1834 Mike Tiemann defined a different name format which is
1835 signalled if the identifier is "op$". In that case, the
1836 format is "op$::XXXX." where XXXX is the name. This is
1837 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1838 /* This lets the user type "break operator+".
1839 We could just put in "+" as the name, but that wouldn't
1841 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1842 char *o
= opname
+ 3;
1844 /* Skip past '::'. */
1847 STABS_CONTINUE (pp
);
1853 main_fn_name
= savestring (opname
, o
- opname
);
1859 main_fn_name
= savestring (*pp
, p
- *pp
);
1860 /* Skip past '::'. */
1863 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1868 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1869 make_cleanup (free
, new_sublist
);
1870 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1872 /* Check for and handle cretinous dbx symbol name continuation! */
1873 if (look_ahead_type
== NULL
)
1876 STABS_CONTINUE (pp
);
1878 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1881 /* Invalid symtab info for member function. */
1887 /* g++ version 1 kludge */
1888 new_sublist
-> fn_field
.type
= look_ahead_type
;
1889 look_ahead_type
= NULL
;
1899 /* If this is just a stub, then we don't have the real name here. */
1901 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1903 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
1904 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
1905 new_sublist
-> fn_field
.is_stub
= 1;
1907 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1910 /* Set this member function's visibility fields. */
1913 case VISIBILITY_PRIVATE
:
1914 new_sublist
-> fn_field
.is_private
= 1;
1916 case VISIBILITY_PROTECTED
:
1917 new_sublist
-> fn_field
.is_protected
= 1;
1921 STABS_CONTINUE (pp
);
1924 case 'A': /* Normal functions. */
1925 new_sublist
-> fn_field
.is_const
= 0;
1926 new_sublist
-> fn_field
.is_volatile
= 0;
1929 case 'B': /* `const' member functions. */
1930 new_sublist
-> fn_field
.is_const
= 1;
1931 new_sublist
-> fn_field
.is_volatile
= 0;
1934 case 'C': /* `volatile' member function. */
1935 new_sublist
-> fn_field
.is_const
= 0;
1936 new_sublist
-> fn_field
.is_volatile
= 1;
1939 case 'D': /* `const volatile' member function. */
1940 new_sublist
-> fn_field
.is_const
= 1;
1941 new_sublist
-> fn_field
.is_volatile
= 1;
1944 case '*': /* File compiled with g++ version 1 -- no info */
1949 complain (&const_vol_complaint
, **pp
);
1958 /* virtual member function, followed by index.
1959 The sign bit is set to distinguish pointers-to-methods
1960 from virtual function indicies. Since the array is
1961 in words, the quantity must be shifted left by 1
1962 on 16 bit machine, and by 2 on 32 bit machine, forcing
1963 the sign bit out, and usable as a valid index into
1964 the array. Remove the sign bit here. */
1965 new_sublist
-> fn_field
.voffset
=
1966 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
1970 STABS_CONTINUE (pp
);
1971 if (**pp
== ';' || **pp
== '\0')
1973 /* Must be g++ version 1. */
1974 new_sublist
-> fn_field
.fcontext
= 0;
1978 /* Figure out from whence this virtual function came.
1979 It may belong to virtual function table of
1980 one of its baseclasses. */
1981 look_ahead_type
= read_type (pp
, objfile
);
1984 /* g++ version 1 overloaded methods. */
1988 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1997 look_ahead_type
= NULL
;
2003 /* static member function. */
2004 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2005 if (strncmp (new_sublist
-> fn_field
.physname
,
2006 main_fn_name
, strlen (main_fn_name
)))
2008 new_sublist
-> fn_field
.is_stub
= 1;
2014 complain (&member_fn_complaint
, (*pp
)[-1]);
2015 /* Fall through into normal member function. */
2018 /* normal member function. */
2019 new_sublist
-> fn_field
.voffset
= 0;
2020 new_sublist
-> fn_field
.fcontext
= 0;
2024 new_sublist
-> next
= sublist
;
2025 sublist
= new_sublist
;
2027 STABS_CONTINUE (pp
);
2029 while (**pp
!= ';' && **pp
!= '\0');
2033 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2034 obstack_alloc (&objfile
-> type_obstack
,
2035 sizeof (struct fn_field
) * length
);
2036 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2037 sizeof (struct fn_field
) * length
);
2038 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2040 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2043 new_fnlist
-> fn_fieldlist
.length
= length
;
2044 new_fnlist
-> next
= fip
-> fnlist
;
2045 fip
-> fnlist
= new_fnlist
;
2047 total_length
+= length
;
2048 STABS_CONTINUE (pp
);
2053 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2054 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2055 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2056 memset (TYPE_FN_FIELDLISTS (type
), 0,
2057 sizeof (struct fn_fieldlist
) * nfn_fields
);
2058 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2059 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2065 /* Special GNU C++ name.
2067 Returns 1 for success, 0 for failure. "failure" means that we can't
2068 keep parsing and it's time for error_type(). */
2071 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2072 struct field_info
*fip
;
2075 struct objfile
*objfile
;
2080 struct type
*context
;
2090 /* At this point, *pp points to something like "22:23=*22...",
2091 where the type number before the ':' is the "context" and
2092 everything after is a regular type definition. Lookup the
2093 type, find it's name, and construct the field name. */
2095 context
= read_type (pp
, objfile
);
2099 case 'f': /* $vf -- a virtual function table pointer */
2100 fip
->list
->field
.name
=
2101 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2104 case 'b': /* $vb -- a virtual bsomethingorother */
2105 name
= type_name_no_tag (context
);
2108 complain (&invalid_cpp_type_complaint
, symnum
);
2111 fip
->list
->field
.name
=
2112 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2116 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2117 fip
->list
->field
.name
=
2118 obconcat (&objfile
->type_obstack
,
2119 "INVALID_CPLUSPLUS_ABBREV", "", "");
2123 /* At this point, *pp points to the ':'. Skip it and read the
2129 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2132 fip
->list
->field
.type
= read_type (pp
, objfile
);
2134 (*pp
)++; /* Skip the comma. */
2140 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2144 /* This field is unpacked. */
2145 fip
->list
->field
.bitsize
= 0;
2146 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2150 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2151 /* We have no idea what syntax an unrecognized abbrev would have, so
2152 better return 0. If we returned 1, we would need to at least advance
2153 *pp to avoid an infinite loop. */
2160 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2161 struct field_info
*fip
;
2165 struct objfile
*objfile
;
2167 fip
-> list
-> field
.name
=
2168 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2171 /* This means we have a visibility for a field coming. */
2175 fip
-> list
-> visibility
= *(*pp
)++;
2179 /* normal dbx-style format, no explicit visibility */
2180 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2183 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2188 /* Possible future hook for nested types. */
2191 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2197 /* Static class member. */
2198 fip
-> list
-> field
.bitpos
= (long) -1;
2204 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2208 else if (**pp
!= ',')
2210 /* Bad structure-type format. */
2211 complain (&stabs_general_complaint
, "bad structure-type format");
2215 (*pp
)++; /* Skip the comma. */
2219 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2222 complain (&stabs_general_complaint
, "bad structure-type format");
2225 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2228 complain (&stabs_general_complaint
, "bad structure-type format");
2233 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2235 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2236 it is a field which has been optimized out. The correct stab for
2237 this case is to use VISIBILITY_IGNORE, but that is a recent
2238 invention. (2) It is a 0-size array. For example
2239 union { int num; char str[0]; } foo. Printing "<no value>" for
2240 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2241 will continue to work, and a 0-size array as a whole doesn't
2242 have any contents to print.
2244 I suspect this probably could also happen with gcc -gstabs (not
2245 -gstabs+) for static fields, and perhaps other C++ extensions.
2246 Hopefully few people use -gstabs with gdb, since it is intended
2247 for dbx compatibility. */
2249 /* Ignore this field. */
2250 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2254 /* Detect an unpacked field and mark it as such.
2255 dbx gives a bit size for all fields.
2256 Note that forward refs cannot be packed,
2257 and treat enums as if they had the width of ints. */
2259 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2260 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2262 fip
-> list
-> field
.bitsize
= 0;
2264 if ((fip
-> list
-> field
.bitsize
2265 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2266 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2267 && (fip
-> list
-> field
.bitsize
2272 fip
-> list
-> field
.bitpos
% 8 == 0)
2274 fip
-> list
-> field
.bitsize
= 0;
2280 /* Read struct or class data fields. They have the form:
2282 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2284 At the end, we see a semicolon instead of a field.
2286 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2289 The optional VISIBILITY is one of:
2291 '/0' (VISIBILITY_PRIVATE)
2292 '/1' (VISIBILITY_PROTECTED)
2293 '/2' (VISIBILITY_PUBLIC)
2294 '/9' (VISIBILITY_IGNORE)
2296 or nothing, for C style fields with public visibility.
2298 Returns 1 for success, 0 for failure. */
2301 read_struct_fields (fip
, pp
, type
, objfile
)
2302 struct field_info
*fip
;
2305 struct objfile
*objfile
;
2308 struct nextfield
*new;
2310 /* We better set p right now, in case there are no fields at all... */
2314 /* Read each data member type until we find the terminating ';' at the end of
2315 the data member list, or break for some other reason such as finding the
2316 start of the member function list. */
2320 STABS_CONTINUE (pp
);
2321 /* Get space to record the next field's data. */
2322 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2323 make_cleanup (free
, new);
2324 memset (new, 0, sizeof (struct nextfield
));
2325 new -> next
= fip
-> list
;
2328 /* Get the field name. */
2331 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2332 unless the CPLUS_MARKER is followed by an underscore, in
2333 which case it is just the name of an anonymous type, which we
2334 should handle like any other type name. We accept either '$'
2335 or '.', because a field name can never contain one of these
2336 characters except as a CPLUS_MARKER (we probably should be
2337 doing that in most parts of GDB). */
2339 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2341 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2346 /* Look for the ':' that separates the field name from the field
2347 values. Data members are delimited by a single ':', while member
2348 functions are delimited by a pair of ':'s. When we hit the member
2349 functions (if any), terminate scan loop and return. */
2351 while (*p
!= ':' && *p
!= '\0')
2358 /* Check to see if we have hit the member functions yet. */
2363 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2365 if (p
[0] == ':' && p
[1] == ':')
2367 /* chill the list of fields: the last entry (at the head) is a
2368 partially constructed entry which we now scrub. */
2369 fip
-> list
= fip
-> list
-> next
;
2374 /* The stabs for C++ derived classes contain baseclass information which
2375 is marked by a '!' character after the total size. This function is
2376 called when we encounter the baseclass marker, and slurps up all the
2377 baseclass information.
2379 Immediately following the '!' marker is the number of base classes that
2380 the class is derived from, followed by information for each base class.
2381 For each base class, there are two visibility specifiers, a bit offset
2382 to the base class information within the derived class, a reference to
2383 the type for the base class, and a terminating semicolon.
2385 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2387 Baseclass information marker __________________|| | | | | | |
2388 Number of baseclasses __________________________| | | | | | |
2389 Visibility specifiers (2) ________________________| | | | | |
2390 Offset in bits from start of class _________________| | | | |
2391 Type number for base class ___________________________| | | |
2392 Visibility specifiers (2) _______________________________| | |
2393 Offset in bits from start of class ________________________| |
2394 Type number of base class ____________________________________|
2396 Return 1 for success, 0 for (error-type-inducing) failure. */
2399 read_baseclasses (fip
, pp
, type
, objfile
)
2400 struct field_info
*fip
;
2403 struct objfile
*objfile
;
2406 struct nextfield
*new;
2414 /* Skip the '!' baseclass information marker. */
2418 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2421 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2427 /* Some stupid compilers have trouble with the following, so break
2428 it up into simpler expressions. */
2429 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2430 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2433 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2436 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2437 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2441 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2443 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2445 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2446 make_cleanup (free
, new);
2447 memset (new, 0, sizeof (struct nextfield
));
2448 new -> next
= fip
-> list
;
2450 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2452 STABS_CONTINUE (pp
);
2456 /* Nothing to do. */
2459 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2462 /* Unknown character. Complain and treat it as non-virtual. */
2464 static struct complaint msg
= {
2465 "Unknown virtual character `%c' for baseclass", 0, 0};
2466 complain (&msg
, **pp
);
2471 new -> visibility
= *(*pp
)++;
2472 switch (new -> visibility
)
2474 case VISIBILITY_PRIVATE
:
2475 case VISIBILITY_PROTECTED
:
2476 case VISIBILITY_PUBLIC
:
2479 /* Bad visibility format. Complain and treat it as
2482 static struct complaint msg
= {
2483 "Unknown visibility `%c' for baseclass", 0, 0};
2484 complain (&msg
, new -> visibility
);
2485 new -> visibility
= VISIBILITY_PUBLIC
;
2492 /* The remaining value is the bit offset of the portion of the object
2493 corresponding to this baseclass. Always zero in the absence of
2494 multiple inheritance. */
2496 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2501 /* The last piece of baseclass information is the type of the
2502 base class. Read it, and remember it's type name as this
2505 new -> field
.type
= read_type (pp
, objfile
);
2506 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2508 /* skip trailing ';' and bump count of number of fields seen */
2517 /* The tail end of stabs for C++ classes that contain a virtual function
2518 pointer contains a tilde, a %, and a type number.
2519 The type number refers to the base class (possibly this class itself) which
2520 contains the vtable pointer for the current class.
2522 This function is called when we have parsed all the method declarations,
2523 so we can look for the vptr base class info. */
2526 read_tilde_fields (fip
, pp
, type
, objfile
)
2527 struct field_info
*fip
;
2530 struct objfile
*objfile
;
2534 STABS_CONTINUE (pp
);
2536 /* If we are positioned at a ';', then skip it. */
2546 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2548 /* Obsolete flags that used to indicate the presence
2549 of constructors and/or destructors. */
2553 /* Read either a '%' or the final ';'. */
2554 if (*(*pp
)++ == '%')
2556 /* The next number is the type number of the base class
2557 (possibly our own class) which supplies the vtable for
2558 this class. Parse it out, and search that class to find
2559 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2560 and TYPE_VPTR_FIELDNO. */
2565 t
= read_type (pp
, objfile
);
2567 while (*p
!= '\0' && *p
!= ';')
2573 /* Premature end of symbol. */
2577 TYPE_VPTR_BASETYPE (type
) = t
;
2578 if (type
== t
) /* Our own class provides vtbl ptr */
2580 for (i
= TYPE_NFIELDS (t
) - 1;
2581 i
>= TYPE_N_BASECLASSES (t
);
2584 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2585 sizeof (vptr_name
) - 1))
2587 TYPE_VPTR_FIELDNO (type
) = i
;
2591 /* Virtual function table field not found. */
2592 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2597 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2608 attach_fn_fields_to_type (fip
, type
)
2609 struct field_info
*fip
;
2610 register struct type
*type
;
2614 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2616 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2618 /* @@ Memory leak on objfile -> type_obstack? */
2621 TYPE_NFN_FIELDS_TOTAL (type
) +=
2622 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2625 for (n
= TYPE_NFN_FIELDS (type
);
2626 fip
-> fnlist
!= NULL
;
2627 fip
-> fnlist
= fip
-> fnlist
-> next
)
2629 --n
; /* Circumvent Sun3 compiler bug */
2630 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2635 /* Create the vector of fields, and record how big it is.
2636 We need this info to record proper virtual function table information
2637 for this class's virtual functions. */
2640 attach_fields_to_type (fip
, type
, objfile
)
2641 struct field_info
*fip
;
2642 register struct type
*type
;
2643 struct objfile
*objfile
;
2645 register int nfields
= 0;
2646 register int non_public_fields
= 0;
2647 register struct nextfield
*scan
;
2649 /* Count up the number of fields that we have, as well as taking note of
2650 whether or not there are any non-public fields, which requires us to
2651 allocate and build the private_field_bits and protected_field_bits
2654 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2657 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2659 non_public_fields
++;
2663 /* Now we know how many fields there are, and whether or not there are any
2664 non-public fields. Record the field count, allocate space for the
2665 array of fields, and create blank visibility bitfields if necessary. */
2667 TYPE_NFIELDS (type
) = nfields
;
2668 TYPE_FIELDS (type
) = (struct field
*)
2669 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2670 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2672 if (non_public_fields
)
2674 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2676 TYPE_FIELD_PRIVATE_BITS (type
) =
2677 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2678 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2680 TYPE_FIELD_PROTECTED_BITS (type
) =
2681 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2682 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2684 TYPE_FIELD_IGNORE_BITS (type
) =
2685 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2686 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2689 /* Copy the saved-up fields into the field vector. Start from the head
2690 of the list, adding to the tail of the field array, so that they end
2691 up in the same order in the array in which they were added to the list. */
2693 while (nfields
-- > 0)
2695 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2696 switch (fip
-> list
-> visibility
)
2698 case VISIBILITY_PRIVATE
:
2699 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2702 case VISIBILITY_PROTECTED
:
2703 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2706 case VISIBILITY_IGNORE
:
2707 SET_TYPE_FIELD_IGNORE (type
, nfields
);
2710 case VISIBILITY_PUBLIC
:
2714 /* Unknown visibility. Complain and treat it as public. */
2716 static struct complaint msg
= {
2717 "Unknown visibility `%c' for field", 0, 0};
2718 complain (&msg
, fip
-> list
-> visibility
);
2722 fip
-> list
= fip
-> list
-> next
;
2727 /* Read the description of a structure (or union type) and return an object
2728 describing the type.
2730 PP points to a character pointer that points to the next unconsumed token
2731 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2732 *PP will point to "4a:1,0,32;;".
2734 TYPE points to an incomplete type that needs to be filled in.
2736 OBJFILE points to the current objfile from which the stabs information is
2737 being read. (Note that it is redundant in that TYPE also contains a pointer
2738 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2741 static struct type
*
2742 read_struct_type (pp
, type
, objfile
)
2745 struct objfile
*objfile
;
2747 struct cleanup
*back_to
;
2748 struct field_info fi
;
2753 back_to
= make_cleanup (null_cleanup
, 0);
2755 INIT_CPLUS_SPECIFIC (type
);
2756 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2758 /* First comes the total size in bytes. */
2762 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2764 return error_type (pp
);
2767 /* Now read the baseclasses, if any, read the regular C struct or C++
2768 class member fields, attach the fields to the type, read the C++
2769 member functions, attach them to the type, and then read any tilde
2770 field (baseclass specifier for the class holding the main vtable). */
2772 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2773 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2774 || !attach_fields_to_type (&fi
, type
, objfile
)
2775 || !read_member_functions (&fi
, pp
, type
, objfile
)
2776 || !attach_fn_fields_to_type (&fi
, type
)
2777 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2779 do_cleanups (back_to
);
2780 return (error_type (pp
));
2783 do_cleanups (back_to
);
2787 /* Read a definition of an array type,
2788 and create and return a suitable type object.
2789 Also creates a range type which represents the bounds of that
2792 static struct type
*
2793 read_array_type (pp
, type
, objfile
)
2795 register struct type
*type
;
2796 struct objfile
*objfile
;
2798 struct type
*index_type
, *element_type
, *range_type
;
2803 /* Format of an array type:
2804 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2807 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2808 for these, produce a type like float[][]. */
2810 index_type
= read_type (pp
, objfile
);
2812 /* Improper format of array type decl. */
2813 return error_type (pp
);
2816 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2821 lower
= read_huge_number (pp
, ';', &nbits
);
2823 return error_type (pp
);
2825 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2830 upper
= read_huge_number (pp
, ';', &nbits
);
2832 return error_type (pp
);
2834 element_type
= read_type (pp
, objfile
);
2843 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2844 type
= create_array_type (type
, element_type
, range_type
);
2846 /* If we have an array whose element type is not yet known, but whose
2847 bounds *are* known, record it to be adjusted at the end of the file. */
2848 /* FIXME: Why check for zero length rather than TYPE_FLAG_STUB? I think
2849 the two have the same effect except that the latter is cleaner and the
2850 former would be wrong for types which really are zero-length (if we
2853 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2855 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2856 add_undefined_type (type
);
2863 /* Read a definition of an enumeration type,
2864 and create and return a suitable type object.
2865 Also defines the symbols that represent the values of the type. */
2867 static struct type
*
2868 read_enum_type (pp
, type
, objfile
)
2870 register struct type
*type
;
2871 struct objfile
*objfile
;
2876 register struct symbol
*sym
;
2878 struct pending
**symlist
;
2879 struct pending
*osyms
, *syms
;
2883 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2884 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2885 to do? For now, force all enum values to file scope. */
2886 if (within_function
)
2887 symlist
= &local_symbols
;
2890 symlist
= &file_symbols
;
2892 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2894 /* Read the value-names and their values.
2895 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2896 A semicolon or comma instead of a NAME means the end. */
2897 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2900 STABS_CONTINUE (pp
);
2902 while (*p
!= ':') p
++;
2903 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2905 n
= read_huge_number (pp
, ',', &nbits
);
2907 return error_type (pp
);
2909 sym
= (struct symbol
*)
2910 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2911 memset (sym
, 0, sizeof (struct symbol
));
2912 SYMBOL_NAME (sym
) = name
;
2913 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
2914 SYMBOL_CLASS (sym
) = LOC_CONST
;
2915 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2916 SYMBOL_VALUE (sym
) = n
;
2917 add_symbol_to_list (sym
, symlist
);
2922 (*pp
)++; /* Skip the semicolon. */
2924 /* Now fill in the fields of the type-structure. */
2926 TYPE_LENGTH (type
) = sizeof (int);
2927 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2928 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2929 TYPE_NFIELDS (type
) = nsyms
;
2930 TYPE_FIELDS (type
) = (struct field
*)
2931 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2932 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2934 /* Find the symbols for the values and put them into the type.
2935 The symbols can be found in the symlist that we put them on
2936 to cause them to be defined. osyms contains the old value
2937 of that symlist; everything up to there was defined by us. */
2938 /* Note that we preserve the order of the enum constants, so
2939 that in something like "enum {FOO, LAST_THING=FOO}" we print
2940 FOO, not LAST_THING. */
2942 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2947 for (; j
< syms
->nsyms
; j
++,n
++)
2949 struct symbol
*xsym
= syms
->symbol
[j
];
2950 SYMBOL_TYPE (xsym
) = type
;
2951 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2952 TYPE_FIELD_VALUE (type
, n
) = 0;
2953 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2954 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2961 /* This screws up perfectly good C programs with enums. FIXME. */
2962 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2963 if(TYPE_NFIELDS(type
) == 2 &&
2964 ((STREQ(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2965 STREQ(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2966 (STREQ(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2967 STREQ(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2968 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2974 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2975 typedefs in every file (for int, long, etc):
2977 type = b <signed> <width>; <offset>; <nbits>
2978 signed = u or s. Possible c in addition to u or s (for char?).
2979 offset = offset from high order bit to start bit of type.
2980 width is # bytes in object of this type, nbits is # bits in type.
2982 The width/offset stuff appears to be for small objects stored in
2983 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2986 static struct type
*
2987 read_sun_builtin_type (pp
, typenums
, objfile
)
2990 struct objfile
*objfile
;
3005 return error_type (pp
);
3009 /* For some odd reason, all forms of char put a c here. This is strange
3010 because no other type has this honor. We can safely ignore this because
3011 we actually determine 'char'acterness by the number of bits specified in
3017 /* The first number appears to be the number of bytes occupied
3018 by this type, except that unsigned short is 4 instead of 2.
3019 Since this information is redundant with the third number,
3020 we will ignore it. */
3021 read_huge_number (pp
, ';', &nbits
);
3023 return error_type (pp
);
3025 /* The second number is always 0, so ignore it too. */
3026 read_huge_number (pp
, ';', &nbits
);
3028 return error_type (pp
);
3030 /* The third number is the number of bits for this type. */
3031 type_bits
= read_huge_number (pp
, 0, &nbits
);
3033 return error_type (pp
);
3035 return init_type (type_bits
== 0 ? TYPE_CODE_VOID
: TYPE_CODE_INT
,
3036 type_bits
/ TARGET_CHAR_BIT
,
3037 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3041 static struct type
*
3042 read_sun_floating_type (pp
, typenums
, objfile
)
3045 struct objfile
*objfile
;
3051 /* The first number has more details about the type, for example
3053 details
= read_huge_number (pp
, ';', &nbits
);
3055 return error_type (pp
);
3057 /* The second number is the number of bytes occupied by this type */
3058 nbytes
= read_huge_number (pp
, ';', &nbits
);
3060 return error_type (pp
);
3062 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3063 || details
== NF_COMPLEX32
)
3064 /* This is a type we can't handle, but we do know the size.
3065 We also will be able to give it a name. */
3066 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3068 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3071 /* Read a number from the string pointed to by *PP.
3072 The value of *PP is advanced over the number.
3073 If END is nonzero, the character that ends the
3074 number must match END, or an error happens;
3075 and that character is skipped if it does match.
3076 If END is zero, *PP is left pointing to that character.
3078 If the number fits in a long, set *BITS to 0 and return the value.
3079 If not, set *BITS to be the number of bits in the number and return 0.
3081 If encounter garbage, set *BITS to -1 and return 0. */
3084 read_huge_number (pp
, end
, bits
)
3104 /* Leading zero means octal. GCC uses this to output values larger
3105 than an int (because that would be hard in decimal). */
3112 upper_limit
= LONG_MAX
/ radix
;
3113 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3115 if (n
<= upper_limit
)
3118 n
+= c
- '0'; /* FIXME this overflows anyway */
3123 /* This depends on large values being output in octal, which is
3130 /* Ignore leading zeroes. */
3134 else if (c
== '2' || c
== '3')
3160 /* Large decimal constants are an error (because it is hard to
3161 count how many bits are in them). */
3167 /* -0x7f is the same as 0x80. So deal with it by adding one to
3168 the number of bits. */
3180 /* It's *BITS which has the interesting information. */
3184 static struct type
*
3185 read_range_type (pp
, typenums
, objfile
)
3188 struct objfile
*objfile
;
3194 struct type
*result_type
;
3195 struct type
*index_type
;
3197 /* First comes a type we are a subrange of.
3198 In C it is usually 0, 1 or the type being defined. */
3199 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3200 not just a type number. */
3201 if (read_type_number (pp
, rangenums
) != 0)
3202 return error_type (pp
);
3203 self_subrange
= (rangenums
[0] == typenums
[0] &&
3204 rangenums
[1] == typenums
[1]);
3206 /* A semicolon should now follow; skip it. */
3210 /* The remaining two operands are usually lower and upper bounds
3211 of the range. But in some special cases they mean something else. */
3212 n2
= read_huge_number (pp
, ';', &n2bits
);
3213 n3
= read_huge_number (pp
, ';', &n3bits
);
3215 if (n2bits
== -1 || n3bits
== -1)
3216 return error_type (pp
);
3218 /* If limits are huge, must be large integral type. */
3219 if (n2bits
!= 0 || n3bits
!= 0)
3221 char got_signed
= 0;
3222 char got_unsigned
= 0;
3223 /* Number of bits in the type. */
3226 /* Range from 0 to <large number> is an unsigned large integral type. */
3227 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3232 /* Range from <large number> to <large number>-1 is a large signed
3233 integral type. Take care of the case where <large number> doesn't
3234 fit in a long but <large number>-1 does. */
3235 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3236 || (n2bits
!= 0 && n3bits
== 0
3237 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3244 if (got_signed
|| got_unsigned
)
3246 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3247 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3251 return error_type (pp
);
3254 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3255 if (self_subrange
&& n2
== 0 && n3
== 0)
3256 return init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
3258 /* If n3 is zero and n2 is not, we want a floating type,
3259 and n2 is the width in bytes.
3261 Fortran programs appear to use this for complex types also,
3262 and they give no way to distinguish between double and single-complex!
3264 GDB does not have complex types.
3266 Just return the complex as a float of that size. It won't work right
3267 for the complex values, but at least it makes the file loadable. */
3269 if (n3
== 0 && n2
> 0)
3271 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3274 /* If the upper bound is -1, it must really be an unsigned int. */
3276 else if (n2
== 0 && n3
== -1)
3278 /* It is unsigned int or unsigned long. */
3279 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3280 compatibility hack. */
3281 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3282 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3285 /* Special case: char is defined (Who knows why) as a subrange of
3286 itself with range 0-127. */
3287 else if (self_subrange
&& n2
== 0 && n3
== 127)
3288 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3290 /* We used to do this only for subrange of self or subrange of int. */
3294 /* n3 actually gives the size. */
3295 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3298 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3300 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3302 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3303 "unsigned long", and we already checked for that,
3304 so don't need to test for it here. */
3306 /* I think this is for Convex "long long". Since I don't know whether
3307 Convex sets self_subrange, I also accept that particular size regardless
3308 of self_subrange. */
3309 else if (n3
== 0 && n2
< 0
3311 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3312 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3313 else if (n2
== -n3
-1)
3316 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3318 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3319 if (n3
== 0x7fffffff)
3320 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3323 /* We have a real range type on our hands. Allocate space and
3324 return a real pointer. */
3326 /* At this point I don't have the faintest idea how to deal with
3327 a self_subrange type; I'm going to assume that this is used
3328 as an idiom, and that all of them are special cases. So . . . */
3330 return error_type (pp
);
3332 index_type
= *dbx_lookup_type (rangenums
);
3333 if (index_type
== NULL
)
3335 /* Does this actually ever happen? Is that why we are worrying
3336 about dealing with it rather than just calling error_type? */
3338 static struct type
*range_type_index
;
3340 complain (&range_type_base_complaint
, rangenums
[1]);
3341 if (range_type_index
== NULL
)
3343 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3344 0, "range type index type", NULL
);
3345 index_type
= range_type_index
;
3348 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3349 return (result_type
);
3352 /* Read in an argument list. This is a list of types, separated by commas
3353 and terminated with END. Return the list of types read in, or (struct type
3354 **)-1 if there is an error. */
3356 static struct type
**
3357 read_args (pp
, end
, objfile
)
3360 struct objfile
*objfile
;
3362 /* FIXME! Remove this arbitrary limit! */
3363 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3369 /* Invalid argument list: no ','. */
3370 return (struct type
**)-1;
3372 STABS_CONTINUE (pp
);
3373 types
[n
++] = read_type (pp
, objfile
);
3375 (*pp
)++; /* get past `end' (the ':' character) */
3379 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3381 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3383 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3384 memset (rval
+ n
, 0, sizeof (struct type
*));
3388 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3390 memcpy (rval
, types
, n
* sizeof (struct type
*));
3394 /* Common block handling. */
3396 /* List of symbols declared since the last BCOMM. This list is a tail
3397 of local_symbols. When ECOMM is seen, the symbols on the list
3398 are noted so their proper addresses can be filled in later,
3399 using the common block base address gotten from the assembler
3402 static struct pending
*common_block
;
3403 static int common_block_i
;
3405 /* Name of the current common block. We get it from the BCOMM instead of the
3406 ECOMM to match IBM documentation (even though IBM puts the name both places
3407 like everyone else). */
3408 static char *common_block_name
;
3410 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3411 to remain after this function returns. */
3414 common_block_start (name
, objfile
)
3416 struct objfile
*objfile
;
3418 if (common_block_name
!= NULL
)
3420 static struct complaint msg
= {
3421 "Invalid symbol data: common block within common block",
3425 common_block
= local_symbols
;
3426 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3427 common_block_name
= obsavestring (name
, strlen (name
),
3428 &objfile
-> symbol_obstack
);
3431 /* Process a N_ECOMM symbol. */
3434 common_block_end (objfile
)
3435 struct objfile
*objfile
;
3437 /* Symbols declared since the BCOMM are to have the common block
3438 start address added in when we know it. common_block and
3439 common_block_i point to the first symbol after the BCOMM in
3440 the local_symbols list; copy the list and hang it off the
3441 symbol for the common block name for later fixup. */
3444 struct pending
*new = 0;
3445 struct pending
*next
;
3448 if (common_block_name
== NULL
)
3450 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
3455 sym
= (struct symbol
*)
3456 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3457 memset (sym
, 0, sizeof (struct symbol
));
3458 SYMBOL_NAME (sym
) = common_block_name
;
3459 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3461 /* Now we copy all the symbols which have been defined since the BCOMM. */
3463 /* Copy all the struct pendings before common_block. */
3464 for (next
= local_symbols
;
3465 next
!= NULL
&& next
!= common_block
;
3468 for (j
= 0; j
< next
->nsyms
; j
++)
3469 add_symbol_to_list (next
->symbol
[j
], &new);
3472 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3473 NULL, it means copy all the local symbols (which we already did
3476 if (common_block
!= NULL
)
3477 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
3478 add_symbol_to_list (common_block
->symbol
[j
], &new);
3480 SYMBOL_NAMESPACE (sym
) = (enum namespace)((long) new);
3482 /* Should we be putting local_symbols back to what it was?
3485 i
= hashname (SYMBOL_NAME (sym
));
3486 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3487 global_sym_chain
[i
] = sym
;
3488 common_block_name
= NULL
;
3491 /* Add a common block's start address to the offset of each symbol
3492 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3493 the common block name). */
3496 fix_common_block (sym
, valu
)
3500 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3501 for ( ; next
; next
= next
->next
)
3504 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3505 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3511 /* What about types defined as forward references inside of a small lexical
3513 /* Add a type to the list of undefined types to be checked through
3514 once this file has been read in. */
3517 add_undefined_type (type
)
3520 if (undef_types_length
== undef_types_allocated
)
3522 undef_types_allocated
*= 2;
3523 undef_types
= (struct type
**)
3524 xrealloc ((char *) undef_types
,
3525 undef_types_allocated
* sizeof (struct type
*));
3527 undef_types
[undef_types_length
++] = type
;
3530 /* Go through each undefined type, see if it's still undefined, and fix it
3531 up if possible. We have two kinds of undefined types:
3533 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3534 Fix: update array length using the element bounds
3535 and the target type's length.
3536 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3537 yet defined at the time a pointer to it was made.
3538 Fix: Do a full lookup on the struct/union tag. */
3540 cleanup_undefined_types ()
3544 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3546 switch (TYPE_CODE (*type
))
3549 case TYPE_CODE_STRUCT
:
3550 case TYPE_CODE_UNION
:
3551 case TYPE_CODE_ENUM
:
3553 /* Check if it has been defined since. Need to do this here
3554 as well as in check_stub_type to deal with the (legitimate in
3555 C though not C++) case of several types with the same name
3556 in different source files. */
3557 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3559 struct pending
*ppt
;
3561 /* Name of the type, without "struct" or "union" */
3562 char *typename
= TYPE_TAG_NAME (*type
);
3564 if (typename
== NULL
)
3566 static struct complaint msg
= {"need a type name", 0, 0};
3570 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3572 for (i
= 0; i
< ppt
->nsyms
; i
++)
3574 struct symbol
*sym
= ppt
->symbol
[i
];
3576 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3577 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3578 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3580 && STREQ (SYMBOL_NAME (sym
), typename
))
3582 memcpy (*type
, SYMBOL_TYPE (sym
),
3583 sizeof (struct type
));
3591 case TYPE_CODE_ARRAY
:
3593 /* This is a kludge which is here for historical reasons
3594 because I suspect that check_stub_type does not get
3595 called everywhere it needs to be called for arrays. Even
3596 with this kludge, those places are broken for the case
3597 where the stub type is defined in another compilation
3598 unit, but this kludge at least deals with it for the case
3599 in which it is the same compilation unit.
3601 Don't try to do this by calling check_stub_type; it might
3602 cause symbols to be read in lookup_symbol, and the symbol
3603 reader is not reentrant. */
3605 struct type
*range_type
;
3608 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3610 if (TYPE_NFIELDS (*type
) != 1)
3612 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3613 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3616 /* Now recompute the length of the array type, based on its
3617 number of elements and the target type's length. */
3618 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3619 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3620 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3621 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3623 /* If the target type is not a stub, we could be clearing
3624 TYPE_FLAG_TARGET_STUB for *type. */
3631 static struct complaint msg
= {"\
3632 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3633 complain (&msg
, TYPE_CODE (*type
));
3639 undef_types_length
= 0;
3642 /* Scan through all of the global symbols defined in the object file,
3643 assigning values to the debugging symbols that need to be assigned
3644 to. Get these symbols from the minimal symbol table. */
3647 scan_file_globals (objfile
)
3648 struct objfile
*objfile
;
3651 struct minimal_symbol
*msymbol
;
3652 struct symbol
*sym
, *prev
;
3654 if (objfile
->msymbols
== 0) /* Beware the null file. */
3657 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3663 /* Get the hash index and check all the symbols
3664 under that hash index. */
3666 hash
= hashname (SYMBOL_NAME (msymbol
));
3668 for (sym
= global_sym_chain
[hash
]; sym
;)
3670 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3671 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3673 /* Splice this symbol out of the hash chain and
3674 assign the value we have to it. */
3677 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3681 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3684 /* Check to see whether we need to fix up a common block. */
3685 /* Note: this code might be executed several times for
3686 the same symbol if there are multiple references. */
3688 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3690 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3694 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3699 sym
= SYMBOL_VALUE_CHAIN (prev
);
3703 sym
= global_sym_chain
[hash
];
3709 sym
= SYMBOL_VALUE_CHAIN (sym
);
3715 /* Initialize anything that needs initializing when starting to read
3716 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3724 /* Initialize anything that needs initializing when a completely new
3725 symbol file is specified (not just adding some symbols from another
3726 file, e.g. a shared library). */
3729 stabsread_new_init ()
3731 /* Empty the hash table of global syms looking for values. */
3732 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3735 /* Initialize anything that needs initializing at the same time as
3736 start_symtab() is called. */
3740 global_stabs
= NULL
; /* AIX COFF */
3741 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3742 n_this_object_header_files
= 1;
3743 type_vector_length
= 0;
3744 type_vector
= (struct type
**) 0;
3746 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3747 common_block_name
= NULL
;
3750 /* Call after end_symtab() */
3756 free ((char *) type_vector
);
3759 type_vector_length
= 0;
3760 previous_stab_code
= 0;
3764 finish_global_stabs (objfile
)
3765 struct objfile
*objfile
;
3769 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3770 free ((PTR
) global_stabs
);
3771 global_stabs
= NULL
;
3775 /* Initializer for this module */
3778 _initialize_stabsread ()
3780 undef_types_allocated
= 20;
3781 undef_types_length
= 0;
3782 undef_types
= (struct type
**)
3783 xmalloc (undef_types_allocated
* sizeof (struct type
*));