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
;
453 #if !defined (REG_STRUCT_HAS_ADDR)
454 #define REG_STRUCT_HAS_ADDR(gcc_p) 0
459 define_symbol (valu
, string
, desc
, type
, objfile
)
464 struct objfile
*objfile
;
466 register struct symbol
*sym
;
467 char *p
= (char *) strchr (string
, ':');
472 /* We would like to eliminate nameless symbols, but keep their types.
473 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
474 to type 2, but, should not create a symbol to address that type. Since
475 the symbol will be nameless, there is no way any user can refer to it. */
479 /* Ignore syms with empty names. */
483 /* Ignore old-style symbols from cc -go */
493 /* If a nameless stab entry, all we need is the type, not the symbol.
494 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
495 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
497 sym
= (struct symbol
*)
498 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
499 memset (sym
, 0, sizeof (struct symbol
));
501 if (processing_gcc_compilation
)
503 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
504 number of bytes occupied by a type or object, which we ignore. */
505 SYMBOL_LINE(sym
) = desc
;
509 SYMBOL_LINE(sym
) = 0; /* unknown */
512 if (string
[0] == CPLUS_MARKER
)
514 /* Special GNU C++ names. */
518 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
519 &objfile
-> symbol_obstack
);
522 case 'v': /* $vtbl_ptr_type */
523 /* Was: SYMBOL_NAME (sym) = "vptr"; */
527 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
528 &objfile
-> symbol_obstack
);
532 /* This was an anonymous type that was never fixed up. */
536 complain (&unrecognized_cplus_name_complaint
, string
);
537 goto normal
; /* Do *something* with it */
543 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
544 SYMBOL_NAME (sym
) = (char *)
545 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
546 /* Open-coded memcpy--saves function call time. */
547 /* FIXME: Does it really? Try replacing with simple strcpy and
548 try it on an executable with a large symbol table. */
549 /* FIXME: considering that gcc can open code memcpy anyway, I
550 doubt it. xoxorich. */
552 register char *p1
= string
;
553 register char *p2
= SYMBOL_NAME (sym
);
561 /* If this symbol is from a C++ compilation, then attempt to cache the
562 demangled form for future reference. This is a typical time versus
563 space tradeoff, that was decided in favor of time because it sped up
564 C++ symbol lookups by a factor of about 20. */
566 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
570 /* Determine the type of name being defined. */
572 /* Getting GDB to correctly skip the symbol on an undefined symbol
573 descriptor and not ever dump core is a very dodgy proposition if
574 we do things this way. I say the acorn RISC machine can just
575 fix their compiler. */
576 /* The Acorn RISC machine's compiler can put out locals that don't
577 start with "234=" or "(3,4)=", so assume anything other than the
578 deftypes we know how to handle is a local. */
579 if (!strchr ("cfFGpPrStTvVXCR", *p
))
581 if (isdigit (*p
) || *p
== '(' || *p
== '-')
590 /* c is a special case, not followed by a type-number.
591 SYMBOL:c=iVALUE for an integer constant symbol.
592 SYMBOL:c=rVALUE for a floating constant symbol.
593 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
594 e.g. "b:c=e6,0" for "const b = blob1"
595 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
598 SYMBOL_CLASS (sym
) = LOC_CONST
;
599 SYMBOL_TYPE (sym
) = error_type (&p
);
600 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
601 add_symbol_to_list (sym
, &file_symbols
);
612 /* FIXME-if-picky-about-floating-accuracy: Should be using
613 target arithmetic to get the value. real.c in GCC
614 probably has the necessary code. */
616 /* FIXME: lookup_fundamental_type is a hack. We should be
617 creating a type especially for the type of float constants.
618 Problem is, what type should it be?
620 Also, what should the name of this type be? Should we
621 be using 'S' constants (see stabs.texinfo) instead? */
623 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
626 obstack_alloc (&objfile
-> symbol_obstack
,
627 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
628 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
629 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
630 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
635 /* Defining integer constants this way is kind of silly,
636 since 'e' constants allows the compiler to give not
637 only the value, but the type as well. C has at least
638 int, long, unsigned int, and long long as constant
639 types; other languages probably should have at least
640 unsigned as well as signed constants. */
642 /* We just need one int constant type for all objfiles.
643 It doesn't depend on languages or anything (arguably its
644 name should be a language-specific name for a type of
645 that size, but I'm inclined to say that if the compiler
646 wants a nice name for the type, it can use 'e'). */
647 static struct type
*int_const_type
;
649 /* Yes, this is as long as a *host* int. That is because we
651 if (int_const_type
== NULL
)
653 init_type (TYPE_CODE_INT
,
654 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
656 (struct objfile
*)NULL
);
657 SYMBOL_TYPE (sym
) = int_const_type
;
658 SYMBOL_VALUE (sym
) = atoi (p
);
659 SYMBOL_CLASS (sym
) = LOC_CONST
;
663 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
664 can be represented as integral.
665 e.g. "b:c=e6,0" for "const b = blob1"
666 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
668 SYMBOL_CLASS (sym
) = LOC_CONST
;
669 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
673 SYMBOL_TYPE (sym
) = error_type (&p
);
678 /* If the value is too big to fit in an int (perhaps because
679 it is unsigned), or something like that, we silently get
680 a bogus value. The type and everything else about it is
681 correct. Ideally, we should be using whatever we have
682 available for parsing unsigned and long long values,
684 SYMBOL_VALUE (sym
) = atoi (p
);
689 SYMBOL_CLASS (sym
) = LOC_CONST
;
690 SYMBOL_TYPE (sym
) = error_type (&p
);
693 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
694 add_symbol_to_list (sym
, &file_symbols
);
698 /* The name of a caught exception. */
699 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
700 SYMBOL_CLASS (sym
) = LOC_LABEL
;
701 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
702 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
703 add_symbol_to_list (sym
, &local_symbols
);
707 /* A static function definition. */
708 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
709 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
710 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
711 add_symbol_to_list (sym
, &file_symbols
);
712 /* fall into process_function_types. */
714 process_function_types
:
715 /* Function result types are described as the result type in stabs.
716 We need to convert this to the function-returning-type-X type
717 in GDB. E.g. "int" is converted to "function returning int". */
718 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
721 /* This code doesn't work -- it needs to realloc and can't. */
722 /* Attempt to set up to record a function prototype... */
723 struct type
*new = alloc_type (objfile
);
725 /* Generate a template for the type of this function. The
726 types of the arguments will be added as we read the symbol
728 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
729 SYMBOL_TYPE(sym
) = new;
730 TYPE_OBJFILE (new) = objfile
;
731 in_function_type
= new;
733 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
736 /* fall into process_prototype_types */
738 process_prototype_types
:
739 /* Sun acc puts declared types of arguments here. We don't care
740 about their actual types (FIXME -- we should remember the whole
741 function prototype), but the list may define some new types
742 that we have to remember, so we must scan it now. */
745 read_type (&p
, objfile
);
750 /* A global function definition. */
751 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
752 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
753 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
754 add_symbol_to_list (sym
, &global_symbols
);
755 goto process_function_types
;
758 /* For a class G (global) symbol, it appears that the
759 value is not correct. It is necessary to search for the
760 corresponding linker definition to find the value.
761 These definitions appear at the end of the namelist. */
762 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
763 i
= hashname (SYMBOL_NAME (sym
));
764 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
765 global_sym_chain
[i
] = sym
;
766 SYMBOL_CLASS (sym
) = LOC_STATIC
;
767 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
768 add_symbol_to_list (sym
, &global_symbols
);
771 /* This case is faked by a conditional above,
772 when there is no code letter in the dbx data.
773 Dbx data never actually contains 'l'. */
775 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
776 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
777 SYMBOL_VALUE (sym
) = valu
;
778 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
779 add_symbol_to_list (sym
, &local_symbols
);
784 /* pF is a two-letter code that means a function parameter in Fortran.
785 The type-number specifies the type of the return value.
786 Translate it into a pointer-to-function type. */
790 = lookup_pointer_type
791 (lookup_function_type (read_type (&p
, objfile
)));
794 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
796 /* Normally this is a parameter, a LOC_ARG. On the i960, it
797 can also be a LOC_LOCAL_ARG depending on symbol type. */
798 #ifndef DBX_PARM_SYMBOL_CLASS
799 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
802 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
803 SYMBOL_VALUE (sym
) = valu
;
804 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
806 /* This doesn't work yet. */
807 add_param_to_type (&in_function_type
, sym
);
809 add_symbol_to_list (sym
, &local_symbols
);
811 #if TARGET_BYTE_ORDER == LITTLE_ENDIAN
812 /* On little-endian machines, this crud is never necessary, and,
813 if the extra bytes contain garbage, is harmful. */
815 #else /* Big endian. */
816 /* If it's gcc-compiled, if it says `short', believe it. */
817 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
820 #if !BELIEVE_PCC_PROMOTION
822 /* This is the signed type which arguments get promoted to. */
823 static struct type
*pcc_promotion_type
;
824 /* This is the unsigned type which arguments get promoted to. */
825 static struct type
*pcc_unsigned_promotion_type
;
827 /* Call it "int" because this is mainly C lossage. */
828 if (pcc_promotion_type
== NULL
)
830 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
833 if (pcc_unsigned_promotion_type
== NULL
)
834 pcc_unsigned_promotion_type
=
835 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
836 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
838 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
839 /* This macro is defined on machines (e.g. sparc) where
840 we should believe the type of a PCC 'short' argument,
841 but shouldn't believe the address (the address is
842 the address of the corresponding int).
844 My guess is that this correction, as opposed to changing
845 the parameter to an 'int' (as done below, for PCC
846 on most machines), is the right thing to do
847 on all machines, but I don't want to risk breaking
848 something that already works. On most PCC machines,
849 the sparc problem doesn't come up because the calling
850 function has to zero the top bytes (not knowing whether
851 the called function wants an int or a short), so there
852 is little practical difference between an int and a short
853 (except perhaps what happens when the GDB user types
854 "print short_arg = 0x10000;").
856 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
857 actually produces the correct address (we don't need to fix it
858 up). I made this code adapt so that it will offset the symbol
859 if it was pointing at an int-aligned location and not
860 otherwise. This way you can use the same gdb for 4.0.x and
863 If the parameter is shorter than an int, and is integral
864 (e.g. char, short, or unsigned equivalent), and is claimed to
865 be passed on an integer boundary, don't believe it! Offset the
866 parameter's address to the tail-end of that integer. */
868 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
869 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
870 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
872 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
873 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
877 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
879 /* If PCC says a parameter is a short or a char,
880 it is really an int. */
881 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
882 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
885 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
886 ? pcc_unsigned_promotion_type
887 : pcc_promotion_type
;
891 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
893 #endif /* !BELIEVE_PCC_PROMOTION. */
894 #endif /* Big endian. */
897 /* acc seems to use P to delare the prototypes of functions that
898 are referenced by this file. gdb is not prepared to deal
899 with this extra information. FIXME, it ought to. */
902 read_type (&p
, objfile
);
903 goto process_prototype_types
;
908 /* Parameter which is in a register. */
909 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
910 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
911 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
912 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
914 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
915 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
917 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
918 add_symbol_to_list (sym
, &local_symbols
);
922 /* Register variable (either global or local). */
923 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
924 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
925 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
926 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
928 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
929 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
931 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
934 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
935 name to represent an argument passed in a register.
936 GCC uses 'P' for the same case. So if we find such a symbol pair
937 we combine it into one 'P' symbol.
939 But we only do this in the REG_STRUCT_HAS_ADDR case, so that
940 we can still get information about what is going on with the
941 stack (VAX for computing args_printed, using stack slots instead
942 of saved registers in backtraces, etc.).
944 Note that this code illegally combines
945 main(argc) struct foo argc; { register struct foo argc; }
946 but this case is considered pathological and causes a warning
947 from a decent compiler. */
950 && local_symbols
->nsyms
> 0
951 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
)
952 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
953 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
))
955 struct symbol
*prev_sym
;
956 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
957 if (SYMBOL_CLASS (prev_sym
) == LOC_ARG
958 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
960 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
961 /* Use the type from the LOC_REGISTER; that is the type
962 that is actually in that register. */
963 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
964 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
969 add_symbol_to_list (sym
, &local_symbols
);
972 add_symbol_to_list (sym
, &file_symbols
);
976 /* Static symbol at top level of file */
977 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
978 SYMBOL_CLASS (sym
) = LOC_STATIC
;
979 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
980 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
981 add_symbol_to_list (sym
, &file_symbols
);
985 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
987 /* For a nameless type, we don't want a create a symbol, thus we
988 did not use `sym'. Return without further processing. */
989 if (nameless
) return NULL
;
991 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
992 SYMBOL_VALUE (sym
) = valu
;
993 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
994 /* C++ vagaries: we may have a type which is derived from
995 a base type which did not have its name defined when the
996 derived class was output. We fill in the derived class's
997 base part member's name here in that case. */
998 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
999 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1000 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1001 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1004 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1005 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1006 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1007 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1010 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1012 if (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1013 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1015 /* If we are giving a name to a type such as "pointer to
1016 foo" or "function returning foo", we better not set
1017 the TYPE_NAME. If the program contains "typedef char
1018 *caddr_t;", we don't want all variables of type char
1019 * to print as caddr_t. This is not just a
1020 consequence of GDB's type management; PCC and GCC (at
1021 least through version 2.4) both output variables of
1022 either type char * or caddr_t with the type number
1023 defined in the 't' symbol for caddr_t. If a future
1024 compiler cleans this up it GDB is not ready for it
1025 yet, but if it becomes ready we somehow need to
1026 disable this check (without breaking the PCC/GCC2.4
1031 Fortunately, this check seems not to be necessary
1032 for anything except pointers or functions. */
1035 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1038 add_symbol_to_list (sym
, &file_symbols
);
1042 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1043 by 't' which means we are typedef'ing it as well. */
1044 synonym
= *p
== 't';
1049 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1050 strlen (SYMBOL_NAME (sym
)),
1051 &objfile
-> symbol_obstack
);
1053 /* The semantics of C++ state that "struct foo { ... }" also defines
1054 a typedef for "foo". Unfortunately, cfront never makes the typedef
1055 when translating C++ into C. We make the typedef here so that
1056 "ptype foo" works as expected for cfront translated code. */
1057 else if (current_subfile
->language
== language_cplus
)
1060 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1061 strlen (SYMBOL_NAME (sym
)),
1062 &objfile
-> symbol_obstack
);
1065 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1067 /* For a nameless type, we don't want a create a symbol, thus we
1068 did not use `sym'. Return without further processing. */
1069 if (nameless
) return NULL
;
1071 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1072 SYMBOL_VALUE (sym
) = valu
;
1073 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1074 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1075 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1076 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1077 add_symbol_to_list (sym
, &file_symbols
);
1081 /* Clone the sym and then modify it. */
1082 register struct symbol
*typedef_sym
= (struct symbol
*)
1083 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1084 *typedef_sym
= *sym
;
1085 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1086 SYMBOL_VALUE (typedef_sym
) = valu
;
1087 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1088 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1089 TYPE_NAME (SYMBOL_TYPE (sym
))
1090 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1091 add_symbol_to_list (typedef_sym
, &file_symbols
);
1096 /* Static symbol of local scope */
1097 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1098 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1099 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1100 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1101 add_symbol_to_list (sym
, &local_symbols
);
1105 /* Reference parameter */
1106 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1107 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1108 SYMBOL_VALUE (sym
) = valu
;
1109 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1110 add_symbol_to_list (sym
, &local_symbols
);
1114 /* This is used by Sun FORTRAN for "function result value".
1115 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1116 that Pascal uses it too, but when I tried it Pascal used
1117 "x:3" (local symbol) instead. */
1118 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1119 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1120 SYMBOL_VALUE (sym
) = valu
;
1121 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1122 add_symbol_to_list (sym
, &local_symbols
);
1126 SYMBOL_TYPE (sym
) = error_type (&p
);
1127 SYMBOL_CLASS (sym
) = LOC_CONST
;
1128 SYMBOL_VALUE (sym
) = 0;
1129 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1130 add_symbol_to_list (sym
, &file_symbols
);
1134 /* When passing structures to a function, some systems sometimes pass
1135 the address in a register, not the structure itself.
1137 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1138 to LOC_REGPARM_ADDR for structures and unions. */
1140 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1141 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
)
1142 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1143 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1144 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1150 /* Skip rest of this symbol and return an error type.
1152 General notes on error recovery: error_type always skips to the
1153 end of the symbol (modulo cretinous dbx symbol name continuation).
1154 Thus code like this:
1156 if (*(*pp)++ != ';')
1157 return error_type (pp);
1159 is wrong because if *pp starts out pointing at '\0' (typically as the
1160 result of an earlier error), it will be incremented to point to the
1161 start of the next symbol, which might produce strange results, at least
1162 if you run off the end of the string table. Instead use
1165 return error_type (pp);
1171 foo = error_type (pp);
1175 And in case it isn't obvious, the point of all this hair is so the compiler
1176 can define new types and new syntaxes, and old versions of the
1177 debugger will be able to read the new symbol tables. */
1179 static struct type
*
1183 complain (&error_type_complaint
);
1186 /* Skip to end of symbol. */
1187 while (**pp
!= '\0')
1192 /* Check for and handle cretinous dbx symbol name continuation! */
1193 if ((*pp
)[-1] == '\\')
1195 *pp
= next_symbol_text ();
1202 return (builtin_type_error
);
1206 /* Read type information or a type definition; return the type. Even
1207 though this routine accepts either type information or a type
1208 definition, the distinction is relevant--some parts of stabsread.c
1209 assume that type information starts with a digit, '-', or '(' in
1210 deciding whether to call read_type. */
1213 read_type (pp
, objfile
)
1215 struct objfile
*objfile
;
1217 register struct type
*type
= 0;
1221 char type_descriptor
;
1223 /* Size in bits of type if specified by a type attribute, or -1 if
1224 there is no size attribute. */
1227 /* Used to distinguish string and bitstring from char-array and set. */
1230 /* Read type number if present. The type number may be omitted.
1231 for instance in a two-dimensional array declared with type
1232 "ar1;1;10;ar1;1;10;4". */
1233 if ((**pp
>= '0' && **pp
<= '9')
1237 if (read_type_number (pp
, typenums
) != 0)
1238 return error_type (pp
);
1240 /* Type is not being defined here. Either it already exists,
1241 or this is a forward reference to it. dbx_alloc_type handles
1244 return dbx_alloc_type (typenums
, objfile
);
1246 /* Type is being defined here. */
1253 /* It might be a type attribute or a member type. */
1254 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1259 /* Type attributes. */
1262 /* Skip to the semicolon. */
1263 while (*p
!= ';' && *p
!= '\0')
1267 return error_type (pp
);
1269 /* Skip the semicolon. */
1275 type_size
= atoi (attr
+ 1);
1285 /* Ignore unrecognized type attributes, so future compilers
1286 can invent new ones. */
1291 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1296 /* 'typenums=' not present, type is anonymous. Read and return
1297 the definition, but don't put it in the type vector. */
1298 typenums
[0] = typenums
[1] = -1;
1302 type_descriptor
= (*pp
)[-1];
1303 switch (type_descriptor
)
1307 enum type_code code
;
1309 /* Used to index through file_symbols. */
1310 struct pending
*ppt
;
1313 /* Name including "struct", etc. */
1317 char *from
, *to
, *p
, *q1
, *q2
;
1319 /* Set the type code according to the following letter. */
1323 code
= TYPE_CODE_STRUCT
;
1326 code
= TYPE_CODE_UNION
;
1329 code
= TYPE_CODE_ENUM
;
1333 /* Complain and keep going, so compilers can invent new
1334 cross-reference types. */
1335 static struct complaint msg
=
1336 {"Unrecognized cross-reference type `%c'", 0, 0};
1337 complain (&msg
, (*pp
)[0]);
1338 code
= TYPE_CODE_STRUCT
;
1343 q1
= strchr(*pp
, '<');
1344 p
= strchr(*pp
, ':');
1346 return error_type (pp
);
1347 while (q1
&& p
> q1
&& p
[1] == ':')
1349 q2
= strchr(q1
, '>');
1355 return error_type (pp
);
1358 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1360 /* Copy the name. */
1366 /* Set the pointer ahead of the name which we just read, and
1371 /* Now check to see whether the type has already been
1372 declared. This was written for arrays of cross-referenced
1373 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1374 sure it is not necessary anymore. But it might be a good
1375 idea, to save a little memory. */
1377 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1378 for (i
= 0; i
< ppt
->nsyms
; i
++)
1380 struct symbol
*sym
= ppt
->symbol
[i
];
1382 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1383 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1384 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1385 && STREQ (SYMBOL_NAME (sym
), type_name
))
1387 obstack_free (&objfile
-> type_obstack
, type_name
);
1388 type
= SYMBOL_TYPE (sym
);
1393 /* Didn't find the type to which this refers, so we must
1394 be dealing with a forward reference. Allocate a type
1395 structure for it, and keep track of it so we can
1396 fill in the rest of the fields when we get the full
1398 type
= dbx_alloc_type (typenums
, objfile
);
1399 TYPE_CODE (type
) = code
;
1400 TYPE_TAG_NAME (type
) = type_name
;
1401 INIT_CPLUS_SPECIFIC(type
);
1402 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1404 add_undefined_type (type
);
1408 case '-': /* RS/6000 built-in type */
1422 if (read_type_number (pp
, xtypenums
) != 0)
1423 return error_type (pp
);
1425 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1426 /* It's being defined as itself. That means it is "void". */
1427 type
= init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
1430 struct type
*xtype
= *dbx_lookup_type (xtypenums
);
1432 /* This can happen if we had '-' followed by a garbage character,
1435 return error_type (pp
);
1437 /* The type is being defined to another type. So we copy the type.
1438 This loses if we copy a C++ class and so we lose track of how
1439 the names are mangled (but g++ doesn't output stabs like this
1442 type
= alloc_type (objfile
);
1443 memcpy (type
, xtype
, sizeof (struct type
));
1445 /* The idea behind clearing the names is that the only purpose
1446 for defining a type to another type is so that the name of
1447 one can be different. So we probably don't need to worry much
1448 about the case where the compiler doesn't give a name to the
1450 TYPE_NAME (type
) = NULL
;
1451 TYPE_TAG_NAME (type
) = NULL
;
1453 if (typenums
[0] != -1)
1454 *dbx_lookup_type (typenums
) = type
;
1457 /* In the following types, we must be sure to overwrite any existing
1458 type that the typenums refer to, rather than allocating a new one
1459 and making the typenums point to the new one. This is because there
1460 may already be pointers to the existing type (if it had been
1461 forward-referenced), and we must change it to a pointer, function,
1462 reference, or whatever, *in-place*. */
1465 type1
= read_type (pp
, objfile
);
1466 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1469 case '&': /* Reference to another type */
1470 type1
= read_type (pp
, objfile
);
1471 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1474 case 'f': /* Function returning another type */
1475 type1
= read_type (pp
, objfile
);
1476 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1479 case 'k': /* Const qualifier on some type (Sun) */
1480 type
= read_type (pp
, objfile
);
1481 /* FIXME! For now, we ignore const and volatile qualifiers. */
1484 case 'B': /* Volatile qual on some type (Sun) */
1485 type
= read_type (pp
, objfile
);
1486 /* FIXME! For now, we ignore const and volatile qualifiers. */
1489 /* FIXME -- we should be doing smash_to_XXX types here. */
1490 case '@': /* Member (class & variable) type */
1492 struct type
*domain
= read_type (pp
, objfile
);
1493 struct type
*memtype
;
1496 /* Invalid member type data format. */
1497 return error_type (pp
);
1500 memtype
= read_type (pp
, objfile
);
1501 type
= dbx_alloc_type (typenums
, objfile
);
1502 smash_to_member_type (type
, domain
, memtype
);
1506 case '#': /* Method (class & fn) type */
1507 if ((*pp
)[0] == '#')
1509 /* We'll get the parameter types from the name. */
1510 struct type
*return_type
;
1513 return_type
= read_type (pp
, objfile
);
1514 if (*(*pp
)++ != ';')
1515 complain (&invalid_member_complaint
, symnum
);
1516 type
= allocate_stub_method (return_type
);
1517 if (typenums
[0] != -1)
1518 *dbx_lookup_type (typenums
) = type
;
1522 struct type
*domain
= read_type (pp
, objfile
);
1523 struct type
*return_type
;
1527 /* Invalid member type data format. */
1528 return error_type (pp
);
1532 return_type
= read_type (pp
, objfile
);
1533 args
= read_args (pp
, ';', objfile
);
1534 type
= dbx_alloc_type (typenums
, objfile
);
1535 smash_to_method_type (type
, domain
, return_type
, args
);
1539 case 'r': /* Range type */
1540 type
= read_range_type (pp
, typenums
, objfile
);
1541 if (typenums
[0] != -1)
1542 *dbx_lookup_type (typenums
) = type
;
1545 case 'b': /* Sun ACC builtin int type */
1546 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1547 if (typenums
[0] != -1)
1548 *dbx_lookup_type (typenums
) = type
;
1551 case 'R': /* Sun ACC builtin float type */
1552 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1553 if (typenums
[0] != -1)
1554 *dbx_lookup_type (typenums
) = type
;
1557 case 'e': /* Enumeration type */
1558 type
= dbx_alloc_type (typenums
, objfile
);
1559 type
= read_enum_type (pp
, type
, objfile
);
1560 if (typenums
[0] != -1)
1561 *dbx_lookup_type (typenums
) = type
;
1564 case 's': /* Struct type */
1565 case 'u': /* Union type */
1566 type
= dbx_alloc_type (typenums
, objfile
);
1567 if (!TYPE_NAME (type
))
1569 TYPE_NAME (type
) = type_synonym_name
;
1571 type_synonym_name
= NULL
;
1572 switch (type_descriptor
)
1575 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1578 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1581 type
= read_struct_type (pp
, type
, objfile
);
1584 case 'a': /* Array type */
1586 return error_type (pp
);
1589 type
= dbx_alloc_type (typenums
, objfile
);
1590 type
= read_array_type (pp
, type
, objfile
);
1592 TYPE_CODE (type
) = TYPE_CODE_STRING
;
1596 type1
= read_type (pp
, objfile
);
1597 type
= create_set_type ((struct type
*) NULL
, type1
);
1599 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
1600 if (typenums
[0] != -1)
1601 *dbx_lookup_type (typenums
) = type
;
1605 --*pp
; /* Go back to the symbol in error */
1606 /* Particularly important if it was \0! */
1607 return error_type (pp
);
1612 warning ("GDB internal error, type is NULL in stabsread.c\n");
1613 return error_type (pp
);
1616 /* Size specified in a type attribute overrides any other size. */
1617 if (type_size
!= -1)
1618 TYPE_LENGTH (type
) = type_size
/ TARGET_CHAR_BIT
;
1623 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1624 Return the proper type node for a given builtin type number. */
1626 static struct type
*
1627 rs6000_builtin_type (typenum
)
1630 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1631 #define NUMBER_RECOGNIZED 30
1632 /* This includes an empty slot for type number -0. */
1633 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1634 struct type
*rettype
= NULL
;
1636 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1638 complain (&rs6000_builtin_complaint
, typenum
);
1639 return builtin_type_error
;
1641 if (negative_types
[-typenum
] != NULL
)
1642 return negative_types
[-typenum
];
1644 #if TARGET_CHAR_BIT != 8
1645 #error This code wrong for TARGET_CHAR_BIT not 8
1646 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1647 that if that ever becomes not true, the correct fix will be to
1648 make the size in the struct type to be in bits, not in units of
1655 /* The size of this and all the other types are fixed, defined
1656 by the debugging format. If there is a type called "int" which
1657 is other than 32 bits, then it should use a new negative type
1658 number (or avoid negative type numbers for that case).
1659 See stabs.texinfo. */
1660 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1663 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1666 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1669 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1672 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1673 "unsigned char", NULL
);
1676 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1679 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1680 "unsigned short", NULL
);
1683 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1684 "unsigned int", NULL
);
1687 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1690 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1691 "unsigned long", NULL
);
1694 rettype
= init_type (TYPE_CODE_VOID
, 0, 0, "void", NULL
);
1697 /* IEEE single precision (32 bit). */
1698 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1701 /* IEEE double precision (64 bit). */
1702 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1705 /* This is an IEEE double on the RS/6000, and different machines with
1706 different sizes for "long double" should use different negative
1707 type numbers. See stabs.texinfo. */
1708 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1711 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1714 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1717 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1720 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1723 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1726 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1730 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1734 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1738 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1742 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1746 /* Complex type consisting of two IEEE single precision values. */
1747 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1750 /* Complex type consisting of two IEEE double precision values. */
1751 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1754 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1757 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1760 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1763 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1766 negative_types
[-typenum
] = rettype
;
1770 /* This page contains subroutines of read_type. */
1772 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1773 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1774 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1775 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1777 /* Read member function stabs info for C++ classes. The form of each member
1780 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1782 An example with two member functions is:
1784 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1786 For the case of overloaded operators, the format is op$::*.funcs, where
1787 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1788 name (such as `+=') and `.' marks the end of the operator name.
1790 Returns 1 for success, 0 for failure. */
1793 read_member_functions (fip
, pp
, type
, objfile
)
1794 struct field_info
*fip
;
1797 struct objfile
*objfile
;
1801 /* Total number of member functions defined in this class. If the class
1802 defines two `f' functions, and one `g' function, then this will have
1804 int total_length
= 0;
1808 struct next_fnfield
*next
;
1809 struct fn_field fn_field
;
1811 struct type
*look_ahead_type
;
1812 struct next_fnfieldlist
*new_fnlist
;
1813 struct next_fnfield
*new_sublist
;
1817 /* Process each list until we find something that is not a member function
1818 or find the end of the functions. */
1822 /* We should be positioned at the start of the function name.
1823 Scan forward to find the first ':' and if it is not the
1824 first of a "::" delimiter, then this is not a member function. */
1836 look_ahead_type
= NULL
;
1839 new_fnlist
= (struct next_fnfieldlist
*)
1840 xmalloc (sizeof (struct next_fnfieldlist
));
1841 make_cleanup (free
, new_fnlist
);
1842 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1844 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1846 /* This is a completely wierd case. In order to stuff in the
1847 names that might contain colons (the usual name delimiter),
1848 Mike Tiemann defined a different name format which is
1849 signalled if the identifier is "op$". In that case, the
1850 format is "op$::XXXX." where XXXX is the name. This is
1851 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1852 /* This lets the user type "break operator+".
1853 We could just put in "+" as the name, but that wouldn't
1855 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1856 char *o
= opname
+ 3;
1858 /* Skip past '::'. */
1861 STABS_CONTINUE (pp
);
1867 main_fn_name
= savestring (opname
, o
- opname
);
1873 main_fn_name
= savestring (*pp
, p
- *pp
);
1874 /* Skip past '::'. */
1877 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1882 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1883 make_cleanup (free
, new_sublist
);
1884 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1886 /* Check for and handle cretinous dbx symbol name continuation! */
1887 if (look_ahead_type
== NULL
)
1890 STABS_CONTINUE (pp
);
1892 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1895 /* Invalid symtab info for member function. */
1901 /* g++ version 1 kludge */
1902 new_sublist
-> fn_field
.type
= look_ahead_type
;
1903 look_ahead_type
= NULL
;
1913 /* If this is just a stub, then we don't have the real name here. */
1915 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1917 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
1918 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
1919 new_sublist
-> fn_field
.is_stub
= 1;
1921 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1924 /* Set this member function's visibility fields. */
1927 case VISIBILITY_PRIVATE
:
1928 new_sublist
-> fn_field
.is_private
= 1;
1930 case VISIBILITY_PROTECTED
:
1931 new_sublist
-> fn_field
.is_protected
= 1;
1935 STABS_CONTINUE (pp
);
1938 case 'A': /* Normal functions. */
1939 new_sublist
-> fn_field
.is_const
= 0;
1940 new_sublist
-> fn_field
.is_volatile
= 0;
1943 case 'B': /* `const' member functions. */
1944 new_sublist
-> fn_field
.is_const
= 1;
1945 new_sublist
-> fn_field
.is_volatile
= 0;
1948 case 'C': /* `volatile' member function. */
1949 new_sublist
-> fn_field
.is_const
= 0;
1950 new_sublist
-> fn_field
.is_volatile
= 1;
1953 case 'D': /* `const volatile' member function. */
1954 new_sublist
-> fn_field
.is_const
= 1;
1955 new_sublist
-> fn_field
.is_volatile
= 1;
1958 case '*': /* File compiled with g++ version 1 -- no info */
1963 complain (&const_vol_complaint
, **pp
);
1972 /* virtual member function, followed by index.
1973 The sign bit is set to distinguish pointers-to-methods
1974 from virtual function indicies. Since the array is
1975 in words, the quantity must be shifted left by 1
1976 on 16 bit machine, and by 2 on 32 bit machine, forcing
1977 the sign bit out, and usable as a valid index into
1978 the array. Remove the sign bit here. */
1979 new_sublist
-> fn_field
.voffset
=
1980 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
1984 STABS_CONTINUE (pp
);
1985 if (**pp
== ';' || **pp
== '\0')
1987 /* Must be g++ version 1. */
1988 new_sublist
-> fn_field
.fcontext
= 0;
1992 /* Figure out from whence this virtual function came.
1993 It may belong to virtual function table of
1994 one of its baseclasses. */
1995 look_ahead_type
= read_type (pp
, objfile
);
1998 /* g++ version 1 overloaded methods. */
2002 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2011 look_ahead_type
= NULL
;
2017 /* static member function. */
2018 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2019 if (strncmp (new_sublist
-> fn_field
.physname
,
2020 main_fn_name
, strlen (main_fn_name
)))
2022 new_sublist
-> fn_field
.is_stub
= 1;
2028 complain (&member_fn_complaint
, (*pp
)[-1]);
2029 /* Fall through into normal member function. */
2032 /* normal member function. */
2033 new_sublist
-> fn_field
.voffset
= 0;
2034 new_sublist
-> fn_field
.fcontext
= 0;
2038 new_sublist
-> next
= sublist
;
2039 sublist
= new_sublist
;
2041 STABS_CONTINUE (pp
);
2043 while (**pp
!= ';' && **pp
!= '\0');
2047 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2048 obstack_alloc (&objfile
-> type_obstack
,
2049 sizeof (struct fn_field
) * length
);
2050 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2051 sizeof (struct fn_field
) * length
);
2052 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2054 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2057 new_fnlist
-> fn_fieldlist
.length
= length
;
2058 new_fnlist
-> next
= fip
-> fnlist
;
2059 fip
-> fnlist
= new_fnlist
;
2061 total_length
+= length
;
2062 STABS_CONTINUE (pp
);
2067 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2068 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2069 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2070 memset (TYPE_FN_FIELDLISTS (type
), 0,
2071 sizeof (struct fn_fieldlist
) * nfn_fields
);
2072 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2073 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2079 /* Special GNU C++ name.
2081 Returns 1 for success, 0 for failure. "failure" means that we can't
2082 keep parsing and it's time for error_type(). */
2085 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2086 struct field_info
*fip
;
2089 struct objfile
*objfile
;
2094 struct type
*context
;
2104 /* At this point, *pp points to something like "22:23=*22...",
2105 where the type number before the ':' is the "context" and
2106 everything after is a regular type definition. Lookup the
2107 type, find it's name, and construct the field name. */
2109 context
= read_type (pp
, objfile
);
2113 case 'f': /* $vf -- a virtual function table pointer */
2114 fip
->list
->field
.name
=
2115 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2118 case 'b': /* $vb -- a virtual bsomethingorother */
2119 name
= type_name_no_tag (context
);
2122 complain (&invalid_cpp_type_complaint
, symnum
);
2125 fip
->list
->field
.name
=
2126 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2130 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2131 fip
->list
->field
.name
=
2132 obconcat (&objfile
->type_obstack
,
2133 "INVALID_CPLUSPLUS_ABBREV", "", "");
2137 /* At this point, *pp points to the ':'. Skip it and read the
2143 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2146 fip
->list
->field
.type
= read_type (pp
, objfile
);
2148 (*pp
)++; /* Skip the comma. */
2154 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2158 /* This field is unpacked. */
2159 fip
->list
->field
.bitsize
= 0;
2160 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2164 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2165 /* We have no idea what syntax an unrecognized abbrev would have, so
2166 better return 0. If we returned 1, we would need to at least advance
2167 *pp to avoid an infinite loop. */
2174 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2175 struct field_info
*fip
;
2179 struct objfile
*objfile
;
2181 fip
-> list
-> field
.name
=
2182 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2185 /* This means we have a visibility for a field coming. */
2189 fip
-> list
-> visibility
= *(*pp
)++;
2193 /* normal dbx-style format, no explicit visibility */
2194 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2197 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2202 /* Possible future hook for nested types. */
2205 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2211 /* Static class member. */
2212 fip
-> list
-> field
.bitpos
= (long) -1;
2218 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2222 else if (**pp
!= ',')
2224 /* Bad structure-type format. */
2225 complain (&stabs_general_complaint
, "bad structure-type format");
2229 (*pp
)++; /* Skip the comma. */
2233 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2236 complain (&stabs_general_complaint
, "bad structure-type format");
2239 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2242 complain (&stabs_general_complaint
, "bad structure-type format");
2247 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2249 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2250 it is a field which has been optimized out. The correct stab for
2251 this case is to use VISIBILITY_IGNORE, but that is a recent
2252 invention. (2) It is a 0-size array. For example
2253 union { int num; char str[0]; } foo. Printing "<no value>" for
2254 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2255 will continue to work, and a 0-size array as a whole doesn't
2256 have any contents to print.
2258 I suspect this probably could also happen with gcc -gstabs (not
2259 -gstabs+) for static fields, and perhaps other C++ extensions.
2260 Hopefully few people use -gstabs with gdb, since it is intended
2261 for dbx compatibility. */
2263 /* Ignore this field. */
2264 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2268 /* Detect an unpacked field and mark it as such.
2269 dbx gives a bit size for all fields.
2270 Note that forward refs cannot be packed,
2271 and treat enums as if they had the width of ints. */
2273 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2274 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2276 fip
-> list
-> field
.bitsize
= 0;
2278 if ((fip
-> list
-> field
.bitsize
2279 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2280 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2281 && (fip
-> list
-> field
.bitsize
2286 fip
-> list
-> field
.bitpos
% 8 == 0)
2288 fip
-> list
-> field
.bitsize
= 0;
2294 /* Read struct or class data fields. They have the form:
2296 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2298 At the end, we see a semicolon instead of a field.
2300 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2303 The optional VISIBILITY is one of:
2305 '/0' (VISIBILITY_PRIVATE)
2306 '/1' (VISIBILITY_PROTECTED)
2307 '/2' (VISIBILITY_PUBLIC)
2308 '/9' (VISIBILITY_IGNORE)
2310 or nothing, for C style fields with public visibility.
2312 Returns 1 for success, 0 for failure. */
2315 read_struct_fields (fip
, pp
, type
, objfile
)
2316 struct field_info
*fip
;
2319 struct objfile
*objfile
;
2322 struct nextfield
*new;
2324 /* We better set p right now, in case there are no fields at all... */
2328 /* Read each data member type until we find the terminating ';' at the end of
2329 the data member list, or break for some other reason such as finding the
2330 start of the member function list. */
2334 STABS_CONTINUE (pp
);
2335 /* Get space to record the next field's data. */
2336 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2337 make_cleanup (free
, new);
2338 memset (new, 0, sizeof (struct nextfield
));
2339 new -> next
= fip
-> list
;
2342 /* Get the field name. */
2345 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2346 unless the CPLUS_MARKER is followed by an underscore, in
2347 which case it is just the name of an anonymous type, which we
2348 should handle like any other type name. We accept either '$'
2349 or '.', because a field name can never contain one of these
2350 characters except as a CPLUS_MARKER (we probably should be
2351 doing that in most parts of GDB). */
2353 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2355 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2360 /* Look for the ':' that separates the field name from the field
2361 values. Data members are delimited by a single ':', while member
2362 functions are delimited by a pair of ':'s. When we hit the member
2363 functions (if any), terminate scan loop and return. */
2365 while (*p
!= ':' && *p
!= '\0')
2372 /* Check to see if we have hit the member functions yet. */
2377 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2379 if (p
[0] == ':' && p
[1] == ':')
2381 /* chill the list of fields: the last entry (at the head) is a
2382 partially constructed entry which we now scrub. */
2383 fip
-> list
= fip
-> list
-> next
;
2388 /* The stabs for C++ derived classes contain baseclass information which
2389 is marked by a '!' character after the total size. This function is
2390 called when we encounter the baseclass marker, and slurps up all the
2391 baseclass information.
2393 Immediately following the '!' marker is the number of base classes that
2394 the class is derived from, followed by information for each base class.
2395 For each base class, there are two visibility specifiers, a bit offset
2396 to the base class information within the derived class, a reference to
2397 the type for the base class, and a terminating semicolon.
2399 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2401 Baseclass information marker __________________|| | | | | | |
2402 Number of baseclasses __________________________| | | | | | |
2403 Visibility specifiers (2) ________________________| | | | | |
2404 Offset in bits from start of class _________________| | | | |
2405 Type number for base class ___________________________| | | |
2406 Visibility specifiers (2) _______________________________| | |
2407 Offset in bits from start of class ________________________| |
2408 Type number of base class ____________________________________|
2410 Return 1 for success, 0 for (error-type-inducing) failure. */
2413 read_baseclasses (fip
, pp
, type
, objfile
)
2414 struct field_info
*fip
;
2417 struct objfile
*objfile
;
2420 struct nextfield
*new;
2428 /* Skip the '!' baseclass information marker. */
2432 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2435 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2441 /* Some stupid compilers have trouble with the following, so break
2442 it up into simpler expressions. */
2443 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2444 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2447 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2450 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2451 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2455 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2457 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2459 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2460 make_cleanup (free
, new);
2461 memset (new, 0, sizeof (struct nextfield
));
2462 new -> next
= fip
-> list
;
2464 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2466 STABS_CONTINUE (pp
);
2470 /* Nothing to do. */
2473 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2476 /* Unknown character. Complain and treat it as non-virtual. */
2478 static struct complaint msg
= {
2479 "Unknown virtual character `%c' for baseclass", 0, 0};
2480 complain (&msg
, **pp
);
2485 new -> visibility
= *(*pp
)++;
2486 switch (new -> visibility
)
2488 case VISIBILITY_PRIVATE
:
2489 case VISIBILITY_PROTECTED
:
2490 case VISIBILITY_PUBLIC
:
2493 /* Bad visibility format. Complain and treat it as
2496 static struct complaint msg
= {
2497 "Unknown visibility `%c' for baseclass", 0, 0};
2498 complain (&msg
, new -> visibility
);
2499 new -> visibility
= VISIBILITY_PUBLIC
;
2506 /* The remaining value is the bit offset of the portion of the object
2507 corresponding to this baseclass. Always zero in the absence of
2508 multiple inheritance. */
2510 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2515 /* The last piece of baseclass information is the type of the
2516 base class. Read it, and remember it's type name as this
2519 new -> field
.type
= read_type (pp
, objfile
);
2520 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2522 /* skip trailing ';' and bump count of number of fields seen */
2531 /* The tail end of stabs for C++ classes that contain a virtual function
2532 pointer contains a tilde, a %, and a type number.
2533 The type number refers to the base class (possibly this class itself) which
2534 contains the vtable pointer for the current class.
2536 This function is called when we have parsed all the method declarations,
2537 so we can look for the vptr base class info. */
2540 read_tilde_fields (fip
, pp
, type
, objfile
)
2541 struct field_info
*fip
;
2544 struct objfile
*objfile
;
2548 STABS_CONTINUE (pp
);
2550 /* If we are positioned at a ';', then skip it. */
2560 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2562 /* Obsolete flags that used to indicate the presence
2563 of constructors and/or destructors. */
2567 /* Read either a '%' or the final ';'. */
2568 if (*(*pp
)++ == '%')
2570 /* The next number is the type number of the base class
2571 (possibly our own class) which supplies the vtable for
2572 this class. Parse it out, and search that class to find
2573 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2574 and TYPE_VPTR_FIELDNO. */
2579 t
= read_type (pp
, objfile
);
2581 while (*p
!= '\0' && *p
!= ';')
2587 /* Premature end of symbol. */
2591 TYPE_VPTR_BASETYPE (type
) = t
;
2592 if (type
== t
) /* Our own class provides vtbl ptr */
2594 for (i
= TYPE_NFIELDS (t
) - 1;
2595 i
>= TYPE_N_BASECLASSES (t
);
2598 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2599 sizeof (vptr_name
) - 1))
2601 TYPE_VPTR_FIELDNO (type
) = i
;
2605 /* Virtual function table field not found. */
2606 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2611 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2622 attach_fn_fields_to_type (fip
, type
)
2623 struct field_info
*fip
;
2624 register struct type
*type
;
2628 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2630 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2632 /* @@ Memory leak on objfile -> type_obstack? */
2635 TYPE_NFN_FIELDS_TOTAL (type
) +=
2636 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2639 for (n
= TYPE_NFN_FIELDS (type
);
2640 fip
-> fnlist
!= NULL
;
2641 fip
-> fnlist
= fip
-> fnlist
-> next
)
2643 --n
; /* Circumvent Sun3 compiler bug */
2644 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2649 /* Create the vector of fields, and record how big it is.
2650 We need this info to record proper virtual function table information
2651 for this class's virtual functions. */
2654 attach_fields_to_type (fip
, type
, objfile
)
2655 struct field_info
*fip
;
2656 register struct type
*type
;
2657 struct objfile
*objfile
;
2659 register int nfields
= 0;
2660 register int non_public_fields
= 0;
2661 register struct nextfield
*scan
;
2663 /* Count up the number of fields that we have, as well as taking note of
2664 whether or not there are any non-public fields, which requires us to
2665 allocate and build the private_field_bits and protected_field_bits
2668 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2671 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2673 non_public_fields
++;
2677 /* Now we know how many fields there are, and whether or not there are any
2678 non-public fields. Record the field count, allocate space for the
2679 array of fields, and create blank visibility bitfields if necessary. */
2681 TYPE_NFIELDS (type
) = nfields
;
2682 TYPE_FIELDS (type
) = (struct field
*)
2683 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2684 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2686 if (non_public_fields
)
2688 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2690 TYPE_FIELD_PRIVATE_BITS (type
) =
2691 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2692 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2694 TYPE_FIELD_PROTECTED_BITS (type
) =
2695 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2696 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2698 TYPE_FIELD_IGNORE_BITS (type
) =
2699 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2700 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2703 /* Copy the saved-up fields into the field vector. Start from the head
2704 of the list, adding to the tail of the field array, so that they end
2705 up in the same order in the array in which they were added to the list. */
2707 while (nfields
-- > 0)
2709 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2710 switch (fip
-> list
-> visibility
)
2712 case VISIBILITY_PRIVATE
:
2713 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2716 case VISIBILITY_PROTECTED
:
2717 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2720 case VISIBILITY_IGNORE
:
2721 SET_TYPE_FIELD_IGNORE (type
, nfields
);
2724 case VISIBILITY_PUBLIC
:
2728 /* Unknown visibility. Complain and treat it as public. */
2730 static struct complaint msg
= {
2731 "Unknown visibility `%c' for field", 0, 0};
2732 complain (&msg
, fip
-> list
-> visibility
);
2736 fip
-> list
= fip
-> list
-> next
;
2741 /* Read the description of a structure (or union type) and return an object
2742 describing the type.
2744 PP points to a character pointer that points to the next unconsumed token
2745 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2746 *PP will point to "4a:1,0,32;;".
2748 TYPE points to an incomplete type that needs to be filled in.
2750 OBJFILE points to the current objfile from which the stabs information is
2751 being read. (Note that it is redundant in that TYPE also contains a pointer
2752 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2755 static struct type
*
2756 read_struct_type (pp
, type
, objfile
)
2759 struct objfile
*objfile
;
2761 struct cleanup
*back_to
;
2762 struct field_info fi
;
2767 back_to
= make_cleanup (null_cleanup
, 0);
2769 INIT_CPLUS_SPECIFIC (type
);
2770 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2772 /* First comes the total size in bytes. */
2776 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2778 return error_type (pp
);
2781 /* Now read the baseclasses, if any, read the regular C struct or C++
2782 class member fields, attach the fields to the type, read the C++
2783 member functions, attach them to the type, and then read any tilde
2784 field (baseclass specifier for the class holding the main vtable). */
2786 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2787 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2788 || !attach_fields_to_type (&fi
, type
, objfile
)
2789 || !read_member_functions (&fi
, pp
, type
, objfile
)
2790 || !attach_fn_fields_to_type (&fi
, type
)
2791 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2793 do_cleanups (back_to
);
2794 return (error_type (pp
));
2797 do_cleanups (back_to
);
2801 /* Read a definition of an array type,
2802 and create and return a suitable type object.
2803 Also creates a range type which represents the bounds of that
2806 static struct type
*
2807 read_array_type (pp
, type
, objfile
)
2809 register struct type
*type
;
2810 struct objfile
*objfile
;
2812 struct type
*index_type
, *element_type
, *range_type
;
2817 /* Format of an array type:
2818 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2821 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2822 for these, produce a type like float[][]. */
2824 index_type
= read_type (pp
, objfile
);
2826 /* Improper format of array type decl. */
2827 return error_type (pp
);
2830 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2835 lower
= read_huge_number (pp
, ';', &nbits
);
2837 return error_type (pp
);
2839 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2844 upper
= read_huge_number (pp
, ';', &nbits
);
2846 return error_type (pp
);
2848 element_type
= read_type (pp
, objfile
);
2857 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2858 type
= create_array_type (type
, element_type
, range_type
);
2860 /* If we have an array whose element type is not yet known, but whose
2861 bounds *are* known, record it to be adjusted at the end of the file. */
2862 /* FIXME: Why check for zero length rather than TYPE_FLAG_STUB? I think
2863 the two have the same effect except that the latter is cleaner and the
2864 former would be wrong for types which really are zero-length (if we
2867 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2869 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
2870 add_undefined_type (type
);
2877 /* Read a definition of an enumeration type,
2878 and create and return a suitable type object.
2879 Also defines the symbols that represent the values of the type. */
2881 static struct type
*
2882 read_enum_type (pp
, type
, objfile
)
2884 register struct type
*type
;
2885 struct objfile
*objfile
;
2890 register struct symbol
*sym
;
2892 struct pending
**symlist
;
2893 struct pending
*osyms
, *syms
;
2897 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2898 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2899 to do? For now, force all enum values to file scope. */
2900 if (within_function
)
2901 symlist
= &local_symbols
;
2904 symlist
= &file_symbols
;
2906 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2908 /* Read the value-names and their values.
2909 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2910 A semicolon or comma instead of a NAME means the end. */
2911 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2914 STABS_CONTINUE (pp
);
2916 while (*p
!= ':') p
++;
2917 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2919 n
= read_huge_number (pp
, ',', &nbits
);
2921 return error_type (pp
);
2923 sym
= (struct symbol
*)
2924 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2925 memset (sym
, 0, sizeof (struct symbol
));
2926 SYMBOL_NAME (sym
) = name
;
2927 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
2928 SYMBOL_CLASS (sym
) = LOC_CONST
;
2929 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2930 SYMBOL_VALUE (sym
) = n
;
2931 add_symbol_to_list (sym
, symlist
);
2936 (*pp
)++; /* Skip the semicolon. */
2938 /* Now fill in the fields of the type-structure. */
2940 TYPE_LENGTH (type
) = sizeof (int);
2941 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2942 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2943 TYPE_NFIELDS (type
) = nsyms
;
2944 TYPE_FIELDS (type
) = (struct field
*)
2945 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2946 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2948 /* Find the symbols for the values and put them into the type.
2949 The symbols can be found in the symlist that we put them on
2950 to cause them to be defined. osyms contains the old value
2951 of that symlist; everything up to there was defined by us. */
2952 /* Note that we preserve the order of the enum constants, so
2953 that in something like "enum {FOO, LAST_THING=FOO}" we print
2954 FOO, not LAST_THING. */
2956 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2961 for (; j
< syms
->nsyms
; j
++,n
++)
2963 struct symbol
*xsym
= syms
->symbol
[j
];
2964 SYMBOL_TYPE (xsym
) = type
;
2965 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2966 TYPE_FIELD_VALUE (type
, n
) = 0;
2967 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2968 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2975 /* This screws up perfectly good C programs with enums. FIXME. */
2976 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2977 if(TYPE_NFIELDS(type
) == 2 &&
2978 ((STREQ(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2979 STREQ(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2980 (STREQ(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2981 STREQ(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2982 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2988 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2989 typedefs in every file (for int, long, etc):
2991 type = b <signed> <width>; <offset>; <nbits>
2992 signed = u or s. Possible c in addition to u or s (for char?).
2993 offset = offset from high order bit to start bit of type.
2994 width is # bytes in object of this type, nbits is # bits in type.
2996 The width/offset stuff appears to be for small objects stored in
2997 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3000 static struct type
*
3001 read_sun_builtin_type (pp
, typenums
, objfile
)
3004 struct objfile
*objfile
;
3019 return error_type (pp
);
3023 /* For some odd reason, all forms of char put a c here. This is strange
3024 because no other type has this honor. We can safely ignore this because
3025 we actually determine 'char'acterness by the number of bits specified in
3031 /* The first number appears to be the number of bytes occupied
3032 by this type, except that unsigned short is 4 instead of 2.
3033 Since this information is redundant with the third number,
3034 we will ignore it. */
3035 read_huge_number (pp
, ';', &nbits
);
3037 return error_type (pp
);
3039 /* The second number is always 0, so ignore it too. */
3040 read_huge_number (pp
, ';', &nbits
);
3042 return error_type (pp
);
3044 /* The third number is the number of bits for this type. */
3045 type_bits
= read_huge_number (pp
, 0, &nbits
);
3047 return error_type (pp
);
3049 return init_type (type_bits
== 0 ? TYPE_CODE_VOID
: TYPE_CODE_INT
,
3050 type_bits
/ TARGET_CHAR_BIT
,
3051 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3055 static struct type
*
3056 read_sun_floating_type (pp
, typenums
, objfile
)
3059 struct objfile
*objfile
;
3065 /* The first number has more details about the type, for example
3067 details
= read_huge_number (pp
, ';', &nbits
);
3069 return error_type (pp
);
3071 /* The second number is the number of bytes occupied by this type */
3072 nbytes
= read_huge_number (pp
, ';', &nbits
);
3074 return error_type (pp
);
3076 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3077 || details
== NF_COMPLEX32
)
3078 /* This is a type we can't handle, but we do know the size.
3079 We also will be able to give it a name. */
3080 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3082 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3085 /* Read a number from the string pointed to by *PP.
3086 The value of *PP is advanced over the number.
3087 If END is nonzero, the character that ends the
3088 number must match END, or an error happens;
3089 and that character is skipped if it does match.
3090 If END is zero, *PP is left pointing to that character.
3092 If the number fits in a long, set *BITS to 0 and return the value.
3093 If not, set *BITS to be the number of bits in the number and return 0.
3095 If encounter garbage, set *BITS to -1 and return 0. */
3098 read_huge_number (pp
, end
, bits
)
3118 /* Leading zero means octal. GCC uses this to output values larger
3119 than an int (because that would be hard in decimal). */
3126 upper_limit
= LONG_MAX
/ radix
;
3127 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3129 if (n
<= upper_limit
)
3132 n
+= c
- '0'; /* FIXME this overflows anyway */
3137 /* This depends on large values being output in octal, which is
3144 /* Ignore leading zeroes. */
3148 else if (c
== '2' || c
== '3')
3174 /* Large decimal constants are an error (because it is hard to
3175 count how many bits are in them). */
3181 /* -0x7f is the same as 0x80. So deal with it by adding one to
3182 the number of bits. */
3194 /* It's *BITS which has the interesting information. */
3198 static struct type
*
3199 read_range_type (pp
, typenums
, objfile
)
3202 struct objfile
*objfile
;
3208 struct type
*result_type
;
3209 struct type
*index_type
;
3211 /* First comes a type we are a subrange of.
3212 In C it is usually 0, 1 or the type being defined. */
3213 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3214 not just a type number. */
3215 if (read_type_number (pp
, rangenums
) != 0)
3216 return error_type (pp
);
3217 self_subrange
= (rangenums
[0] == typenums
[0] &&
3218 rangenums
[1] == typenums
[1]);
3220 /* A semicolon should now follow; skip it. */
3224 /* The remaining two operands are usually lower and upper bounds
3225 of the range. But in some special cases they mean something else. */
3226 n2
= read_huge_number (pp
, ';', &n2bits
);
3227 n3
= read_huge_number (pp
, ';', &n3bits
);
3229 if (n2bits
== -1 || n3bits
== -1)
3230 return error_type (pp
);
3232 /* If limits are huge, must be large integral type. */
3233 if (n2bits
!= 0 || n3bits
!= 0)
3235 char got_signed
= 0;
3236 char got_unsigned
= 0;
3237 /* Number of bits in the type. */
3240 /* Range from 0 to <large number> is an unsigned large integral type. */
3241 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3246 /* Range from <large number> to <large number>-1 is a large signed
3247 integral type. Take care of the case where <large number> doesn't
3248 fit in a long but <large number>-1 does. */
3249 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3250 || (n2bits
!= 0 && n3bits
== 0
3251 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3258 if (got_signed
|| got_unsigned
)
3260 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3261 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3265 return error_type (pp
);
3268 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3269 if (self_subrange
&& n2
== 0 && n3
== 0)
3270 return init_type (TYPE_CODE_VOID
, 0, 0, NULL
, objfile
);
3272 /* If n3 is zero and n2 is not, we want a floating type,
3273 and n2 is the width in bytes.
3275 Fortran programs appear to use this for complex types also,
3276 and they give no way to distinguish between double and single-complex!
3278 GDB does not have complex types.
3280 Just return the complex as a float of that size. It won't work right
3281 for the complex values, but at least it makes the file loadable. */
3283 if (n3
== 0 && n2
> 0)
3285 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3288 /* If the upper bound is -1, it must really be an unsigned int. */
3290 else if (n2
== 0 && n3
== -1)
3292 /* It is unsigned int or unsigned long. */
3293 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3294 compatibility hack. */
3295 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3296 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3299 /* Special case: char is defined (Who knows why) as a subrange of
3300 itself with range 0-127. */
3301 else if (self_subrange
&& n2
== 0 && n3
== 127)
3302 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3304 /* We used to do this only for subrange of self or subrange of int. */
3308 /* n3 actually gives the size. */
3309 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3312 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3314 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3316 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3317 "unsigned long", and we already checked for that,
3318 so don't need to test for it here. */
3320 /* I think this is for Convex "long long". Since I don't know whether
3321 Convex sets self_subrange, I also accept that particular size regardless
3322 of self_subrange. */
3323 else if (n3
== 0 && n2
< 0
3325 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3326 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3327 else if (n2
== -n3
-1)
3330 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3332 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3333 if (n3
== 0x7fffffff)
3334 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3337 /* We have a real range type on our hands. Allocate space and
3338 return a real pointer. */
3340 /* At this point I don't have the faintest idea how to deal with
3341 a self_subrange type; I'm going to assume that this is used
3342 as an idiom, and that all of them are special cases. So . . . */
3344 return error_type (pp
);
3346 index_type
= *dbx_lookup_type (rangenums
);
3347 if (index_type
== NULL
)
3349 /* Does this actually ever happen? Is that why we are worrying
3350 about dealing with it rather than just calling error_type? */
3352 static struct type
*range_type_index
;
3354 complain (&range_type_base_complaint
, rangenums
[1]);
3355 if (range_type_index
== NULL
)
3357 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3358 0, "range type index type", NULL
);
3359 index_type
= range_type_index
;
3362 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3363 return (result_type
);
3366 /* Read in an argument list. This is a list of types, separated by commas
3367 and terminated with END. Return the list of types read in, or (struct type
3368 **)-1 if there is an error. */
3370 static struct type
**
3371 read_args (pp
, end
, objfile
)
3374 struct objfile
*objfile
;
3376 /* FIXME! Remove this arbitrary limit! */
3377 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3383 /* Invalid argument list: no ','. */
3384 return (struct type
**)-1;
3386 STABS_CONTINUE (pp
);
3387 types
[n
++] = read_type (pp
, objfile
);
3389 (*pp
)++; /* get past `end' (the ':' character) */
3393 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3395 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3397 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3398 memset (rval
+ n
, 0, sizeof (struct type
*));
3402 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3404 memcpy (rval
, types
, n
* sizeof (struct type
*));
3408 /* Common block handling. */
3410 /* List of symbols declared since the last BCOMM. This list is a tail
3411 of local_symbols. When ECOMM is seen, the symbols on the list
3412 are noted so their proper addresses can be filled in later,
3413 using the common block base address gotten from the assembler
3416 static struct pending
*common_block
;
3417 static int common_block_i
;
3419 /* Name of the current common block. We get it from the BCOMM instead of the
3420 ECOMM to match IBM documentation (even though IBM puts the name both places
3421 like everyone else). */
3422 static char *common_block_name
;
3424 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3425 to remain after this function returns. */
3428 common_block_start (name
, objfile
)
3430 struct objfile
*objfile
;
3432 if (common_block_name
!= NULL
)
3434 static struct complaint msg
= {
3435 "Invalid symbol data: common block within common block",
3439 common_block
= local_symbols
;
3440 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3441 common_block_name
= obsavestring (name
, strlen (name
),
3442 &objfile
-> symbol_obstack
);
3445 /* Process a N_ECOMM symbol. */
3448 common_block_end (objfile
)
3449 struct objfile
*objfile
;
3451 /* Symbols declared since the BCOMM are to have the common block
3452 start address added in when we know it. common_block and
3453 common_block_i point to the first symbol after the BCOMM in
3454 the local_symbols list; copy the list and hang it off the
3455 symbol for the common block name for later fixup. */
3458 struct pending
*new = 0;
3459 struct pending
*next
;
3462 if (common_block_name
== NULL
)
3464 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
3469 sym
= (struct symbol
*)
3470 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3471 memset (sym
, 0, sizeof (struct symbol
));
3472 SYMBOL_NAME (sym
) = common_block_name
;
3473 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3475 /* Now we copy all the symbols which have been defined since the BCOMM. */
3477 /* Copy all the struct pendings before common_block. */
3478 for (next
= local_symbols
;
3479 next
!= NULL
&& next
!= common_block
;
3482 for (j
= 0; j
< next
->nsyms
; j
++)
3483 add_symbol_to_list (next
->symbol
[j
], &new);
3486 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3487 NULL, it means copy all the local symbols (which we already did
3490 if (common_block
!= NULL
)
3491 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
3492 add_symbol_to_list (common_block
->symbol
[j
], &new);
3494 SYMBOL_NAMESPACE (sym
) = (enum namespace)((long) new);
3496 /* Should we be putting local_symbols back to what it was?
3499 i
= hashname (SYMBOL_NAME (sym
));
3500 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3501 global_sym_chain
[i
] = sym
;
3502 common_block_name
= NULL
;
3505 /* Add a common block's start address to the offset of each symbol
3506 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3507 the common block name). */
3510 fix_common_block (sym
, valu
)
3514 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3515 for ( ; next
; next
= next
->next
)
3518 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3519 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3525 /* What about types defined as forward references inside of a small lexical
3527 /* Add a type to the list of undefined types to be checked through
3528 once this file has been read in. */
3531 add_undefined_type (type
)
3534 if (undef_types_length
== undef_types_allocated
)
3536 undef_types_allocated
*= 2;
3537 undef_types
= (struct type
**)
3538 xrealloc ((char *) undef_types
,
3539 undef_types_allocated
* sizeof (struct type
*));
3541 undef_types
[undef_types_length
++] = type
;
3544 /* Go through each undefined type, see if it's still undefined, and fix it
3545 up if possible. We have two kinds of undefined types:
3547 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3548 Fix: update array length using the element bounds
3549 and the target type's length.
3550 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3551 yet defined at the time a pointer to it was made.
3552 Fix: Do a full lookup on the struct/union tag. */
3554 cleanup_undefined_types ()
3558 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3560 switch (TYPE_CODE (*type
))
3563 case TYPE_CODE_STRUCT
:
3564 case TYPE_CODE_UNION
:
3565 case TYPE_CODE_ENUM
:
3567 /* Check if it has been defined since. Need to do this here
3568 as well as in check_stub_type to deal with the (legitimate in
3569 C though not C++) case of several types with the same name
3570 in different source files. */
3571 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3573 struct pending
*ppt
;
3575 /* Name of the type, without "struct" or "union" */
3576 char *typename
= TYPE_TAG_NAME (*type
);
3578 if (typename
== NULL
)
3580 static struct complaint msg
= {"need a type name", 0, 0};
3584 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3586 for (i
= 0; i
< ppt
->nsyms
; i
++)
3588 struct symbol
*sym
= ppt
->symbol
[i
];
3590 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3591 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3592 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3594 && STREQ (SYMBOL_NAME (sym
), typename
))
3596 memcpy (*type
, SYMBOL_TYPE (sym
),
3597 sizeof (struct type
));
3605 case TYPE_CODE_ARRAY
:
3607 /* This is a kludge which is here for historical reasons
3608 because I suspect that check_stub_type does not get
3609 called everywhere it needs to be called for arrays. Even
3610 with this kludge, those places are broken for the case
3611 where the stub type is defined in another compilation
3612 unit, but this kludge at least deals with it for the case
3613 in which it is the same compilation unit.
3615 Don't try to do this by calling check_stub_type; it might
3616 cause symbols to be read in lookup_symbol, and the symbol
3617 reader is not reentrant. */
3619 struct type
*range_type
;
3622 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3624 if (TYPE_NFIELDS (*type
) != 1)
3626 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3627 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3630 /* Now recompute the length of the array type, based on its
3631 number of elements and the target type's length. */
3632 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3633 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3634 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3635 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3637 /* If the target type is not a stub, we could be clearing
3638 TYPE_FLAG_TARGET_STUB for *type. */
3645 static struct complaint msg
= {"\
3646 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3647 complain (&msg
, TYPE_CODE (*type
));
3653 undef_types_length
= 0;
3656 /* Scan through all of the global symbols defined in the object file,
3657 assigning values to the debugging symbols that need to be assigned
3658 to. Get these symbols from the minimal symbol table. */
3661 scan_file_globals (objfile
)
3662 struct objfile
*objfile
;
3665 struct minimal_symbol
*msymbol
;
3666 struct symbol
*sym
, *prev
;
3668 if (objfile
->msymbols
== 0) /* Beware the null file. */
3671 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3677 /* Get the hash index and check all the symbols
3678 under that hash index. */
3680 hash
= hashname (SYMBOL_NAME (msymbol
));
3682 for (sym
= global_sym_chain
[hash
]; sym
;)
3684 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3685 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3687 /* Splice this symbol out of the hash chain and
3688 assign the value we have to it. */
3691 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3695 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3698 /* Check to see whether we need to fix up a common block. */
3699 /* Note: this code might be executed several times for
3700 the same symbol if there are multiple references. */
3702 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3704 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3708 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3713 sym
= SYMBOL_VALUE_CHAIN (prev
);
3717 sym
= global_sym_chain
[hash
];
3723 sym
= SYMBOL_VALUE_CHAIN (sym
);
3729 /* Initialize anything that needs initializing when starting to read
3730 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3738 /* Initialize anything that needs initializing when a completely new
3739 symbol file is specified (not just adding some symbols from another
3740 file, e.g. a shared library). */
3743 stabsread_new_init ()
3745 /* Empty the hash table of global syms looking for values. */
3746 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3749 /* Initialize anything that needs initializing at the same time as
3750 start_symtab() is called. */
3754 global_stabs
= NULL
; /* AIX COFF */
3755 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3756 n_this_object_header_files
= 1;
3757 type_vector_length
= 0;
3758 type_vector
= (struct type
**) 0;
3760 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3761 common_block_name
= NULL
;
3764 /* Call after end_symtab() */
3770 free ((char *) type_vector
);
3773 type_vector_length
= 0;
3774 previous_stab_code
= 0;
3778 finish_global_stabs (objfile
)
3779 struct objfile
*objfile
;
3783 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3784 free ((PTR
) global_stabs
);
3785 global_stabs
= NULL
;
3789 /* Initializer for this module */
3792 _initialize_stabsread ()
3794 undef_types_allocated
= 20;
3795 undef_types_length
= 0;
3796 undef_types
= (struct type
**)
3797 xmalloc (undef_types_allocated
* sizeof (struct type
*));