1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, 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. */
28 #include "gdb_string.h"
35 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
37 #include "aout/aout64.h"
38 #include "gdb-stabs.h"
40 #include "complaints.h"
45 /* Ask stabsread.h to define the vars it normally declares `extern'. */
47 #include "stabsread.h" /* Our own declarations */
50 /* The routines that read and process a complete stabs for a C struct or
51 C++ class pass lists of data member fields and lists of member function
52 fields in an instance of a field_info structure, as defined below.
53 This is part of some reorganization of low level C++ support and is
54 expected to eventually go away... (FIXME) */
60 struct nextfield
*next
;
62 /* This is the raw visibility from the stab. It is not checked
63 for being one of the visibilities we recognize, so code which
64 examines this field better be able to deal. */
69 struct next_fnfieldlist
71 struct next_fnfieldlist
*next
;
72 struct fn_fieldlist fn_fieldlist
;
77 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
79 static long read_huge_number
PARAMS ((char **, int, int *));
81 static struct type
*error_type
PARAMS ((char **));
84 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
88 fix_common_block
PARAMS ((struct symbol
*, int));
91 read_type_number
PARAMS ((char **, int *));
94 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
97 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
100 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
103 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
106 rs6000_builtin_type
PARAMS ((int));
109 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
113 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
117 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
121 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
125 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
128 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
132 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
135 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
137 static struct type
**
138 read_args
PARAMS ((char **, int, struct objfile
*));
141 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
144 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
145 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
147 /* Define this as 1 if a pcc declaration of a char or short argument
148 gives the correct address. Otherwise assume pcc gives the
149 address of the corresponding int, which is not the same on a
150 big-endian machine. */
152 #ifndef BELIEVE_PCC_PROMOTION
153 #define BELIEVE_PCC_PROMOTION 0
156 struct complaint invalid_cpp_abbrev_complaint
=
157 {"invalid C++ abbreviation `%s'", 0, 0};
159 struct complaint invalid_cpp_type_complaint
=
160 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
162 struct complaint member_fn_complaint
=
163 {"member function type missing, got '%c'", 0, 0};
165 struct complaint const_vol_complaint
=
166 {"const/volatile indicator missing, got '%c'", 0, 0};
168 struct complaint error_type_complaint
=
169 {"debug info mismatch between compiler and debugger", 0, 0};
171 struct complaint invalid_member_complaint
=
172 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
174 struct complaint range_type_base_complaint
=
175 {"base type %d of range type is not defined", 0, 0};
177 struct complaint reg_value_complaint
=
178 {"register number too large in symbol %s", 0, 0};
180 struct complaint vtbl_notfound_complaint
=
181 {"virtual function table pointer not found when defining class `%s'", 0, 0};
183 struct complaint unrecognized_cplus_name_complaint
=
184 {"Unknown C++ symbol name `%s'", 0, 0};
186 struct complaint rs6000_builtin_complaint
=
187 {"Unknown builtin type %d", 0, 0};
189 struct complaint unresolved_sym_chain_complaint
=
190 {"%s: `%s' from global_sym_chain unresolved", 0, 0};
192 struct complaint stabs_general_complaint
=
195 /* Make a list of forward references which haven't been defined. */
197 static struct type
**undef_types
;
198 static int undef_types_allocated
;
199 static int undef_types_length
;
201 /* Check for and handle cretinous stabs symbol name continuation! */
202 #define STABS_CONTINUE(pp) \
204 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
205 *(pp) = next_symbol_text (); \
208 /* FIXME: These probably should be our own types (like rs6000_builtin_type
209 has its own types) rather than builtin_type_*. */
210 static struct type
**os9k_type_vector
[] = {
216 &builtin_type_unsigned_char
,
217 &builtin_type_unsigned_short
,
218 &builtin_type_unsigned_long
,
219 &builtin_type_unsigned_int
,
221 &builtin_type_double
,
223 &builtin_type_long_double
226 static void os9k_init_type_vector
PARAMS ((struct type
**));
229 os9k_init_type_vector(tv
)
233 for (i
=0; i
<sizeof(os9k_type_vector
)/sizeof(struct type
**); i
++)
234 tv
[i
] = (os9k_type_vector
[i
] == 0 ? 0 : *(os9k_type_vector
[i
]));
237 /* Look up a dbx type-number pair. Return the address of the slot
238 where the type for that number-pair is stored.
239 The number-pair is in TYPENUMS.
241 This can be used for finding the type associated with that pair
242 or for associating a new type with the pair. */
245 dbx_lookup_type (typenums
)
248 register int filenum
= typenums
[0];
249 register int index
= typenums
[1];
251 register int real_filenum
;
252 register struct header_file
*f
;
255 if (filenum
== -1) /* -1,-1 is for temporary types. */
258 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
260 static struct complaint msg
= {"\
261 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
263 complain (&msg
, filenum
, index
, symnum
);
271 /* Caller wants address of address of type. We think
272 that negative (rs6k builtin) types will never appear as
273 "lvalues", (nor should they), so we stuff the real type
274 pointer into a temp, and return its address. If referenced,
275 this will do the right thing. */
276 static struct type
*temp_type
;
278 temp_type
= rs6000_builtin_type(index
);
282 /* Type is defined outside of header files.
283 Find it in this object file's type vector. */
284 if (index
>= type_vector_length
)
286 old_len
= type_vector_length
;
289 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
290 type_vector
= (struct type
**)
291 malloc (type_vector_length
* sizeof (struct type
*));
293 while (index
>= type_vector_length
)
295 type_vector_length
*= 2;
297 type_vector
= (struct type
**)
298 xrealloc ((char *) type_vector
,
299 (type_vector_length
* sizeof (struct type
*)));
300 memset (&type_vector
[old_len
], 0,
301 (type_vector_length
- old_len
) * sizeof (struct type
*));
304 /* Deal with OS9000 fundamental types. */
305 os9k_init_type_vector (type_vector
);
307 return (&type_vector
[index
]);
311 real_filenum
= this_object_header_files
[filenum
];
313 if (real_filenum
>= n_header_files
)
315 struct type
*temp_type
;
316 struct type
**temp_type_p
;
318 warning ("GDB internal error: bad real_filenum");
321 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
322 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
323 *temp_type_p
= temp_type
;
327 f
= &header_files
[real_filenum
];
329 f_orig_length
= f
->length
;
330 if (index
>= f_orig_length
)
332 while (index
>= f
->length
)
336 f
->vector
= (struct type
**)
337 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
338 memset (&f
->vector
[f_orig_length
], 0,
339 (f
->length
- f_orig_length
) * sizeof (struct type
*));
341 return (&f
->vector
[index
]);
345 /* Make sure there is a type allocated for type numbers TYPENUMS
346 and return the type object.
347 This can create an empty (zeroed) type object.
348 TYPENUMS may be (-1, -1) to return a new type object that is not
349 put into the type vector, and so may not be referred to by number. */
352 dbx_alloc_type (typenums
, objfile
)
354 struct objfile
*objfile
;
356 register struct type
**type_addr
;
358 if (typenums
[0] == -1)
360 return (alloc_type (objfile
));
363 type_addr
= dbx_lookup_type (typenums
);
365 /* If we are referring to a type not known at all yet,
366 allocate an empty type for it.
367 We will fill it in later if we find out how. */
370 *type_addr
= alloc_type (objfile
);
376 /* for all the stabs in a given stab vector, build appropriate types
377 and fix their symbols in given symbol vector. */
380 patch_block_stabs (symbols
, stabs
, objfile
)
381 struct pending
*symbols
;
382 struct pending_stabs
*stabs
;
383 struct objfile
*objfile
;
393 /* for all the stab entries, find their corresponding symbols and
394 patch their types! */
396 for (ii
= 0; ii
< stabs
->count
; ++ii
)
398 name
= stabs
->stab
[ii
];
399 pp
= (char*) strchr (name
, ':');
403 pp
= (char *)strchr(pp
, ':');
405 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
408 /* FIXME-maybe: it would be nice if we noticed whether
409 the variable was defined *anywhere*, not just whether
410 it is defined in this compilation unit. But neither
411 xlc or GCC seem to need such a definition, and until
412 we do psymtabs (so that the minimal symbols from all
413 compilation units are available now), I'm not sure
414 how to get the information. */
416 /* On xcoff, if a global is defined and never referenced,
417 ld will remove it from the executable. There is then
418 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
419 sym
= (struct symbol
*)
420 obstack_alloc (&objfile
->symbol_obstack
,
421 sizeof (struct symbol
));
423 memset (sym
, 0, sizeof (struct symbol
));
424 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
425 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
427 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
429 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
431 /* I don't think the linker does this with functions,
432 so as far as I know this is never executed.
433 But it doesn't hurt to check. */
435 lookup_function_type (read_type (&pp
, objfile
));
439 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
441 add_symbol_to_list (sym
, &global_symbols
);
446 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
449 lookup_function_type (read_type (&pp
, objfile
));
453 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
461 /* Read a number by which a type is referred to in dbx data,
462 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
463 Just a single number N is equivalent to (0,N).
464 Return the two numbers by storing them in the vector TYPENUMS.
465 TYPENUMS will then be used as an argument to dbx_lookup_type.
467 Returns 0 for success, -1 for error. */
470 read_type_number (pp
, typenums
)
472 register int *typenums
;
478 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
479 if (nbits
!= 0) return -1;
480 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
481 if (nbits
!= 0) return -1;
486 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
487 if (nbits
!= 0) return -1;
493 /* To handle GNU C++ typename abbreviation, we need to be able to
494 fill in a type's name as soon as space for that type is allocated.
495 `type_synonym_name' is the name of the type being allocated.
496 It is cleared as soon as it is used (lest all allocated types
499 static char *type_synonym_name
;
501 #if !defined (REG_STRUCT_HAS_ADDR)
502 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
507 define_symbol (valu
, string
, desc
, type
, objfile
)
512 struct objfile
*objfile
;
514 register struct symbol
*sym
;
515 char *p
= (char *) strchr (string
, ':');
520 /* We would like to eliminate nameless symbols, but keep their types.
521 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
522 to type 2, but, should not create a symbol to address that type. Since
523 the symbol will be nameless, there is no way any user can refer to it. */
527 /* Ignore syms with empty names. */
531 /* Ignore old-style symbols from cc -go */
541 /* If a nameless stab entry, all we need is the type, not the symbol.
542 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
543 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
545 sym
= (struct symbol
*)
546 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
547 memset (sym
, 0, sizeof (struct symbol
));
549 switch (type
& N_TYPE
)
552 SYMBOL_SECTION(sym
) = SECT_OFF_TEXT
;
555 SYMBOL_SECTION(sym
) = SECT_OFF_DATA
;
558 SYMBOL_SECTION(sym
) = SECT_OFF_BSS
;
562 if (processing_gcc_compilation
)
564 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
565 number of bytes occupied by a type or object, which we ignore. */
566 SYMBOL_LINE(sym
) = desc
;
570 SYMBOL_LINE(sym
) = 0; /* unknown */
573 if (string
[0] == CPLUS_MARKER
)
575 /* Special GNU C++ names. */
579 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
580 &objfile
-> symbol_obstack
);
583 case 'v': /* $vtbl_ptr_type */
584 /* Was: SYMBOL_NAME (sym) = "vptr"; */
588 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
589 &objfile
-> symbol_obstack
);
593 /* This was an anonymous type that was never fixed up. */
596 #ifdef STATIC_TRANSFORM_NAME
598 /* SunPRO (3.0 at least) static variable encoding. */
603 complain (&unrecognized_cplus_name_complaint
, string
);
604 goto normal
; /* Do *something* with it */
610 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
611 SYMBOL_NAME (sym
) = (char *)
612 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
613 /* Open-coded memcpy--saves function call time. */
614 /* FIXME: Does it really? Try replacing with simple strcpy and
615 try it on an executable with a large symbol table. */
616 /* FIXME: considering that gcc can open code memcpy anyway, I
617 doubt it. xoxorich. */
619 register char *p1
= string
;
620 register char *p2
= SYMBOL_NAME (sym
);
628 /* If this symbol is from a C++ compilation, then attempt to cache the
629 demangled form for future reference. This is a typical time versus
630 space tradeoff, that was decided in favor of time because it sped up
631 C++ symbol lookups by a factor of about 20. */
633 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
637 /* Determine the type of name being defined. */
639 /* Getting GDB to correctly skip the symbol on an undefined symbol
640 descriptor and not ever dump core is a very dodgy proposition if
641 we do things this way. I say the acorn RISC machine can just
642 fix their compiler. */
643 /* The Acorn RISC machine's compiler can put out locals that don't
644 start with "234=" or "(3,4)=", so assume anything other than the
645 deftypes we know how to handle is a local. */
646 if (!strchr ("cfFGpPrStTvVXCR", *p
))
648 if (isdigit (*p
) || *p
== '(' || *p
== '-')
657 /* c is a special case, not followed by a type-number.
658 SYMBOL:c=iVALUE for an integer constant symbol.
659 SYMBOL:c=rVALUE for a floating constant symbol.
660 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
661 e.g. "b:c=e6,0" for "const b = blob1"
662 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
665 SYMBOL_CLASS (sym
) = LOC_CONST
;
666 SYMBOL_TYPE (sym
) = error_type (&p
);
667 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
668 add_symbol_to_list (sym
, &file_symbols
);
679 /* FIXME-if-picky-about-floating-accuracy: Should be using
680 target arithmetic to get the value. real.c in GCC
681 probably has the necessary code. */
683 /* FIXME: lookup_fundamental_type is a hack. We should be
684 creating a type especially for the type of float constants.
685 Problem is, what type should it be?
687 Also, what should the name of this type be? Should we
688 be using 'S' constants (see stabs.texinfo) instead? */
690 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
693 obstack_alloc (&objfile
-> symbol_obstack
,
694 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
695 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
696 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
697 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
702 /* Defining integer constants this way is kind of silly,
703 since 'e' constants allows the compiler to give not
704 only the value, but the type as well. C has at least
705 int, long, unsigned int, and long long as constant
706 types; other languages probably should have at least
707 unsigned as well as signed constants. */
709 /* We just need one int constant type for all objfiles.
710 It doesn't depend on languages or anything (arguably its
711 name should be a language-specific name for a type of
712 that size, but I'm inclined to say that if the compiler
713 wants a nice name for the type, it can use 'e'). */
714 static struct type
*int_const_type
;
716 /* Yes, this is as long as a *host* int. That is because we
718 if (int_const_type
== NULL
)
720 init_type (TYPE_CODE_INT
,
721 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
723 (struct objfile
*)NULL
);
724 SYMBOL_TYPE (sym
) = int_const_type
;
725 SYMBOL_VALUE (sym
) = atoi (p
);
726 SYMBOL_CLASS (sym
) = LOC_CONST
;
730 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
731 can be represented as integral.
732 e.g. "b:c=e6,0" for "const b = blob1"
733 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
735 SYMBOL_CLASS (sym
) = LOC_CONST
;
736 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
740 SYMBOL_TYPE (sym
) = error_type (&p
);
745 /* If the value is too big to fit in an int (perhaps because
746 it is unsigned), or something like that, we silently get
747 a bogus value. The type and everything else about it is
748 correct. Ideally, we should be using whatever we have
749 available for parsing unsigned and long long values,
751 SYMBOL_VALUE (sym
) = atoi (p
);
756 SYMBOL_CLASS (sym
) = LOC_CONST
;
757 SYMBOL_TYPE (sym
) = error_type (&p
);
760 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
761 add_symbol_to_list (sym
, &file_symbols
);
765 /* The name of a caught exception. */
766 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
767 SYMBOL_CLASS (sym
) = LOC_LABEL
;
768 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
769 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
770 add_symbol_to_list (sym
, &local_symbols
);
774 /* A static function definition. */
775 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
776 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
777 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
778 add_symbol_to_list (sym
, &file_symbols
);
779 /* fall into process_function_types. */
781 process_function_types
:
782 /* Function result types are described as the result type in stabs.
783 We need to convert this to the function-returning-type-X type
784 in GDB. E.g. "int" is converted to "function returning int". */
785 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
786 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
787 /* fall into process_prototype_types */
789 process_prototype_types
:
790 /* Sun acc puts declared types of arguments here. We don't care
791 about their actual types (FIXME -- we should remember the whole
792 function prototype), but the list may define some new types
793 that we have to remember, so we must scan it now. */
796 read_type (&p
, objfile
);
801 /* A global function definition. */
802 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
803 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
804 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
805 add_symbol_to_list (sym
, &global_symbols
);
806 goto process_function_types
;
809 /* For a class G (global) symbol, it appears that the
810 value is not correct. It is necessary to search for the
811 corresponding linker definition to find the value.
812 These definitions appear at the end of the namelist. */
813 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
814 i
= hashname (SYMBOL_NAME (sym
));
815 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
816 global_sym_chain
[i
] = sym
;
817 SYMBOL_CLASS (sym
) = LOC_STATIC
;
818 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
819 add_symbol_to_list (sym
, &global_symbols
);
822 /* This case is faked by a conditional above,
823 when there is no code letter in the dbx data.
824 Dbx data never actually contains 'l'. */
827 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
828 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
829 SYMBOL_VALUE (sym
) = valu
;
830 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
831 add_symbol_to_list (sym
, &local_symbols
);
836 /* pF is a two-letter code that means a function parameter in Fortran.
837 The type-number specifies the type of the return value.
838 Translate it into a pointer-to-function type. */
842 = lookup_pointer_type
843 (lookup_function_type (read_type (&p
, objfile
)));
846 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
848 /* Normally this is a parameter, a LOC_ARG. On the i960, it
849 can also be a LOC_LOCAL_ARG depending on symbol type. */
850 #ifndef DBX_PARM_SYMBOL_CLASS
851 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
854 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
855 SYMBOL_VALUE (sym
) = valu
;
856 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
857 add_symbol_to_list (sym
, &local_symbols
);
859 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
861 /* On little-endian machines, this crud is never necessary,
862 and, if the extra bytes contain garbage, is harmful. */
866 /* If it's gcc-compiled, if it says `short', believe it. */
867 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
870 #if !BELIEVE_PCC_PROMOTION
872 /* This is the signed type which arguments get promoted to. */
873 static struct type
*pcc_promotion_type
;
874 /* This is the unsigned type which arguments get promoted to. */
875 static struct type
*pcc_unsigned_promotion_type
;
877 /* Call it "int" because this is mainly C lossage. */
878 if (pcc_promotion_type
== NULL
)
880 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
883 if (pcc_unsigned_promotion_type
== NULL
)
884 pcc_unsigned_promotion_type
=
885 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
886 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
888 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
889 /* This macro is defined on machines (e.g. sparc) where
890 we should believe the type of a PCC 'short' argument,
891 but shouldn't believe the address (the address is
892 the address of the corresponding int).
894 My guess is that this correction, as opposed to changing
895 the parameter to an 'int' (as done below, for PCC
896 on most machines), is the right thing to do
897 on all machines, but I don't want to risk breaking
898 something that already works. On most PCC machines,
899 the sparc problem doesn't come up because the calling
900 function has to zero the top bytes (not knowing whether
901 the called function wants an int or a short), so there
902 is little practical difference between an int and a short
903 (except perhaps what happens when the GDB user types
904 "print short_arg = 0x10000;").
906 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
907 actually produces the correct address (we don't need to fix it
908 up). I made this code adapt so that it will offset the symbol
909 if it was pointing at an int-aligned location and not
910 otherwise. This way you can use the same gdb for 4.0.x and
913 If the parameter is shorter than an int, and is integral
914 (e.g. char, short, or unsigned equivalent), and is claimed to
915 be passed on an integer boundary, don't believe it! Offset the
916 parameter's address to the tail-end of that integer. */
918 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
919 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
920 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
922 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
923 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
927 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
929 /* If PCC says a parameter is a short or a char,
930 it is really an int. */
931 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
932 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
935 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
936 ? pcc_unsigned_promotion_type
937 : pcc_promotion_type
;
941 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
943 #endif /* !BELIEVE_PCC_PROMOTION. */
946 /* acc seems to use P to delare the prototypes of functions that
947 are referenced by this file. gdb is not prepared to deal
948 with this extra information. FIXME, it ought to. */
951 read_type (&p
, objfile
);
952 goto process_prototype_types
;
957 /* Parameter which is in a register. */
958 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
959 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
960 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
961 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
963 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
964 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
966 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
967 add_symbol_to_list (sym
, &local_symbols
);
971 /* Register variable (either global or local). */
972 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
973 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
974 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
975 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
977 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
978 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
980 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
983 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
984 name to represent an argument passed in a register.
985 GCC uses 'P' for the same case. So if we find such a symbol pair
986 we combine it into one 'P' symbol. For Sun cc we need to do this
987 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
988 the 'p' symbol even if it never saves the argument onto the stack.
990 On most machines, we want to preserve both symbols, so that
991 we can still get information about what is going on with the
992 stack (VAX for computing args_printed, using stack slots instead
993 of saved registers in backtraces, etc.).
995 Note that this code illegally combines
996 main(argc) struct foo argc; { register struct foo argc; }
997 but this case is considered pathological and causes a warning
998 from a decent compiler. */
1001 && local_symbols
->nsyms
> 0
1002 #ifndef USE_REGISTER_NOT_ARG
1003 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1005 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1006 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1010 struct symbol
*prev_sym
;
1011 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1012 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1013 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1014 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
1016 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1017 /* Use the type from the LOC_REGISTER; that is the type
1018 that is actually in that register. */
1019 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1020 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1025 add_symbol_to_list (sym
, &local_symbols
);
1028 add_symbol_to_list (sym
, &file_symbols
);
1032 /* Static symbol at top level of file */
1033 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1034 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1035 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1036 #ifdef STATIC_TRANSFORM_NAME
1037 if (SYMBOL_NAME (sym
)[0] == '$')
1039 struct minimal_symbol
*msym
;
1040 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1043 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1044 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1048 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1049 add_symbol_to_list (sym
, &file_symbols
);
1053 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1055 /* For a nameless type, we don't want a create a symbol, thus we
1056 did not use `sym'. Return without further processing. */
1057 if (nameless
) return NULL
;
1059 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1060 SYMBOL_VALUE (sym
) = valu
;
1061 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1062 /* C++ vagaries: we may have a type which is derived from
1063 a base type which did not have its name defined when the
1064 derived class was output. We fill in the derived class's
1065 base part member's name here in that case. */
1066 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1067 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1068 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1069 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1072 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1073 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1074 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1075 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1078 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1080 /* gcc-2.6 or later (when using -fvtable-thunks)
1081 emits a unique named type for a vtable entry.
1082 Some gdb code depends on that specific name. */
1083 extern const char vtbl_ptr_name
[];
1085 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1086 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1087 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1089 /* If we are giving a name to a type such as "pointer to
1090 foo" or "function returning foo", we better not set
1091 the TYPE_NAME. If the program contains "typedef char
1092 *caddr_t;", we don't want all variables of type char
1093 * to print as caddr_t. This is not just a
1094 consequence of GDB's type management; PCC and GCC (at
1095 least through version 2.4) both output variables of
1096 either type char * or caddr_t with the type number
1097 defined in the 't' symbol for caddr_t. If a future
1098 compiler cleans this up it GDB is not ready for it
1099 yet, but if it becomes ready we somehow need to
1100 disable this check (without breaking the PCC/GCC2.4
1105 Fortunately, this check seems not to be necessary
1106 for anything except pointers or functions. */
1109 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1112 add_symbol_to_list (sym
, &file_symbols
);
1116 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1117 by 't' which means we are typedef'ing it as well. */
1118 synonym
= *p
== 't';
1123 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1124 strlen (SYMBOL_NAME (sym
)),
1125 &objfile
-> symbol_obstack
);
1127 /* The semantics of C++ state that "struct foo { ... }" also defines
1128 a typedef for "foo". Unfortunately, cfront never makes the typedef
1129 when translating C++ into C. We make the typedef here so that
1130 "ptype foo" works as expected for cfront translated code. */
1131 else if (current_subfile
->language
== language_cplus
)
1134 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1135 strlen (SYMBOL_NAME (sym
)),
1136 &objfile
-> symbol_obstack
);
1139 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1141 /* For a nameless type, we don't want a create a symbol, thus we
1142 did not use `sym'. Return without further processing. */
1143 if (nameless
) return NULL
;
1145 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1146 SYMBOL_VALUE (sym
) = valu
;
1147 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1148 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1149 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1150 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1151 add_symbol_to_list (sym
, &file_symbols
);
1155 /* Clone the sym and then modify it. */
1156 register struct symbol
*typedef_sym
= (struct symbol
*)
1157 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1158 *typedef_sym
= *sym
;
1159 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1160 SYMBOL_VALUE (typedef_sym
) = valu
;
1161 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1162 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1163 TYPE_NAME (SYMBOL_TYPE (sym
))
1164 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1165 add_symbol_to_list (typedef_sym
, &file_symbols
);
1170 /* Static symbol of local scope */
1171 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1172 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1173 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1174 #ifdef STATIC_TRANSFORM_NAME
1175 if (SYMBOL_NAME (sym
)[0] == '$')
1177 struct minimal_symbol
*msym
;
1178 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1181 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1182 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1186 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1188 add_symbol_to_list (sym
, &global_symbols
);
1190 add_symbol_to_list (sym
, &local_symbols
);
1194 /* Reference parameter */
1195 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1196 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1197 SYMBOL_VALUE (sym
) = valu
;
1198 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1199 add_symbol_to_list (sym
, &local_symbols
);
1203 /* Reference parameter which is in a register. */
1204 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1205 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1206 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1207 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1209 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
1210 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1212 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1213 add_symbol_to_list (sym
, &local_symbols
);
1217 /* This is used by Sun FORTRAN for "function result value".
1218 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1219 that Pascal uses it too, but when I tried it Pascal used
1220 "x:3" (local symbol) instead. */
1221 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1222 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1223 SYMBOL_VALUE (sym
) = valu
;
1224 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1225 add_symbol_to_list (sym
, &local_symbols
);
1229 SYMBOL_TYPE (sym
) = error_type (&p
);
1230 SYMBOL_CLASS (sym
) = LOC_CONST
;
1231 SYMBOL_VALUE (sym
) = 0;
1232 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1233 add_symbol_to_list (sym
, &file_symbols
);
1237 /* When passing structures to a function, some systems sometimes pass
1238 the address in a register, not the structure itself.
1240 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1241 to LOC_REGPARM_ADDR for structures and unions. */
1243 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1244 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1246 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1247 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1248 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1250 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1251 subsequent arguments on the sparc, for example). */
1252 if (SYMBOL_CLASS (sym
) == LOC_ARG
1253 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1255 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1256 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1257 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1263 /* Skip rest of this symbol and return an error type.
1265 General notes on error recovery: error_type always skips to the
1266 end of the symbol (modulo cretinous dbx symbol name continuation).
1267 Thus code like this:
1269 if (*(*pp)++ != ';')
1270 return error_type (pp);
1272 is wrong because if *pp starts out pointing at '\0' (typically as the
1273 result of an earlier error), it will be incremented to point to the
1274 start of the next symbol, which might produce strange results, at least
1275 if you run off the end of the string table. Instead use
1278 return error_type (pp);
1284 foo = error_type (pp);
1288 And in case it isn't obvious, the point of all this hair is so the compiler
1289 can define new types and new syntaxes, and old versions of the
1290 debugger will be able to read the new symbol tables. */
1292 static struct type
*
1296 complain (&error_type_complaint
);
1299 /* Skip to end of symbol. */
1300 while (**pp
!= '\0')
1305 /* Check for and handle cretinous dbx symbol name continuation! */
1306 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1308 *pp
= next_symbol_text ();
1315 return (builtin_type_error
);
1319 /* Read type information or a type definition; return the type. Even
1320 though this routine accepts either type information or a type
1321 definition, the distinction is relevant--some parts of stabsread.c
1322 assume that type information starts with a digit, '-', or '(' in
1323 deciding whether to call read_type. */
1326 read_type (pp
, objfile
)
1328 struct objfile
*objfile
;
1330 register struct type
*type
= 0;
1334 char type_descriptor
;
1336 /* Size in bits of type if specified by a type attribute, or -1 if
1337 there is no size attribute. */
1340 /* Used to distinguish string and bitstring from char-array and set. */
1343 /* Read type number if present. The type number may be omitted.
1344 for instance in a two-dimensional array declared with type
1345 "ar1;1;10;ar1;1;10;4". */
1346 if ((**pp
>= '0' && **pp
<= '9')
1350 if (read_type_number (pp
, typenums
) != 0)
1351 return error_type (pp
);
1353 /* Type is not being defined here. Either it already exists,
1354 or this is a forward reference to it. dbx_alloc_type handles
1357 return dbx_alloc_type (typenums
, objfile
);
1359 /* Type is being defined here. */
1366 /* It might be a type attribute or a member type. */
1367 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1372 /* Type attributes. */
1375 /* Skip to the semicolon. */
1376 while (*p
!= ';' && *p
!= '\0')
1380 return error_type (pp
);
1382 /* Skip the semicolon. */
1388 type_size
= atoi (attr
+ 1);
1398 /* Ignore unrecognized type attributes, so future compilers
1399 can invent new ones. */
1404 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1409 /* 'typenums=' not present, type is anonymous. Read and return
1410 the definition, but don't put it in the type vector. */
1411 typenums
[0] = typenums
[1] = -1;
1415 type_descriptor
= (*pp
)[-1];
1416 switch (type_descriptor
)
1420 enum type_code code
;
1422 /* Used to index through file_symbols. */
1423 struct pending
*ppt
;
1426 /* Name including "struct", etc. */
1430 char *from
, *to
, *p
, *q1
, *q2
;
1432 /* Set the type code according to the following letter. */
1436 code
= TYPE_CODE_STRUCT
;
1439 code
= TYPE_CODE_UNION
;
1442 code
= TYPE_CODE_ENUM
;
1446 /* Complain and keep going, so compilers can invent new
1447 cross-reference types. */
1448 static struct complaint msg
=
1449 {"Unrecognized cross-reference type `%c'", 0, 0};
1450 complain (&msg
, (*pp
)[0]);
1451 code
= TYPE_CODE_STRUCT
;
1456 q1
= strchr(*pp
, '<');
1457 p
= strchr(*pp
, ':');
1459 return error_type (pp
);
1460 while (q1
&& p
> q1
&& p
[1] == ':')
1462 q2
= strchr(q1
, '>');
1468 return error_type (pp
);
1471 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1473 /* Copy the name. */
1479 /* Set the pointer ahead of the name which we just read, and
1484 /* Now check to see whether the type has already been
1485 declared. This was written for arrays of cross-referenced
1486 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1487 sure it is not necessary anymore. But it might be a good
1488 idea, to save a little memory. */
1490 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1491 for (i
= 0; i
< ppt
->nsyms
; i
++)
1493 struct symbol
*sym
= ppt
->symbol
[i
];
1495 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1496 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1497 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1498 && STREQ (SYMBOL_NAME (sym
), type_name
))
1500 obstack_free (&objfile
-> type_obstack
, type_name
);
1501 type
= SYMBOL_TYPE (sym
);
1506 /* Didn't find the type to which this refers, so we must
1507 be dealing with a forward reference. Allocate a type
1508 structure for it, and keep track of it so we can
1509 fill in the rest of the fields when we get the full
1511 type
= dbx_alloc_type (typenums
, objfile
);
1512 TYPE_CODE (type
) = code
;
1513 TYPE_TAG_NAME (type
) = type_name
;
1514 INIT_CPLUS_SPECIFIC(type
);
1515 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1517 add_undefined_type (type
);
1521 case '-': /* RS/6000 built-in type */
1540 /* Peek ahead at the number to detect void. */
1541 if (read_type_number (pp
, xtypenums
) != 0)
1542 return error_type (pp
);
1544 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1545 /* It's being defined as itself. That means it is "void". */
1546 type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
1551 /* Go back to the number and have read_type get it. This means
1552 that we can deal with something like t(1,2)=(3,4)=... which
1553 the Lucid compiler uses. */
1555 xtype
= read_type (pp
, objfile
);
1557 /* The type is being defined to another type. So we copy the type.
1558 This loses if we copy a C++ class and so we lose track of how
1559 the names are mangled (but g++ doesn't output stabs like this
1562 type
= alloc_type (objfile
);
1563 memcpy (type
, xtype
, sizeof (struct type
));
1565 /* The idea behind clearing the names is that the only purpose
1566 for defining a type to another type is so that the name of
1567 one can be different. So we probably don't need to worry much
1568 about the case where the compiler doesn't give a name to the
1570 TYPE_NAME (type
) = NULL
;
1571 TYPE_TAG_NAME (type
) = NULL
;
1573 if (typenums
[0] != -1)
1574 *dbx_lookup_type (typenums
) = type
;
1578 /* In the following types, we must be sure to overwrite any existing
1579 type that the typenums refer to, rather than allocating a new one
1580 and making the typenums point to the new one. This is because there
1581 may already be pointers to the existing type (if it had been
1582 forward-referenced), and we must change it to a pointer, function,
1583 reference, or whatever, *in-place*. */
1586 type1
= read_type (pp
, objfile
);
1587 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1590 case '&': /* Reference to another type */
1591 type1
= read_type (pp
, objfile
);
1592 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1595 case 'f': /* Function returning another type */
1596 if (os9k_stabs
&& **pp
== '(')
1598 /* Function prototype; parse it.
1599 We must conditionalize this on os9k_stabs because otherwise
1600 it could be confused with a Sun-style (1,3) typenumber
1606 t
= read_type(pp
, objfile
);
1607 if (**pp
== ',') ++*pp
;
1610 type1
= read_type (pp
, objfile
);
1611 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1614 case 'k': /* Const qualifier on some type (Sun) */
1615 case 'c': /* Const qualifier on some type (OS9000) */
1616 /* Because 'c' means other things to AIX and 'k' is perfectly good,
1617 only accept 'c' in the os9k_stabs case. */
1618 if (type_descriptor
== 'c' && !os9k_stabs
)
1619 return error_type (pp
);
1620 type
= read_type (pp
, objfile
);
1621 /* FIXME! For now, we ignore const and volatile qualifiers. */
1624 case 'B': /* Volatile qual on some type (Sun) */
1625 case 'i': /* Volatile qual on some type (OS9000) */
1626 /* Because 'i' means other things to AIX and 'B' is perfectly good,
1627 only accept 'i' in the os9k_stabs case. */
1628 if (type_descriptor
== 'i' && !os9k_stabs
)
1629 return error_type (pp
);
1630 type
= read_type (pp
, objfile
);
1631 /* FIXME! For now, we ignore const and volatile qualifiers. */
1634 /* FIXME -- we should be doing smash_to_XXX types here. */
1635 case '@': /* Member (class & variable) type */
1637 struct type
*domain
= read_type (pp
, objfile
);
1638 struct type
*memtype
;
1641 /* Invalid member type data format. */
1642 return error_type (pp
);
1645 memtype
= read_type (pp
, objfile
);
1646 type
= dbx_alloc_type (typenums
, objfile
);
1647 smash_to_member_type (type
, domain
, memtype
);
1651 case '#': /* Method (class & fn) type */
1652 if ((*pp
)[0] == '#')
1654 /* We'll get the parameter types from the name. */
1655 struct type
*return_type
;
1658 return_type
= read_type (pp
, objfile
);
1659 if (*(*pp
)++ != ';')
1660 complain (&invalid_member_complaint
, symnum
);
1661 type
= allocate_stub_method (return_type
);
1662 if (typenums
[0] != -1)
1663 *dbx_lookup_type (typenums
) = type
;
1667 struct type
*domain
= read_type (pp
, objfile
);
1668 struct type
*return_type
;
1672 /* Invalid member type data format. */
1673 return error_type (pp
);
1677 return_type
= read_type (pp
, objfile
);
1678 args
= read_args (pp
, ';', objfile
);
1679 type
= dbx_alloc_type (typenums
, objfile
);
1680 smash_to_method_type (type
, domain
, return_type
, args
);
1684 case 'r': /* Range type */
1685 type
= read_range_type (pp
, typenums
, objfile
);
1686 if (typenums
[0] != -1)
1687 *dbx_lookup_type (typenums
) = type
;
1692 /* Const and volatile qualified type. */
1693 type
= read_type (pp
, objfile
);
1696 /* Sun ACC builtin int type */
1697 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1698 if (typenums
[0] != -1)
1699 *dbx_lookup_type (typenums
) = type
;
1703 case 'R': /* Sun ACC builtin float type */
1704 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1705 if (typenums
[0] != -1)
1706 *dbx_lookup_type (typenums
) = type
;
1709 case 'e': /* Enumeration type */
1710 type
= dbx_alloc_type (typenums
, objfile
);
1711 type
= read_enum_type (pp
, type
, objfile
);
1712 if (typenums
[0] != -1)
1713 *dbx_lookup_type (typenums
) = type
;
1716 case 's': /* Struct type */
1717 case 'u': /* Union type */
1718 type
= dbx_alloc_type (typenums
, objfile
);
1719 if (!TYPE_NAME (type
))
1721 TYPE_NAME (type
) = type_synonym_name
;
1723 type_synonym_name
= NULL
;
1724 switch (type_descriptor
)
1727 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1730 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1733 type
= read_struct_type (pp
, type
, objfile
);
1736 case 'a': /* Array type */
1738 return error_type (pp
);
1741 type
= dbx_alloc_type (typenums
, objfile
);
1742 type
= read_array_type (pp
, type
, objfile
);
1744 TYPE_CODE (type
) = TYPE_CODE_STRING
;
1748 type1
= read_type (pp
, objfile
);
1749 type
= create_set_type ((struct type
*) NULL
, type1
);
1751 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
1752 if (typenums
[0] != -1)
1753 *dbx_lookup_type (typenums
) = type
;
1757 --*pp
; /* Go back to the symbol in error */
1758 /* Particularly important if it was \0! */
1759 return error_type (pp
);
1764 warning ("GDB internal error, type is NULL in stabsread.c\n");
1765 return error_type (pp
);
1768 /* Size specified in a type attribute overrides any other size. */
1769 if (type_size
!= -1)
1770 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
1775 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1776 Return the proper type node for a given builtin type number. */
1778 static struct type
*
1779 rs6000_builtin_type (typenum
)
1782 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1783 #define NUMBER_RECOGNIZED 34
1784 /* This includes an empty slot for type number -0. */
1785 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1786 struct type
*rettype
= NULL
;
1788 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1790 complain (&rs6000_builtin_complaint
, typenum
);
1791 return builtin_type_error
;
1793 if (negative_types
[-typenum
] != NULL
)
1794 return negative_types
[-typenum
];
1796 #if TARGET_CHAR_BIT != 8
1797 #error This code wrong for TARGET_CHAR_BIT not 8
1798 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1799 that if that ever becomes not true, the correct fix will be to
1800 make the size in the struct type to be in bits, not in units of
1807 /* The size of this and all the other types are fixed, defined
1808 by the debugging format. If there is a type called "int" which
1809 is other than 32 bits, then it should use a new negative type
1810 number (or avoid negative type numbers for that case).
1811 See stabs.texinfo. */
1812 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1815 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1818 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1821 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1824 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1825 "unsigned char", NULL
);
1828 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1831 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1832 "unsigned short", NULL
);
1835 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1836 "unsigned int", NULL
);
1839 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1842 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1843 "unsigned long", NULL
);
1846 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
1849 /* IEEE single precision (32 bit). */
1850 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1853 /* IEEE double precision (64 bit). */
1854 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1857 /* This is an IEEE double on the RS/6000, and different machines with
1858 different sizes for "long double" should use different negative
1859 type numbers. See stabs.texinfo. */
1860 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1863 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1866 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1869 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1872 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1875 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1878 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1882 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1886 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1890 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1894 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1898 /* Complex type consisting of two IEEE single precision values. */
1899 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1902 /* Complex type consisting of two IEEE double precision values. */
1903 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1906 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1909 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1912 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1915 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1918 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
1921 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
1922 "unsigned long long", NULL
);
1925 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
1929 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
1932 negative_types
[-typenum
] = rettype
;
1936 /* This page contains subroutines of read_type. */
1938 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1939 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1940 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1941 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1943 /* Read member function stabs info for C++ classes. The form of each member
1946 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1948 An example with two member functions is:
1950 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1952 For the case of overloaded operators, the format is op$::*.funcs, where
1953 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1954 name (such as `+=') and `.' marks the end of the operator name.
1956 Returns 1 for success, 0 for failure. */
1959 read_member_functions (fip
, pp
, type
, objfile
)
1960 struct field_info
*fip
;
1963 struct objfile
*objfile
;
1967 /* Total number of member functions defined in this class. If the class
1968 defines two `f' functions, and one `g' function, then this will have
1970 int total_length
= 0;
1974 struct next_fnfield
*next
;
1975 struct fn_field fn_field
;
1977 struct type
*look_ahead_type
;
1978 struct next_fnfieldlist
*new_fnlist
;
1979 struct next_fnfield
*new_sublist
;
1983 /* Process each list until we find something that is not a member function
1984 or find the end of the functions. */
1988 /* We should be positioned at the start of the function name.
1989 Scan forward to find the first ':' and if it is not the
1990 first of a "::" delimiter, then this is not a member function. */
2002 look_ahead_type
= NULL
;
2005 new_fnlist
= (struct next_fnfieldlist
*)
2006 xmalloc (sizeof (struct next_fnfieldlist
));
2007 make_cleanup (free
, new_fnlist
);
2008 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2010 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
2012 /* This is a completely wierd case. In order to stuff in the
2013 names that might contain colons (the usual name delimiter),
2014 Mike Tiemann defined a different name format which is
2015 signalled if the identifier is "op$". In that case, the
2016 format is "op$::XXXX." where XXXX is the name. This is
2017 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2018 /* This lets the user type "break operator+".
2019 We could just put in "+" as the name, but that wouldn't
2021 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2022 char *o
= opname
+ 3;
2024 /* Skip past '::'. */
2027 STABS_CONTINUE (pp
);
2033 main_fn_name
= savestring (opname
, o
- opname
);
2039 main_fn_name
= savestring (*pp
, p
- *pp
);
2040 /* Skip past '::'. */
2043 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
2048 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2049 make_cleanup (free
, new_sublist
);
2050 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2052 /* Check for and handle cretinous dbx symbol name continuation! */
2053 if (look_ahead_type
== NULL
)
2056 STABS_CONTINUE (pp
);
2058 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
2061 /* Invalid symtab info for member function. */
2067 /* g++ version 1 kludge */
2068 new_sublist
-> fn_field
.type
= look_ahead_type
;
2069 look_ahead_type
= NULL
;
2079 /* If this is just a stub, then we don't have the real name here. */
2081 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2083 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2084 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2085 new_sublist
-> fn_field
.is_stub
= 1;
2087 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2090 /* Set this member function's visibility fields. */
2093 case VISIBILITY_PRIVATE
:
2094 new_sublist
-> fn_field
.is_private
= 1;
2096 case VISIBILITY_PROTECTED
:
2097 new_sublist
-> fn_field
.is_protected
= 1;
2101 STABS_CONTINUE (pp
);
2104 case 'A': /* Normal functions. */
2105 new_sublist
-> fn_field
.is_const
= 0;
2106 new_sublist
-> fn_field
.is_volatile
= 0;
2109 case 'B': /* `const' member functions. */
2110 new_sublist
-> fn_field
.is_const
= 1;
2111 new_sublist
-> fn_field
.is_volatile
= 0;
2114 case 'C': /* `volatile' member function. */
2115 new_sublist
-> fn_field
.is_const
= 0;
2116 new_sublist
-> fn_field
.is_volatile
= 1;
2119 case 'D': /* `const volatile' member function. */
2120 new_sublist
-> fn_field
.is_const
= 1;
2121 new_sublist
-> fn_field
.is_volatile
= 1;
2124 case '*': /* File compiled with g++ version 1 -- no info */
2129 complain (&const_vol_complaint
, **pp
);
2138 /* virtual member function, followed by index.
2139 The sign bit is set to distinguish pointers-to-methods
2140 from virtual function indicies. Since the array is
2141 in words, the quantity must be shifted left by 1
2142 on 16 bit machine, and by 2 on 32 bit machine, forcing
2143 the sign bit out, and usable as a valid index into
2144 the array. Remove the sign bit here. */
2145 new_sublist
-> fn_field
.voffset
=
2146 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2150 STABS_CONTINUE (pp
);
2151 if (**pp
== ';' || **pp
== '\0')
2153 /* Must be g++ version 1. */
2154 new_sublist
-> fn_field
.fcontext
= 0;
2158 /* Figure out from whence this virtual function came.
2159 It may belong to virtual function table of
2160 one of its baseclasses. */
2161 look_ahead_type
= read_type (pp
, objfile
);
2164 /* g++ version 1 overloaded methods. */
2168 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2177 look_ahead_type
= NULL
;
2183 /* static member function. */
2184 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2185 if (strncmp (new_sublist
-> fn_field
.physname
,
2186 main_fn_name
, strlen (main_fn_name
)))
2188 new_sublist
-> fn_field
.is_stub
= 1;
2194 complain (&member_fn_complaint
, (*pp
)[-1]);
2195 /* Fall through into normal member function. */
2198 /* normal member function. */
2199 new_sublist
-> fn_field
.voffset
= 0;
2200 new_sublist
-> fn_field
.fcontext
= 0;
2204 new_sublist
-> next
= sublist
;
2205 sublist
= new_sublist
;
2207 STABS_CONTINUE (pp
);
2209 while (**pp
!= ';' && **pp
!= '\0');
2213 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2214 obstack_alloc (&objfile
-> type_obstack
,
2215 sizeof (struct fn_field
) * length
);
2216 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2217 sizeof (struct fn_field
) * length
);
2218 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2220 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2223 new_fnlist
-> fn_fieldlist
.length
= length
;
2224 new_fnlist
-> next
= fip
-> fnlist
;
2225 fip
-> fnlist
= new_fnlist
;
2227 total_length
+= length
;
2228 STABS_CONTINUE (pp
);
2233 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2234 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2235 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2236 memset (TYPE_FN_FIELDLISTS (type
), 0,
2237 sizeof (struct fn_fieldlist
) * nfn_fields
);
2238 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2239 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2245 /* Special GNU C++ name.
2247 Returns 1 for success, 0 for failure. "failure" means that we can't
2248 keep parsing and it's time for error_type(). */
2251 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2252 struct field_info
*fip
;
2255 struct objfile
*objfile
;
2260 struct type
*context
;
2270 /* At this point, *pp points to something like "22:23=*22...",
2271 where the type number before the ':' is the "context" and
2272 everything after is a regular type definition. Lookup the
2273 type, find it's name, and construct the field name. */
2275 context
= read_type (pp
, objfile
);
2279 case 'f': /* $vf -- a virtual function table pointer */
2280 fip
->list
->field
.name
=
2281 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2284 case 'b': /* $vb -- a virtual bsomethingorother */
2285 name
= type_name_no_tag (context
);
2288 complain (&invalid_cpp_type_complaint
, symnum
);
2291 fip
->list
->field
.name
=
2292 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2296 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2297 fip
->list
->field
.name
=
2298 obconcat (&objfile
->type_obstack
,
2299 "INVALID_CPLUSPLUS_ABBREV", "", "");
2303 /* At this point, *pp points to the ':'. Skip it and read the
2309 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2312 fip
->list
->field
.type
= read_type (pp
, objfile
);
2314 (*pp
)++; /* Skip the comma. */
2320 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2324 /* This field is unpacked. */
2325 fip
->list
->field
.bitsize
= 0;
2326 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2330 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2331 /* We have no idea what syntax an unrecognized abbrev would have, so
2332 better return 0. If we returned 1, we would need to at least advance
2333 *pp to avoid an infinite loop. */
2340 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2341 struct field_info
*fip
;
2345 struct objfile
*objfile
;
2347 /* The following is code to work around cfront generated stabs.
2348 The stabs contains full mangled name for each field.
2349 We try to demangle the name and extract the field name out of it.
2351 if (current_language
->la_language
== language_cplus
)
2357 dem
= cplus_demangle (*pp
, DMGL_ANSI
| DMGL_PARAMS
);
2360 dem_p
= strrchr (dem
, ':');
2361 if (dem_p
!= 0 && *(dem_p
-1)==':')
2363 fip
->list
->field
.name
=
2364 obsavestring (dem_p
, strlen(dem_p
), &objfile
-> type_obstack
);
2368 fip
->list
->field
.name
=
2369 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2373 /* end of code for cfront work around */
2376 fip
-> list
-> field
.name
=
2377 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2380 /* This means we have a visibility for a field coming. */
2384 fip
-> list
-> visibility
= *(*pp
)++;
2388 /* normal dbx-style format, no explicit visibility */
2389 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2392 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2397 /* Possible future hook for nested types. */
2400 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2406 /* Static class member. */
2407 fip
-> list
-> field
.bitpos
= (long) -1;
2413 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2417 else if (**pp
!= ',')
2419 /* Bad structure-type format. */
2420 complain (&stabs_general_complaint
, "bad structure-type format");
2424 (*pp
)++; /* Skip the comma. */
2428 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2431 complain (&stabs_general_complaint
, "bad structure-type format");
2434 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2437 complain (&stabs_general_complaint
, "bad structure-type format");
2442 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2444 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2445 it is a field which has been optimized out. The correct stab for
2446 this case is to use VISIBILITY_IGNORE, but that is a recent
2447 invention. (2) It is a 0-size array. For example
2448 union { int num; char str[0]; } foo. Printing "<no value>" for
2449 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2450 will continue to work, and a 0-size array as a whole doesn't
2451 have any contents to print.
2453 I suspect this probably could also happen with gcc -gstabs (not
2454 -gstabs+) for static fields, and perhaps other C++ extensions.
2455 Hopefully few people use -gstabs with gdb, since it is intended
2456 for dbx compatibility. */
2458 /* Ignore this field. */
2459 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2463 /* Detect an unpacked field and mark it as such.
2464 dbx gives a bit size for all fields.
2465 Note that forward refs cannot be packed,
2466 and treat enums as if they had the width of ints. */
2468 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2469 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2471 fip
-> list
-> field
.bitsize
= 0;
2473 if ((fip
-> list
-> field
.bitsize
2474 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2475 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2476 && (fip
-> list
-> field
.bitsize
2481 fip
-> list
-> field
.bitpos
% 8 == 0)
2483 fip
-> list
-> field
.bitsize
= 0;
2489 /* Read struct or class data fields. They have the form:
2491 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2493 At the end, we see a semicolon instead of a field.
2495 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2498 The optional VISIBILITY is one of:
2500 '/0' (VISIBILITY_PRIVATE)
2501 '/1' (VISIBILITY_PROTECTED)
2502 '/2' (VISIBILITY_PUBLIC)
2503 '/9' (VISIBILITY_IGNORE)
2505 or nothing, for C style fields with public visibility.
2507 Returns 1 for success, 0 for failure. */
2510 read_struct_fields (fip
, pp
, type
, objfile
)
2511 struct field_info
*fip
;
2514 struct objfile
*objfile
;
2517 struct nextfield
*new;
2519 /* We better set p right now, in case there are no fields at all... */
2523 /* Read each data member type until we find the terminating ';' at the end of
2524 the data member list, or break for some other reason such as finding the
2525 start of the member function list. */
2529 if (os9k_stabs
&& **pp
== ',') break;
2530 STABS_CONTINUE (pp
);
2531 /* Get space to record the next field's data. */
2532 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2533 make_cleanup (free
, new);
2534 memset (new, 0, sizeof (struct nextfield
));
2535 new -> next
= fip
-> list
;
2538 /* Get the field name. */
2541 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2542 unless the CPLUS_MARKER is followed by an underscore, in
2543 which case it is just the name of an anonymous type, which we
2544 should handle like any other type name. We accept either '$'
2545 or '.', because a field name can never contain one of these
2546 characters except as a CPLUS_MARKER (we probably should be
2547 doing that in most parts of GDB). */
2549 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2551 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2556 /* Look for the ':' that separates the field name from the field
2557 values. Data members are delimited by a single ':', while member
2558 functions are delimited by a pair of ':'s. When we hit the member
2559 functions (if any), terminate scan loop and return. */
2561 while (*p
!= ':' && *p
!= '\0')
2568 /* Check to see if we have hit the member functions yet. */
2573 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2575 if (p
[0] == ':' && p
[1] == ':')
2577 /* chill the list of fields: the last entry (at the head) is a
2578 partially constructed entry which we now scrub. */
2579 fip
-> list
= fip
-> list
-> next
;
2584 /* The stabs for C++ derived classes contain baseclass information which
2585 is marked by a '!' character after the total size. This function is
2586 called when we encounter the baseclass marker, and slurps up all the
2587 baseclass information.
2589 Immediately following the '!' marker is the number of base classes that
2590 the class is derived from, followed by information for each base class.
2591 For each base class, there are two visibility specifiers, a bit offset
2592 to the base class information within the derived class, a reference to
2593 the type for the base class, and a terminating semicolon.
2595 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2597 Baseclass information marker __________________|| | | | | | |
2598 Number of baseclasses __________________________| | | | | | |
2599 Visibility specifiers (2) ________________________| | | | | |
2600 Offset in bits from start of class _________________| | | | |
2601 Type number for base class ___________________________| | | |
2602 Visibility specifiers (2) _______________________________| | |
2603 Offset in bits from start of class ________________________| |
2604 Type number of base class ____________________________________|
2606 Return 1 for success, 0 for (error-type-inducing) failure. */
2609 read_baseclasses (fip
, pp
, type
, objfile
)
2610 struct field_info
*fip
;
2613 struct objfile
*objfile
;
2616 struct nextfield
*new;
2624 /* Skip the '!' baseclass information marker. */
2628 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2631 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2637 /* Some stupid compilers have trouble with the following, so break
2638 it up into simpler expressions. */
2639 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2640 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2643 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2646 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2647 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2651 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2653 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2655 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2656 make_cleanup (free
, new);
2657 memset (new, 0, sizeof (struct nextfield
));
2658 new -> next
= fip
-> list
;
2660 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2662 STABS_CONTINUE (pp
);
2666 /* Nothing to do. */
2669 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2672 /* Unknown character. Complain and treat it as non-virtual. */
2674 static struct complaint msg
= {
2675 "Unknown virtual character `%c' for baseclass", 0, 0};
2676 complain (&msg
, **pp
);
2681 new -> visibility
= *(*pp
)++;
2682 switch (new -> visibility
)
2684 case VISIBILITY_PRIVATE
:
2685 case VISIBILITY_PROTECTED
:
2686 case VISIBILITY_PUBLIC
:
2689 /* Bad visibility format. Complain and treat it as
2692 static struct complaint msg
= {
2693 "Unknown visibility `%c' for baseclass", 0, 0};
2694 complain (&msg
, new -> visibility
);
2695 new -> visibility
= VISIBILITY_PUBLIC
;
2702 /* The remaining value is the bit offset of the portion of the object
2703 corresponding to this baseclass. Always zero in the absence of
2704 multiple inheritance. */
2706 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2711 /* The last piece of baseclass information is the type of the
2712 base class. Read it, and remember it's type name as this
2715 new -> field
.type
= read_type (pp
, objfile
);
2716 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2718 /* skip trailing ';' and bump count of number of fields seen */
2727 /* The tail end of stabs for C++ classes that contain a virtual function
2728 pointer contains a tilde, a %, and a type number.
2729 The type number refers to the base class (possibly this class itself) which
2730 contains the vtable pointer for the current class.
2732 This function is called when we have parsed all the method declarations,
2733 so we can look for the vptr base class info. */
2736 read_tilde_fields (fip
, pp
, type
, objfile
)
2737 struct field_info
*fip
;
2740 struct objfile
*objfile
;
2744 STABS_CONTINUE (pp
);
2746 /* If we are positioned at a ';', then skip it. */
2756 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2758 /* Obsolete flags that used to indicate the presence
2759 of constructors and/or destructors. */
2763 /* Read either a '%' or the final ';'. */
2764 if (*(*pp
)++ == '%')
2766 /* The next number is the type number of the base class
2767 (possibly our own class) which supplies the vtable for
2768 this class. Parse it out, and search that class to find
2769 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2770 and TYPE_VPTR_FIELDNO. */
2775 t
= read_type (pp
, objfile
);
2777 while (*p
!= '\0' && *p
!= ';')
2783 /* Premature end of symbol. */
2787 TYPE_VPTR_BASETYPE (type
) = t
;
2788 if (type
== t
) /* Our own class provides vtbl ptr */
2790 for (i
= TYPE_NFIELDS (t
) - 1;
2791 i
>= TYPE_N_BASECLASSES (t
);
2794 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2795 sizeof (vptr_name
) - 1))
2797 TYPE_VPTR_FIELDNO (type
) = i
;
2801 /* Virtual function table field not found. */
2802 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2807 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2818 attach_fn_fields_to_type (fip
, type
)
2819 struct field_info
*fip
;
2820 register struct type
*type
;
2824 for (n
= TYPE_NFN_FIELDS (type
);
2825 fip
-> fnlist
!= NULL
;
2826 fip
-> fnlist
= fip
-> fnlist
-> next
)
2828 --n
; /* Circumvent Sun3 compiler bug */
2829 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2834 /* Create the vector of fields, and record how big it is.
2835 We need this info to record proper virtual function table information
2836 for this class's virtual functions. */
2839 attach_fields_to_type (fip
, type
, objfile
)
2840 struct field_info
*fip
;
2841 register struct type
*type
;
2842 struct objfile
*objfile
;
2844 register int nfields
= 0;
2845 register int non_public_fields
= 0;
2846 register struct nextfield
*scan
;
2848 /* Count up the number of fields that we have, as well as taking note of
2849 whether or not there are any non-public fields, which requires us to
2850 allocate and build the private_field_bits and protected_field_bits
2853 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2856 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2858 non_public_fields
++;
2862 /* Now we know how many fields there are, and whether or not there are any
2863 non-public fields. Record the field count, allocate space for the
2864 array of fields, and create blank visibility bitfields if necessary. */
2866 TYPE_NFIELDS (type
) = nfields
;
2867 TYPE_FIELDS (type
) = (struct field
*)
2868 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2869 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2871 if (non_public_fields
)
2873 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2875 TYPE_FIELD_PRIVATE_BITS (type
) =
2876 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2877 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2879 TYPE_FIELD_PROTECTED_BITS (type
) =
2880 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2881 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2883 TYPE_FIELD_IGNORE_BITS (type
) =
2884 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2885 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2888 /* Copy the saved-up fields into the field vector. Start from the head
2889 of the list, adding to the tail of the field array, so that they end
2890 up in the same order in the array in which they were added to the list. */
2892 while (nfields
-- > 0)
2894 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2895 switch (fip
-> list
-> visibility
)
2897 case VISIBILITY_PRIVATE
:
2898 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2901 case VISIBILITY_PROTECTED
:
2902 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2905 case VISIBILITY_IGNORE
:
2906 SET_TYPE_FIELD_IGNORE (type
, nfields
);
2909 case VISIBILITY_PUBLIC
:
2913 /* Unknown visibility. Complain and treat it as public. */
2915 static struct complaint msg
= {
2916 "Unknown visibility `%c' for field", 0, 0};
2917 complain (&msg
, fip
-> list
-> visibility
);
2921 fip
-> list
= fip
-> list
-> next
;
2926 /* Read the description of a structure (or union type) and return an object
2927 describing the type.
2929 PP points to a character pointer that points to the next unconsumed token
2930 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2931 *PP will point to "4a:1,0,32;;".
2933 TYPE points to an incomplete type that needs to be filled in.
2935 OBJFILE points to the current objfile from which the stabs information is
2936 being read. (Note that it is redundant in that TYPE also contains a pointer
2937 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2940 static struct type
*
2941 read_struct_type (pp
, type
, objfile
)
2944 struct objfile
*objfile
;
2946 struct cleanup
*back_to
;
2947 struct field_info fi
;
2952 back_to
= make_cleanup (null_cleanup
, 0);
2954 INIT_CPLUS_SPECIFIC (type
);
2955 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2957 /* First comes the total size in bytes. */
2961 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2963 return error_type (pp
);
2966 /* Now read the baseclasses, if any, read the regular C struct or C++
2967 class member fields, attach the fields to the type, read the C++
2968 member functions, attach them to the type, and then read any tilde
2969 field (baseclass specifier for the class holding the main vtable). */
2971 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2972 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2973 || !attach_fields_to_type (&fi
, type
, objfile
)
2974 || !read_member_functions (&fi
, pp
, type
, objfile
)
2975 || !attach_fn_fields_to_type (&fi
, type
)
2976 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2978 do_cleanups (back_to
);
2979 return (error_type (pp
));
2982 do_cleanups (back_to
);
2986 /* Read a definition of an array type,
2987 and create and return a suitable type object.
2988 Also creates a range type which represents the bounds of that
2991 static struct type
*
2992 read_array_type (pp
, type
, objfile
)
2994 register struct type
*type
;
2995 struct objfile
*objfile
;
2997 struct type
*index_type
, *element_type
, *range_type
;
3002 /* Format of an array type:
3003 "ar<index type>;lower;upper;<array_contents_type>".
3004 OS9000: "arlower,upper;<array_contents_type>".
3006 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3007 for these, produce a type like float[][]. */
3010 index_type
= builtin_type_int
;
3013 index_type
= read_type (pp
, objfile
);
3015 /* Improper format of array type decl. */
3016 return error_type (pp
);
3020 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3025 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
3027 return error_type (pp
);
3029 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3034 upper
= read_huge_number (pp
, ';', &nbits
);
3036 return error_type (pp
);
3038 element_type
= read_type (pp
, objfile
);
3047 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
3048 type
= create_array_type (type
, element_type
, range_type
);
3050 /* If we have an array whose element type is not yet known, but whose
3051 bounds *are* known, record it to be adjusted at the end of the file. */
3053 if ((TYPE_FLAGS (element_type
) & TYPE_FLAG_STUB
) && !adjustable
)
3055 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
3056 add_undefined_type (type
);
3063 /* Read a definition of an enumeration type,
3064 and create and return a suitable type object.
3065 Also defines the symbols that represent the values of the type. */
3067 static struct type
*
3068 read_enum_type (pp
, type
, objfile
)
3070 register struct type
*type
;
3071 struct objfile
*objfile
;
3076 register struct symbol
*sym
;
3078 struct pending
**symlist
;
3079 struct pending
*osyms
, *syms
;
3082 int unsigned_enum
= 1;
3085 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3086 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3087 to do? For now, force all enum values to file scope. */
3088 if (within_function
)
3089 symlist
= &local_symbols
;
3092 symlist
= &file_symbols
;
3094 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3098 /* Size. Perhaps this does not have to be conditionalized on
3099 os9k_stabs (assuming the name of an enum constant can't start
3101 read_huge_number (pp
, 0, &nbits
);
3103 return error_type (pp
);
3106 /* The aix4 compiler emits an extra field before the enum members;
3107 my guess is it's a type of some sort. Just ignore it. */
3110 /* Skip over the type. */
3114 /* Skip over the colon. */
3118 /* Read the value-names and their values.
3119 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3120 A semicolon or comma instead of a NAME means the end. */
3121 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3123 STABS_CONTINUE (pp
);
3125 while (*p
!= ':') p
++;
3126 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3128 n
= read_huge_number (pp
, ',', &nbits
);
3130 return error_type (pp
);
3132 sym
= (struct symbol
*)
3133 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3134 memset (sym
, 0, sizeof (struct symbol
));
3135 SYMBOL_NAME (sym
) = name
;
3136 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3137 SYMBOL_CLASS (sym
) = LOC_CONST
;
3138 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3139 SYMBOL_VALUE (sym
) = n
;
3142 add_symbol_to_list (sym
, symlist
);
3147 (*pp
)++; /* Skip the semicolon. */
3149 /* Now fill in the fields of the type-structure. */
3151 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3152 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3153 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3155 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3156 TYPE_NFIELDS (type
) = nsyms
;
3157 TYPE_FIELDS (type
) = (struct field
*)
3158 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3159 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3161 /* Find the symbols for the values and put them into the type.
3162 The symbols can be found in the symlist that we put them on
3163 to cause them to be defined. osyms contains the old value
3164 of that symlist; everything up to there was defined by us. */
3165 /* Note that we preserve the order of the enum constants, so
3166 that in something like "enum {FOO, LAST_THING=FOO}" we print
3167 FOO, not LAST_THING. */
3169 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
3171 int last
= syms
== osyms
? o_nsyms
: 0;
3172 int j
= syms
->nsyms
;
3173 for (; --j
>= last
; --n
)
3175 struct symbol
*xsym
= syms
->symbol
[j
];
3176 SYMBOL_TYPE (xsym
) = type
;
3177 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3178 TYPE_FIELD_VALUE (type
, n
) = 0;
3179 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3180 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3189 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3190 typedefs in every file (for int, long, etc):
3192 type = b <signed> <width>; <offset>; <nbits>
3193 signed = u or s. Possible c in addition to u or s (for char?).
3194 offset = offset from high order bit to start bit of type.
3195 width is # bytes in object of this type, nbits is # bits in type.
3197 The width/offset stuff appears to be for small objects stored in
3198 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3201 static struct type
*
3202 read_sun_builtin_type (pp
, typenums
, objfile
)
3205 struct objfile
*objfile
;
3220 return error_type (pp
);
3224 /* For some odd reason, all forms of char put a c here. This is strange
3225 because no other type has this honor. We can safely ignore this because
3226 we actually determine 'char'acterness by the number of bits specified in
3232 /* The first number appears to be the number of bytes occupied
3233 by this type, except that unsigned short is 4 instead of 2.
3234 Since this information is redundant with the third number,
3235 we will ignore it. */
3236 read_huge_number (pp
, ';', &nbits
);
3238 return error_type (pp
);
3240 /* The second number is always 0, so ignore it too. */
3241 read_huge_number (pp
, ';', &nbits
);
3243 return error_type (pp
);
3245 /* The third number is the number of bits for this type. */
3246 type_bits
= read_huge_number (pp
, 0, &nbits
);
3248 return error_type (pp
);
3249 /* The type *should* end with a semicolon. If it are embedded
3250 in a larger type the semicolon may be the only way to know where
3251 the type ends. If this type is at the end of the stabstring we
3252 can deal with the omitted semicolon (but we don't have to like
3253 it). Don't bother to complain(), Sun's compiler omits the semicolon
3259 return init_type (TYPE_CODE_VOID
, 1,
3260 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3263 return init_type (TYPE_CODE_INT
,
3264 type_bits
/ TARGET_CHAR_BIT
,
3265 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3269 static struct type
*
3270 read_sun_floating_type (pp
, typenums
, objfile
)
3273 struct objfile
*objfile
;
3279 /* The first number has more details about the type, for example
3281 details
= read_huge_number (pp
, ';', &nbits
);
3283 return error_type (pp
);
3285 /* The second number is the number of bytes occupied by this type */
3286 nbytes
= read_huge_number (pp
, ';', &nbits
);
3288 return error_type (pp
);
3290 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3291 || details
== NF_COMPLEX32
)
3292 /* This is a type we can't handle, but we do know the size.
3293 We also will be able to give it a name. */
3294 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3296 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3299 /* Read a number from the string pointed to by *PP.
3300 The value of *PP is advanced over the number.
3301 If END is nonzero, the character that ends the
3302 number must match END, or an error happens;
3303 and that character is skipped if it does match.
3304 If END is zero, *PP is left pointing to that character.
3306 If the number fits in a long, set *BITS to 0 and return the value.
3307 If not, set *BITS to be the number of bits in the number and return 0.
3309 If encounter garbage, set *BITS to -1 and return 0. */
3312 read_huge_number (pp
, end
, bits
)
3332 /* Leading zero means octal. GCC uses this to output values larger
3333 than an int (because that would be hard in decimal). */
3341 upper_limit
= ULONG_MAX
/ radix
;
3343 upper_limit
= LONG_MAX
/ radix
;
3345 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3347 if (n
<= upper_limit
)
3350 n
+= c
- '0'; /* FIXME this overflows anyway */
3355 /* This depends on large values being output in octal, which is
3362 /* Ignore leading zeroes. */
3366 else if (c
== '2' || c
== '3')
3392 /* Large decimal constants are an error (because it is hard to
3393 count how many bits are in them). */
3399 /* -0x7f is the same as 0x80. So deal with it by adding one to
3400 the number of bits. */
3412 /* It's *BITS which has the interesting information. */
3416 static struct type
*
3417 read_range_type (pp
, typenums
, objfile
)
3420 struct objfile
*objfile
;
3422 char *orig_pp
= *pp
;
3427 struct type
*result_type
;
3428 struct type
*index_type
= NULL
;
3430 /* First comes a type we are a subrange of.
3431 In C it is usually 0, 1 or the type being defined. */
3432 if (read_type_number (pp
, rangenums
) != 0)
3433 return error_type (pp
);
3434 self_subrange
= (rangenums
[0] == typenums
[0] &&
3435 rangenums
[1] == typenums
[1]);
3440 index_type
= read_type (pp
, objfile
);
3443 /* A semicolon should now follow; skip it. */
3447 /* The remaining two operands are usually lower and upper bounds
3448 of the range. But in some special cases they mean something else. */
3449 n2
= read_huge_number (pp
, ';', &n2bits
);
3450 n3
= read_huge_number (pp
, ';', &n3bits
);
3452 if (n2bits
== -1 || n3bits
== -1)
3453 return error_type (pp
);
3456 goto handle_true_range
;
3458 /* If limits are huge, must be large integral type. */
3459 if (n2bits
!= 0 || n3bits
!= 0)
3461 char got_signed
= 0;
3462 char got_unsigned
= 0;
3463 /* Number of bits in the type. */
3466 /* Range from 0 to <large number> is an unsigned large integral type. */
3467 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3472 /* Range from <large number> to <large number>-1 is a large signed
3473 integral type. Take care of the case where <large number> doesn't
3474 fit in a long but <large number>-1 does. */
3475 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3476 || (n2bits
!= 0 && n3bits
== 0
3477 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3484 if (got_signed
|| got_unsigned
)
3486 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3487 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3491 return error_type (pp
);
3494 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3495 if (self_subrange
&& n2
== 0 && n3
== 0)
3496 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
3498 /* If n3 is zero and n2 is not, we want a floating type,
3499 and n2 is the width in bytes.
3501 Fortran programs appear to use this for complex types also,
3502 and they give no way to distinguish between double and single-complex!
3504 GDB does not have complex types.
3506 Just return the complex as a float of that size. It won't work right
3507 for the complex values, but at least it makes the file loadable. */
3509 if (n3
== 0 && n2
> 0)
3511 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3514 /* If the upper bound is -1, it must really be an unsigned int. */
3516 else if (n2
== 0 && n3
== -1)
3518 /* It is unsigned int or unsigned long. */
3519 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3520 compatibility hack. */
3521 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3522 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3525 /* Special case: char is defined (Who knows why) as a subrange of
3526 itself with range 0-127. */
3527 else if (self_subrange
&& n2
== 0 && n3
== 127)
3528 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3530 /* We used to do this only for subrange of self or subrange of int. */
3534 /* n3 actually gives the size. */
3535 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3538 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3540 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3542 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3543 "unsigned long", and we already checked for that,
3544 so don't need to test for it here. */
3546 /* I think this is for Convex "long long". Since I don't know whether
3547 Convex sets self_subrange, I also accept that particular size regardless
3548 of self_subrange. */
3549 else if (n3
== 0 && n2
< 0
3551 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3552 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3553 else if (n2
== -n3
-1)
3556 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3558 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3559 if (n3
== 0x7fffffff)
3560 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3563 /* We have a real range type on our hands. Allocate space and
3564 return a real pointer. */
3567 /* At this point I don't have the faintest idea how to deal with
3568 a self_subrange type; I'm going to assume that this is used
3569 as an idiom, and that all of them are special cases. So . . . */
3571 return error_type (pp
);
3573 index_type
= *dbx_lookup_type (rangenums
);
3574 if (index_type
== NULL
)
3576 /* Does this actually ever happen? Is that why we are worrying
3577 about dealing with it rather than just calling error_type? */
3579 static struct type
*range_type_index
;
3581 complain (&range_type_base_complaint
, rangenums
[1]);
3582 if (range_type_index
== NULL
)
3584 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3585 0, "range type index type", NULL
);
3586 index_type
= range_type_index
;
3589 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3590 return (result_type
);
3593 /* Read in an argument list. This is a list of types, separated by commas
3594 and terminated with END. Return the list of types read in, or (struct type
3595 **)-1 if there is an error. */
3597 static struct type
**
3598 read_args (pp
, end
, objfile
)
3601 struct objfile
*objfile
;
3603 /* FIXME! Remove this arbitrary limit! */
3604 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3610 /* Invalid argument list: no ','. */
3611 return (struct type
**)-1;
3613 STABS_CONTINUE (pp
);
3614 types
[n
++] = read_type (pp
, objfile
);
3616 (*pp
)++; /* get past `end' (the ':' character) */
3620 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3622 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3624 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3625 memset (rval
+ n
, 0, sizeof (struct type
*));
3629 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3631 memcpy (rval
, types
, n
* sizeof (struct type
*));
3635 /* Common block handling. */
3637 /* List of symbols declared since the last BCOMM. This list is a tail
3638 of local_symbols. When ECOMM is seen, the symbols on the list
3639 are noted so their proper addresses can be filled in later,
3640 using the common block base address gotten from the assembler
3643 static struct pending
*common_block
;
3644 static int common_block_i
;
3646 /* Name of the current common block. We get it from the BCOMM instead of the
3647 ECOMM to match IBM documentation (even though IBM puts the name both places
3648 like everyone else). */
3649 static char *common_block_name
;
3651 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3652 to remain after this function returns. */
3655 common_block_start (name
, objfile
)
3657 struct objfile
*objfile
;
3659 if (common_block_name
!= NULL
)
3661 static struct complaint msg
= {
3662 "Invalid symbol data: common block within common block",
3666 common_block
= local_symbols
;
3667 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3668 common_block_name
= obsavestring (name
, strlen (name
),
3669 &objfile
-> symbol_obstack
);
3672 /* Process a N_ECOMM symbol. */
3675 common_block_end (objfile
)
3676 struct objfile
*objfile
;
3678 /* Symbols declared since the BCOMM are to have the common block
3679 start address added in when we know it. common_block and
3680 common_block_i point to the first symbol after the BCOMM in
3681 the local_symbols list; copy the list and hang it off the
3682 symbol for the common block name for later fixup. */
3685 struct pending
*new = 0;
3686 struct pending
*next
;
3689 if (common_block_name
== NULL
)
3691 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
3696 sym
= (struct symbol
*)
3697 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3698 memset (sym
, 0, sizeof (struct symbol
));
3699 SYMBOL_NAME (sym
) = common_block_name
;
3700 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3702 /* Now we copy all the symbols which have been defined since the BCOMM. */
3704 /* Copy all the struct pendings before common_block. */
3705 for (next
= local_symbols
;
3706 next
!= NULL
&& next
!= common_block
;
3709 for (j
= 0; j
< next
->nsyms
; j
++)
3710 add_symbol_to_list (next
->symbol
[j
], &new);
3713 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3714 NULL, it means copy all the local symbols (which we already did
3717 if (common_block
!= NULL
)
3718 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
3719 add_symbol_to_list (common_block
->symbol
[j
], &new);
3721 SYMBOL_TYPE (sym
) = (struct type
*) new;
3723 /* Should we be putting local_symbols back to what it was?
3726 i
= hashname (SYMBOL_NAME (sym
));
3727 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3728 global_sym_chain
[i
] = sym
;
3729 common_block_name
= NULL
;
3732 /* Add a common block's start address to the offset of each symbol
3733 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3734 the common block name). */
3737 fix_common_block (sym
, valu
)
3741 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
3742 for ( ; next
; next
= next
->next
)
3745 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3746 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3752 /* What about types defined as forward references inside of a small lexical
3754 /* Add a type to the list of undefined types to be checked through
3755 once this file has been read in. */
3758 add_undefined_type (type
)
3761 if (undef_types_length
== undef_types_allocated
)
3763 undef_types_allocated
*= 2;
3764 undef_types
= (struct type
**)
3765 xrealloc ((char *) undef_types
,
3766 undef_types_allocated
* sizeof (struct type
*));
3768 undef_types
[undef_types_length
++] = type
;
3771 /* Go through each undefined type, see if it's still undefined, and fix it
3772 up if possible. We have two kinds of undefined types:
3774 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3775 Fix: update array length using the element bounds
3776 and the target type's length.
3777 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3778 yet defined at the time a pointer to it was made.
3779 Fix: Do a full lookup on the struct/union tag. */
3781 cleanup_undefined_types ()
3785 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3787 switch (TYPE_CODE (*type
))
3790 case TYPE_CODE_STRUCT
:
3791 case TYPE_CODE_UNION
:
3792 case TYPE_CODE_ENUM
:
3794 /* Check if it has been defined since. Need to do this here
3795 as well as in check_stub_type to deal with the (legitimate in
3796 C though not C++) case of several types with the same name
3797 in different source files. */
3798 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3800 struct pending
*ppt
;
3802 /* Name of the type, without "struct" or "union" */
3803 char *typename
= TYPE_TAG_NAME (*type
);
3805 if (typename
== NULL
)
3807 static struct complaint msg
= {"need a type name", 0, 0};
3811 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3813 for (i
= 0; i
< ppt
->nsyms
; i
++)
3815 struct symbol
*sym
= ppt
->symbol
[i
];
3817 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3818 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3819 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3821 && STREQ (SYMBOL_NAME (sym
), typename
))
3823 memcpy (*type
, SYMBOL_TYPE (sym
),
3824 sizeof (struct type
));
3832 case TYPE_CODE_ARRAY
:
3834 /* This is a kludge which is here for historical reasons
3835 because I suspect that check_stub_type does not get
3836 called everywhere it needs to be called for arrays. Even
3837 with this kludge, those places are broken for the case
3838 where the stub type is defined in another compilation
3839 unit, but this kludge at least deals with it for the case
3840 in which it is the same compilation unit.
3842 Don't try to do this by calling check_stub_type; it might
3843 cause symbols to be read in lookup_symbol, and the symbol
3844 reader is not reentrant. */
3846 struct type
*range_type
;
3849 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3851 if (TYPE_NFIELDS (*type
) != 1)
3853 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3854 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3857 /* Now recompute the length of the array type, based on its
3858 number of elements and the target type's length. */
3859 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3860 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3861 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3862 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3864 /* If the target type is not a stub, we could be clearing
3865 TYPE_FLAG_TARGET_STUB for *type. */
3872 static struct complaint msg
= {"\
3873 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3874 complain (&msg
, TYPE_CODE (*type
));
3880 undef_types_length
= 0;
3883 /* Scan through all of the global symbols defined in the object file,
3884 assigning values to the debugging symbols that need to be assigned
3885 to. Get these symbols from the minimal symbol table.
3886 Return 1 if there might still be unresolved debugging symbols, else 0. */
3888 static int scan_file_globals_1
PARAMS ((struct objfile
*));
3891 scan_file_globals_1 (objfile
)
3892 struct objfile
*objfile
;
3895 struct minimal_symbol
*msymbol
;
3896 struct symbol
*sym
, *prev
;
3898 /* Avoid expensive loop through all minimal symbols if there are
3899 no unresolved symbols. */
3900 for (hash
= 0; hash
< HASHSIZE
; hash
++)
3902 if (global_sym_chain
[hash
])
3905 if (hash
>= HASHSIZE
)
3908 if (objfile
->msymbols
== 0) /* Beware the null file. */
3911 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3915 /* Skip static symbols. */
3916 switch (MSYMBOL_TYPE (msymbol
))
3928 /* Get the hash index and check all the symbols
3929 under that hash index. */
3931 hash
= hashname (SYMBOL_NAME (msymbol
));
3933 for (sym
= global_sym_chain
[hash
]; sym
;)
3935 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3936 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3938 /* Splice this symbol out of the hash chain and
3939 assign the value we have to it. */
3942 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3946 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3949 /* Check to see whether we need to fix up a common block. */
3950 /* Note: this code might be executed several times for
3951 the same symbol if there are multiple references. */
3953 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3955 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3959 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3962 SYMBOL_SECTION (sym
) = SYMBOL_SECTION (msymbol
);
3966 sym
= SYMBOL_VALUE_CHAIN (prev
);
3970 sym
= global_sym_chain
[hash
];
3976 sym
= SYMBOL_VALUE_CHAIN (sym
);
3983 /* Assign values to global debugging symbols.
3984 Search the passed objfile first, then try the runtime common symbols.
3985 Complain about any remaining unresolved symbols and remove them
3989 scan_file_globals (objfile
)
3990 struct objfile
*objfile
;
3993 struct symbol
*sym
, *prev
;
3995 if (scan_file_globals_1 (objfile
) == 0)
3997 if (rt_common_objfile
&& scan_file_globals_1 (rt_common_objfile
) == 0)
4000 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4002 sym
= global_sym_chain
[hash
];
4005 complain (&unresolved_sym_chain_complaint
,
4006 objfile
->name
, SYMBOL_NAME (sym
));
4008 /* Change the symbol address from the misleading chain value
4011 sym
= SYMBOL_VALUE_CHAIN (sym
);
4012 SYMBOL_VALUE_ADDRESS (prev
) = 0;
4015 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4018 /* Initialize anything that needs initializing when starting to read
4019 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4027 /* Initialize anything that needs initializing when a completely new
4028 symbol file is specified (not just adding some symbols from another
4029 file, e.g. a shared library). */
4032 stabsread_new_init ()
4034 /* Empty the hash table of global syms looking for values. */
4035 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4038 /* Initialize anything that needs initializing at the same time as
4039 start_symtab() is called. */
4043 global_stabs
= NULL
; /* AIX COFF */
4044 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4045 n_this_object_header_files
= 1;
4046 type_vector_length
= 0;
4047 type_vector
= (struct type
**) 0;
4049 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4050 common_block_name
= NULL
;
4055 /* Call after end_symtab() */
4061 free ((char *) type_vector
);
4064 type_vector_length
= 0;
4065 previous_stab_code
= 0;
4069 finish_global_stabs (objfile
)
4070 struct objfile
*objfile
;
4074 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
4075 free ((PTR
) global_stabs
);
4076 global_stabs
= NULL
;
4080 /* Initializer for this module */
4083 _initialize_stabsread ()
4085 undef_types_allocated
= 20;
4086 undef_types_length
= 0;
4087 undef_types
= (struct type
**)
4088 xmalloc (undef_types_allocated
* sizeof (struct type
*));