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., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
35 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
37 #include "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. */
597 complain (&unrecognized_cplus_name_complaint
, string
);
598 goto normal
; /* Do *something* with it */
604 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
605 SYMBOL_NAME (sym
) = (char *)
606 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
607 /* Open-coded memcpy--saves function call time. */
608 /* FIXME: Does it really? Try replacing with simple strcpy and
609 try it on an executable with a large symbol table. */
610 /* FIXME: considering that gcc can open code memcpy anyway, I
611 doubt it. xoxorich. */
613 register char *p1
= string
;
614 register char *p2
= SYMBOL_NAME (sym
);
622 /* If this symbol is from a C++ compilation, then attempt to cache the
623 demangled form for future reference. This is a typical time versus
624 space tradeoff, that was decided in favor of time because it sped up
625 C++ symbol lookups by a factor of about 20. */
627 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
631 /* Determine the type of name being defined. */
633 /* Getting GDB to correctly skip the symbol on an undefined symbol
634 descriptor and not ever dump core is a very dodgy proposition if
635 we do things this way. I say the acorn RISC machine can just
636 fix their compiler. */
637 /* The Acorn RISC machine's compiler can put out locals that don't
638 start with "234=" or "(3,4)=", so assume anything other than the
639 deftypes we know how to handle is a local. */
640 if (!strchr ("cfFGpPrStTvVXCR", *p
))
642 if (isdigit (*p
) || *p
== '(' || *p
== '-')
651 /* c is a special case, not followed by a type-number.
652 SYMBOL:c=iVALUE for an integer constant symbol.
653 SYMBOL:c=rVALUE for a floating constant symbol.
654 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
655 e.g. "b:c=e6,0" for "const b = blob1"
656 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
659 SYMBOL_CLASS (sym
) = LOC_CONST
;
660 SYMBOL_TYPE (sym
) = error_type (&p
);
661 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
662 add_symbol_to_list (sym
, &file_symbols
);
673 /* FIXME-if-picky-about-floating-accuracy: Should be using
674 target arithmetic to get the value. real.c in GCC
675 probably has the necessary code. */
677 /* FIXME: lookup_fundamental_type is a hack. We should be
678 creating a type especially for the type of float constants.
679 Problem is, what type should it be?
681 Also, what should the name of this type be? Should we
682 be using 'S' constants (see stabs.texinfo) instead? */
684 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
687 obstack_alloc (&objfile
-> symbol_obstack
,
688 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
689 store_floating (dbl_valu
, TYPE_LENGTH (SYMBOL_TYPE (sym
)), d
);
690 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
691 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
696 /* Defining integer constants this way is kind of silly,
697 since 'e' constants allows the compiler to give not
698 only the value, but the type as well. C has at least
699 int, long, unsigned int, and long long as constant
700 types; other languages probably should have at least
701 unsigned as well as signed constants. */
703 /* We just need one int constant type for all objfiles.
704 It doesn't depend on languages or anything (arguably its
705 name should be a language-specific name for a type of
706 that size, but I'm inclined to say that if the compiler
707 wants a nice name for the type, it can use 'e'). */
708 static struct type
*int_const_type
;
710 /* Yes, this is as long as a *host* int. That is because we
712 if (int_const_type
== NULL
)
714 init_type (TYPE_CODE_INT
,
715 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
717 (struct objfile
*)NULL
);
718 SYMBOL_TYPE (sym
) = int_const_type
;
719 SYMBOL_VALUE (sym
) = atoi (p
);
720 SYMBOL_CLASS (sym
) = LOC_CONST
;
724 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
725 can be represented as integral.
726 e.g. "b:c=e6,0" for "const b = blob1"
727 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
729 SYMBOL_CLASS (sym
) = LOC_CONST
;
730 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
734 SYMBOL_TYPE (sym
) = error_type (&p
);
739 /* If the value is too big to fit in an int (perhaps because
740 it is unsigned), or something like that, we silently get
741 a bogus value. The type and everything else about it is
742 correct. Ideally, we should be using whatever we have
743 available for parsing unsigned and long long values,
745 SYMBOL_VALUE (sym
) = atoi (p
);
750 SYMBOL_CLASS (sym
) = LOC_CONST
;
751 SYMBOL_TYPE (sym
) = error_type (&p
);
754 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
755 add_symbol_to_list (sym
, &file_symbols
);
759 /* The name of a caught exception. */
760 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
761 SYMBOL_CLASS (sym
) = LOC_LABEL
;
762 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
763 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
764 add_symbol_to_list (sym
, &local_symbols
);
768 /* A static function definition. */
769 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
770 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
771 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
772 add_symbol_to_list (sym
, &file_symbols
);
773 /* fall into process_function_types. */
775 process_function_types
:
776 /* Function result types are described as the result type in stabs.
777 We need to convert this to the function-returning-type-X type
778 in GDB. E.g. "int" is converted to "function returning int". */
779 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
780 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
781 /* fall into process_prototype_types */
783 process_prototype_types
:
784 /* Sun acc puts declared types of arguments here. We don't care
785 about their actual types (FIXME -- we should remember the whole
786 function prototype), but the list may define some new types
787 that we have to remember, so we must scan it now. */
790 read_type (&p
, objfile
);
795 /* A global function definition. */
796 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
797 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
798 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
799 add_symbol_to_list (sym
, &global_symbols
);
800 goto process_function_types
;
803 /* For a class G (global) symbol, it appears that the
804 value is not correct. It is necessary to search for the
805 corresponding linker definition to find the value.
806 These definitions appear at the end of the namelist. */
807 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
808 i
= hashname (SYMBOL_NAME (sym
));
809 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
810 global_sym_chain
[i
] = sym
;
811 SYMBOL_CLASS (sym
) = LOC_STATIC
;
812 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
813 add_symbol_to_list (sym
, &global_symbols
);
816 /* This case is faked by a conditional above,
817 when there is no code letter in the dbx data.
818 Dbx data never actually contains 'l'. */
821 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
822 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
823 SYMBOL_VALUE (sym
) = valu
;
824 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
825 add_symbol_to_list (sym
, &local_symbols
);
830 /* pF is a two-letter code that means a function parameter in Fortran.
831 The type-number specifies the type of the return value.
832 Translate it into a pointer-to-function type. */
836 = lookup_pointer_type
837 (lookup_function_type (read_type (&p
, objfile
)));
840 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
842 /* Normally this is a parameter, a LOC_ARG. On the i960, it
843 can also be a LOC_LOCAL_ARG depending on symbol type. */
844 #ifndef DBX_PARM_SYMBOL_CLASS
845 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
848 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
849 SYMBOL_VALUE (sym
) = valu
;
850 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
851 add_symbol_to_list (sym
, &local_symbols
);
853 if (TARGET_BYTE_ORDER
!= BIG_ENDIAN
)
855 /* On little-endian machines, this crud is never necessary,
856 and, if the extra bytes contain garbage, is harmful. */
860 /* If it's gcc-compiled, if it says `short', believe it. */
861 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
864 #if !BELIEVE_PCC_PROMOTION
866 /* This is the signed type which arguments get promoted to. */
867 static struct type
*pcc_promotion_type
;
868 /* This is the unsigned type which arguments get promoted to. */
869 static struct type
*pcc_unsigned_promotion_type
;
871 /* Call it "int" because this is mainly C lossage. */
872 if (pcc_promotion_type
== NULL
)
874 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
877 if (pcc_unsigned_promotion_type
== NULL
)
878 pcc_unsigned_promotion_type
=
879 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
880 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
882 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
883 /* This macro is defined on machines (e.g. sparc) where
884 we should believe the type of a PCC 'short' argument,
885 but shouldn't believe the address (the address is
886 the address of the corresponding int).
888 My guess is that this correction, as opposed to changing
889 the parameter to an 'int' (as done below, for PCC
890 on most machines), is the right thing to do
891 on all machines, but I don't want to risk breaking
892 something that already works. On most PCC machines,
893 the sparc problem doesn't come up because the calling
894 function has to zero the top bytes (not knowing whether
895 the called function wants an int or a short), so there
896 is little practical difference between an int and a short
897 (except perhaps what happens when the GDB user types
898 "print short_arg = 0x10000;").
900 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
901 actually produces the correct address (we don't need to fix it
902 up). I made this code adapt so that it will offset the symbol
903 if it was pointing at an int-aligned location and not
904 otherwise. This way you can use the same gdb for 4.0.x and
907 If the parameter is shorter than an int, and is integral
908 (e.g. char, short, or unsigned equivalent), and is claimed to
909 be passed on an integer boundary, don't believe it! Offset the
910 parameter's address to the tail-end of that integer. */
912 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
913 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
914 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
916 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
917 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
921 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
923 /* If PCC says a parameter is a short or a char,
924 it is really an int. */
925 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
926 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
929 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
930 ? pcc_unsigned_promotion_type
931 : pcc_promotion_type
;
935 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
937 #endif /* !BELIEVE_PCC_PROMOTION. */
940 /* acc seems to use P to delare the prototypes of functions that
941 are referenced by this file. gdb is not prepared to deal
942 with this extra information. FIXME, it ought to. */
945 read_type (&p
, objfile
);
946 goto process_prototype_types
;
951 /* Parameter which is in a register. */
952 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
953 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
954 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
955 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
957 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
958 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
960 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
961 add_symbol_to_list (sym
, &local_symbols
);
965 /* Register variable (either global or local). */
966 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
967 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
968 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
969 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
971 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
972 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
974 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
977 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
978 name to represent an argument passed in a register.
979 GCC uses 'P' for the same case. So if we find such a symbol pair
980 we combine it into one 'P' symbol. For Sun cc we need to do this
981 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
982 the 'p' symbol even if it never saves the argument onto the stack.
984 On most machines, we want to preserve both symbols, so that
985 we can still get information about what is going on with the
986 stack (VAX for computing args_printed, using stack slots instead
987 of saved registers in backtraces, etc.).
989 Note that this code illegally combines
990 main(argc) struct foo argc; { register struct foo argc; }
991 but this case is considered pathological and causes a warning
992 from a decent compiler. */
995 && local_symbols
->nsyms
> 0
996 #ifndef USE_REGISTER_NOT_ARG
997 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
999 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1000 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1004 struct symbol
*prev_sym
;
1005 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1006 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1007 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1008 && STREQ (SYMBOL_NAME (prev_sym
), SYMBOL_NAME(sym
)))
1010 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1011 /* Use the type from the LOC_REGISTER; that is the type
1012 that is actually in that register. */
1013 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1014 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1019 add_symbol_to_list (sym
, &local_symbols
);
1022 add_symbol_to_list (sym
, &file_symbols
);
1026 /* Static symbol at top level of file */
1027 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1028 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1029 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1030 #ifdef STATIC_TRANSFORM_NAME
1031 if (SYMBOL_NAME (sym
)[0] == '$')
1033 struct minimal_symbol
*msym
;
1034 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1037 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1038 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1042 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1043 add_symbol_to_list (sym
, &file_symbols
);
1047 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1049 /* For a nameless type, we don't want a create a symbol, thus we
1050 did not use `sym'. Return without further processing. */
1051 if (nameless
) return NULL
;
1053 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1054 SYMBOL_VALUE (sym
) = valu
;
1055 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1056 /* C++ vagaries: we may have a type which is derived from
1057 a base type which did not have its name defined when the
1058 derived class was output. We fill in the derived class's
1059 base part member's name here in that case. */
1060 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1061 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1062 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1063 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1066 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1067 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1068 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1069 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1072 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1074 /* gcc-2.6 or later (when using -fvtable-thunks)
1075 emits a unique named type for a vtable entry.
1076 Some gdb code depends on that specific name. */
1077 extern const char vtbl_ptr_name
[];
1079 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1080 && strcmp (SYMBOL_NAME (sym
), vtbl_ptr_name
))
1081 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1083 /* If we are giving a name to a type such as "pointer to
1084 foo" or "function returning foo", we better not set
1085 the TYPE_NAME. If the program contains "typedef char
1086 *caddr_t;", we don't want all variables of type char
1087 * to print as caddr_t. This is not just a
1088 consequence of GDB's type management; PCC and GCC (at
1089 least through version 2.4) both output variables of
1090 either type char * or caddr_t with the type number
1091 defined in the 't' symbol for caddr_t. If a future
1092 compiler cleans this up it GDB is not ready for it
1093 yet, but if it becomes ready we somehow need to
1094 disable this check (without breaking the PCC/GCC2.4
1099 Fortunately, this check seems not to be necessary
1100 for anything except pointers or functions. */
1103 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_NAME (sym
);
1106 add_symbol_to_list (sym
, &file_symbols
);
1110 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1111 by 't' which means we are typedef'ing it as well. */
1112 synonym
= *p
== 't';
1117 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1118 strlen (SYMBOL_NAME (sym
)),
1119 &objfile
-> symbol_obstack
);
1121 /* The semantics of C++ state that "struct foo { ... }" also defines
1122 a typedef for "foo". Unfortunately, cfront never makes the typedef
1123 when translating C++ into C. We make the typedef here so that
1124 "ptype foo" works as expected for cfront translated code. */
1125 else if (current_subfile
->language
== language_cplus
)
1128 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
1129 strlen (SYMBOL_NAME (sym
)),
1130 &objfile
-> symbol_obstack
);
1133 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1135 /* For a nameless type, we don't want a create a symbol, thus we
1136 did not use `sym'. Return without further processing. */
1137 if (nameless
) return NULL
;
1139 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1140 SYMBOL_VALUE (sym
) = valu
;
1141 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1142 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1143 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1144 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1145 add_symbol_to_list (sym
, &file_symbols
);
1149 /* Clone the sym and then modify it. */
1150 register struct symbol
*typedef_sym
= (struct symbol
*)
1151 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
1152 *typedef_sym
= *sym
;
1153 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1154 SYMBOL_VALUE (typedef_sym
) = valu
;
1155 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1156 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1157 TYPE_NAME (SYMBOL_TYPE (sym
))
1158 = obconcat (&objfile
-> type_obstack
, "", "", SYMBOL_NAME (sym
));
1159 add_symbol_to_list (typedef_sym
, &file_symbols
);
1164 /* Static symbol of local scope */
1165 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1166 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1167 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1168 #ifdef STATIC_TRANSFORM_NAME
1169 if (SYMBOL_NAME (sym
)[0] == '$')
1171 struct minimal_symbol
*msym
;
1172 msym
= lookup_minimal_symbol (SYMBOL_NAME (sym
), NULL
, objfile
);
1175 SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym
));
1176 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1180 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1182 add_symbol_to_list (sym
, &global_symbols
);
1184 add_symbol_to_list (sym
, &local_symbols
);
1188 /* Reference parameter */
1189 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1190 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1191 SYMBOL_VALUE (sym
) = valu
;
1192 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1193 add_symbol_to_list (sym
, &local_symbols
);
1197 /* Reference parameter which is in a register. */
1198 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1199 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1200 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1201 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
1203 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
1204 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1206 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1207 add_symbol_to_list (sym
, &local_symbols
);
1211 /* This is used by Sun FORTRAN for "function result value".
1212 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1213 that Pascal uses it too, but when I tried it Pascal used
1214 "x:3" (local symbol) instead. */
1215 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1216 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1217 SYMBOL_VALUE (sym
) = valu
;
1218 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1219 add_symbol_to_list (sym
, &local_symbols
);
1223 SYMBOL_TYPE (sym
) = error_type (&p
);
1224 SYMBOL_CLASS (sym
) = LOC_CONST
;
1225 SYMBOL_VALUE (sym
) = 0;
1226 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1227 add_symbol_to_list (sym
, &file_symbols
);
1231 /* When passing structures to a function, some systems sometimes pass
1232 the address in a register, not the structure itself.
1234 If REG_STRUCT_HAS_ADDR yields non-zero we have to convert LOC_REGPARM
1235 to LOC_REGPARM_ADDR for structures and unions. */
1237 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
1238 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1240 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1241 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1242 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1244 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1245 subsequent arguments on the sparc, for example). */
1246 if (SYMBOL_CLASS (sym
) == LOC_ARG
1247 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation
,
1249 && ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
)
1250 || (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)))
1251 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1257 /* Skip rest of this symbol and return an error type.
1259 General notes on error recovery: error_type always skips to the
1260 end of the symbol (modulo cretinous dbx symbol name continuation).
1261 Thus code like this:
1263 if (*(*pp)++ != ';')
1264 return error_type (pp);
1266 is wrong because if *pp starts out pointing at '\0' (typically as the
1267 result of an earlier error), it will be incremented to point to the
1268 start of the next symbol, which might produce strange results, at least
1269 if you run off the end of the string table. Instead use
1272 return error_type (pp);
1278 foo = error_type (pp);
1282 And in case it isn't obvious, the point of all this hair is so the compiler
1283 can define new types and new syntaxes, and old versions of the
1284 debugger will be able to read the new symbol tables. */
1286 static struct type
*
1290 complain (&error_type_complaint
);
1293 /* Skip to end of symbol. */
1294 while (**pp
!= '\0')
1299 /* Check for and handle cretinous dbx symbol name continuation! */
1300 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1302 *pp
= next_symbol_text ();
1309 return (builtin_type_error
);
1313 /* Read type information or a type definition; return the type. Even
1314 though this routine accepts either type information or a type
1315 definition, the distinction is relevant--some parts of stabsread.c
1316 assume that type information starts with a digit, '-', or '(' in
1317 deciding whether to call read_type. */
1320 read_type (pp
, objfile
)
1322 struct objfile
*objfile
;
1324 register struct type
*type
= 0;
1328 char type_descriptor
;
1330 /* Size in bits of type if specified by a type attribute, or -1 if
1331 there is no size attribute. */
1334 /* Used to distinguish string and bitstring from char-array and set. */
1337 /* Read type number if present. The type number may be omitted.
1338 for instance in a two-dimensional array declared with type
1339 "ar1;1;10;ar1;1;10;4". */
1340 if ((**pp
>= '0' && **pp
<= '9')
1344 if (read_type_number (pp
, typenums
) != 0)
1345 return error_type (pp
);
1347 /* Type is not being defined here. Either it already exists,
1348 or this is a forward reference to it. dbx_alloc_type handles
1351 return dbx_alloc_type (typenums
, objfile
);
1353 /* Type is being defined here. */
1360 /* It might be a type attribute or a member type. */
1361 if (isdigit (*p
) || *p
== '(' || *p
== '-')
1366 /* Type attributes. */
1369 /* Skip to the semicolon. */
1370 while (*p
!= ';' && *p
!= '\0')
1374 return error_type (pp
);
1376 /* Skip the semicolon. */
1382 type_size
= atoi (attr
+ 1);
1392 /* Ignore unrecognized type attributes, so future compilers
1393 can invent new ones. */
1398 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1403 /* 'typenums=' not present, type is anonymous. Read and return
1404 the definition, but don't put it in the type vector. */
1405 typenums
[0] = typenums
[1] = -1;
1409 type_descriptor
= (*pp
)[-1];
1410 switch (type_descriptor
)
1414 enum type_code code
;
1416 /* Used to index through file_symbols. */
1417 struct pending
*ppt
;
1420 /* Name including "struct", etc. */
1424 char *from
, *to
, *p
, *q1
, *q2
;
1426 /* Set the type code according to the following letter. */
1430 code
= TYPE_CODE_STRUCT
;
1433 code
= TYPE_CODE_UNION
;
1436 code
= TYPE_CODE_ENUM
;
1440 /* Complain and keep going, so compilers can invent new
1441 cross-reference types. */
1442 static struct complaint msg
=
1443 {"Unrecognized cross-reference type `%c'", 0, 0};
1444 complain (&msg
, (*pp
)[0]);
1445 code
= TYPE_CODE_STRUCT
;
1450 q1
= strchr(*pp
, '<');
1451 p
= strchr(*pp
, ':');
1453 return error_type (pp
);
1454 while (q1
&& p
> q1
&& p
[1] == ':')
1456 q2
= strchr(q1
, '>');
1462 return error_type (pp
);
1465 (char *)obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1467 /* Copy the name. */
1473 /* Set the pointer ahead of the name which we just read, and
1478 /* Now check to see whether the type has already been
1479 declared. This was written for arrays of cross-referenced
1480 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1481 sure it is not necessary anymore. But it might be a good
1482 idea, to save a little memory. */
1484 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1485 for (i
= 0; i
< ppt
->nsyms
; i
++)
1487 struct symbol
*sym
= ppt
->symbol
[i
];
1489 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1490 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1491 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1492 && STREQ (SYMBOL_NAME (sym
), type_name
))
1494 obstack_free (&objfile
-> type_obstack
, type_name
);
1495 type
= SYMBOL_TYPE (sym
);
1500 /* Didn't find the type to which this refers, so we must
1501 be dealing with a forward reference. Allocate a type
1502 structure for it, and keep track of it so we can
1503 fill in the rest of the fields when we get the full
1505 type
= dbx_alloc_type (typenums
, objfile
);
1506 TYPE_CODE (type
) = code
;
1507 TYPE_TAG_NAME (type
) = type_name
;
1508 INIT_CPLUS_SPECIFIC(type
);
1509 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1511 add_undefined_type (type
);
1515 case '-': /* RS/6000 built-in type */
1534 /* Peek ahead at the number to detect void. */
1535 if (read_type_number (pp
, xtypenums
) != 0)
1536 return error_type (pp
);
1538 if (typenums
[0] == xtypenums
[0] && typenums
[1] == xtypenums
[1])
1539 /* It's being defined as itself. That means it is "void". */
1540 type
= init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
1545 /* Go back to the number and have read_type get it. This means
1546 that we can deal with something like t(1,2)=(3,4)=... which
1547 the Lucid compiler uses. */
1549 xtype
= read_type (pp
, objfile
);
1551 /* The type is being defined to another type. So we copy the type.
1552 This loses if we copy a C++ class and so we lose track of how
1553 the names are mangled (but g++ doesn't output stabs like this
1556 type
= alloc_type (objfile
);
1557 memcpy (type
, xtype
, sizeof (struct type
));
1559 /* The idea behind clearing the names is that the only purpose
1560 for defining a type to another type is so that the name of
1561 one can be different. So we probably don't need to worry much
1562 about the case where the compiler doesn't give a name to the
1564 TYPE_NAME (type
) = NULL
;
1565 TYPE_TAG_NAME (type
) = NULL
;
1567 if (typenums
[0] != -1)
1568 *dbx_lookup_type (typenums
) = type
;
1572 /* In the following types, we must be sure to overwrite any existing
1573 type that the typenums refer to, rather than allocating a new one
1574 and making the typenums point to the new one. This is because there
1575 may already be pointers to the existing type (if it had been
1576 forward-referenced), and we must change it to a pointer, function,
1577 reference, or whatever, *in-place*. */
1580 type1
= read_type (pp
, objfile
);
1581 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1584 case '&': /* Reference to another type */
1585 type1
= read_type (pp
, objfile
);
1586 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1589 case 'f': /* Function returning another type */
1590 if (os9k_stabs
&& **pp
== '(')
1592 /* Function prototype; parse it.
1593 We must conditionalize this on os9k_stabs because otherwise
1594 it could be confused with a Sun-style (1,3) typenumber
1600 t
= read_type(pp
, objfile
);
1601 if (**pp
== ',') ++*pp
;
1604 type1
= read_type (pp
, objfile
);
1605 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1608 case 'k': /* Const qualifier on some type (Sun) */
1609 case 'c': /* Const qualifier on some type (OS9000) */
1610 /* Because 'c' means other things to AIX and 'k' is perfectly good,
1611 only accept 'c' in the os9k_stabs case. */
1612 if (type_descriptor
== 'c' && !os9k_stabs
)
1613 return error_type (pp
);
1614 type
= read_type (pp
, objfile
);
1615 /* FIXME! For now, we ignore const and volatile qualifiers. */
1618 case 'B': /* Volatile qual on some type (Sun) */
1619 case 'i': /* Volatile qual on some type (OS9000) */
1620 /* Because 'i' means other things to AIX and 'B' is perfectly good,
1621 only accept 'i' in the os9k_stabs case. */
1622 if (type_descriptor
== 'i' && !os9k_stabs
)
1623 return error_type (pp
);
1624 type
= read_type (pp
, objfile
);
1625 /* FIXME! For now, we ignore const and volatile qualifiers. */
1628 /* FIXME -- we should be doing smash_to_XXX types here. */
1629 case '@': /* Member (class & variable) type */
1631 struct type
*domain
= read_type (pp
, objfile
);
1632 struct type
*memtype
;
1635 /* Invalid member type data format. */
1636 return error_type (pp
);
1639 memtype
= read_type (pp
, objfile
);
1640 type
= dbx_alloc_type (typenums
, objfile
);
1641 smash_to_member_type (type
, domain
, memtype
);
1645 case '#': /* Method (class & fn) type */
1646 if ((*pp
)[0] == '#')
1648 /* We'll get the parameter types from the name. */
1649 struct type
*return_type
;
1652 return_type
= read_type (pp
, objfile
);
1653 if (*(*pp
)++ != ';')
1654 complain (&invalid_member_complaint
, symnum
);
1655 type
= allocate_stub_method (return_type
);
1656 if (typenums
[0] != -1)
1657 *dbx_lookup_type (typenums
) = type
;
1661 struct type
*domain
= read_type (pp
, objfile
);
1662 struct type
*return_type
;
1666 /* Invalid member type data format. */
1667 return error_type (pp
);
1671 return_type
= read_type (pp
, objfile
);
1672 args
= read_args (pp
, ';', objfile
);
1673 type
= dbx_alloc_type (typenums
, objfile
);
1674 smash_to_method_type (type
, domain
, return_type
, args
);
1678 case 'r': /* Range type */
1679 type
= read_range_type (pp
, typenums
, objfile
);
1680 if (typenums
[0] != -1)
1681 *dbx_lookup_type (typenums
) = type
;
1686 /* Const and volatile qualified type. */
1687 type
= read_type (pp
, objfile
);
1690 /* Sun ACC builtin int type */
1691 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1692 if (typenums
[0] != -1)
1693 *dbx_lookup_type (typenums
) = type
;
1697 case 'R': /* Sun ACC builtin float type */
1698 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1699 if (typenums
[0] != -1)
1700 *dbx_lookup_type (typenums
) = type
;
1703 case 'e': /* Enumeration type */
1704 type
= dbx_alloc_type (typenums
, objfile
);
1705 type
= read_enum_type (pp
, type
, objfile
);
1706 if (typenums
[0] != -1)
1707 *dbx_lookup_type (typenums
) = type
;
1710 case 's': /* Struct type */
1711 case 'u': /* Union type */
1712 type
= dbx_alloc_type (typenums
, objfile
);
1713 if (!TYPE_NAME (type
))
1715 TYPE_NAME (type
) = type_synonym_name
;
1717 type_synonym_name
= NULL
;
1718 switch (type_descriptor
)
1721 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1724 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1727 type
= read_struct_type (pp
, type
, objfile
);
1730 case 'a': /* Array type */
1732 return error_type (pp
);
1735 type
= dbx_alloc_type (typenums
, objfile
);
1736 type
= read_array_type (pp
, type
, objfile
);
1738 TYPE_CODE (type
) = TYPE_CODE_STRING
;
1742 type1
= read_type (pp
, objfile
);
1743 type
= create_set_type ((struct type
*) NULL
, type1
);
1745 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
1746 if (typenums
[0] != -1)
1747 *dbx_lookup_type (typenums
) = type
;
1751 --*pp
; /* Go back to the symbol in error */
1752 /* Particularly important if it was \0! */
1753 return error_type (pp
);
1758 warning ("GDB internal error, type is NULL in stabsread.c\n");
1759 return error_type (pp
);
1762 /* Size specified in a type attribute overrides any other size. */
1763 if (type_size
!= -1)
1764 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
1769 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1770 Return the proper type node for a given builtin type number. */
1772 static struct type
*
1773 rs6000_builtin_type (typenum
)
1776 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1777 #define NUMBER_RECOGNIZED 30
1778 /* This includes an empty slot for type number -0. */
1779 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
1780 struct type
*rettype
= NULL
;
1782 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
1784 complain (&rs6000_builtin_complaint
, typenum
);
1785 return builtin_type_error
;
1787 if (negative_types
[-typenum
] != NULL
)
1788 return negative_types
[-typenum
];
1790 #if TARGET_CHAR_BIT != 8
1791 #error This code wrong for TARGET_CHAR_BIT not 8
1792 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1793 that if that ever becomes not true, the correct fix will be to
1794 make the size in the struct type to be in bits, not in units of
1801 /* The size of this and all the other types are fixed, defined
1802 by the debugging format. If there is a type called "int" which
1803 is other than 32 bits, then it should use a new negative type
1804 number (or avoid negative type numbers for that case).
1805 See stabs.texinfo. */
1806 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
1809 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
1812 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
1815 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
1818 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
1819 "unsigned char", NULL
);
1822 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
1825 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
1826 "unsigned short", NULL
);
1829 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1830 "unsigned int", NULL
);
1833 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1836 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
1837 "unsigned long", NULL
);
1840 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
1843 /* IEEE single precision (32 bit). */
1844 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
1847 /* IEEE double precision (64 bit). */
1848 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
1851 /* This is an IEEE double on the RS/6000, and different machines with
1852 different sizes for "long double" should use different negative
1853 type numbers. See stabs.texinfo. */
1854 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
1857 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
1860 rettype
= init_type (TYPE_CODE_BOOL
, 4, 0, "boolean", NULL
);
1863 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
1866 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
1869 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
1872 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
1876 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
1880 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
1884 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1888 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
1892 /* Complex type consisting of two IEEE single precision values. */
1893 rettype
= init_type (TYPE_CODE_ERROR
, 8, 0, "complex", NULL
);
1896 /* Complex type consisting of two IEEE double precision values. */
1897 rettype
= init_type (TYPE_CODE_ERROR
, 16, 0, "double complex", NULL
);
1900 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
1903 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
1906 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
1909 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
1912 negative_types
[-typenum
] = rettype
;
1916 /* This page contains subroutines of read_type. */
1918 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1919 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1920 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1921 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1923 /* Read member function stabs info for C++ classes. The form of each member
1926 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1928 An example with two member functions is:
1930 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1932 For the case of overloaded operators, the format is op$::*.funcs, where
1933 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1934 name (such as `+=') and `.' marks the end of the operator name.
1936 Returns 1 for success, 0 for failure. */
1939 read_member_functions (fip
, pp
, type
, objfile
)
1940 struct field_info
*fip
;
1943 struct objfile
*objfile
;
1947 /* Total number of member functions defined in this class. If the class
1948 defines two `f' functions, and one `g' function, then this will have
1950 int total_length
= 0;
1954 struct next_fnfield
*next
;
1955 struct fn_field fn_field
;
1957 struct type
*look_ahead_type
;
1958 struct next_fnfieldlist
*new_fnlist
;
1959 struct next_fnfield
*new_sublist
;
1963 /* Process each list until we find something that is not a member function
1964 or find the end of the functions. */
1968 /* We should be positioned at the start of the function name.
1969 Scan forward to find the first ':' and if it is not the
1970 first of a "::" delimiter, then this is not a member function. */
1982 look_ahead_type
= NULL
;
1985 new_fnlist
= (struct next_fnfieldlist
*)
1986 xmalloc (sizeof (struct next_fnfieldlist
));
1987 make_cleanup (free
, new_fnlist
);
1988 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1990 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1992 /* This is a completely wierd case. In order to stuff in the
1993 names that might contain colons (the usual name delimiter),
1994 Mike Tiemann defined a different name format which is
1995 signalled if the identifier is "op$". In that case, the
1996 format is "op$::XXXX." where XXXX is the name. This is
1997 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1998 /* This lets the user type "break operator+".
1999 We could just put in "+" as the name, but that wouldn't
2001 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
2002 char *o
= opname
+ 3;
2004 /* Skip past '::'. */
2007 STABS_CONTINUE (pp
);
2013 main_fn_name
= savestring (opname
, o
- opname
);
2019 main_fn_name
= savestring (*pp
, p
- *pp
);
2020 /* Skip past '::'. */
2023 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
2028 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2029 make_cleanup (free
, new_sublist
);
2030 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2032 /* Check for and handle cretinous dbx symbol name continuation! */
2033 if (look_ahead_type
== NULL
)
2036 STABS_CONTINUE (pp
);
2038 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
2041 /* Invalid symtab info for member function. */
2047 /* g++ version 1 kludge */
2048 new_sublist
-> fn_field
.type
= look_ahead_type
;
2049 look_ahead_type
= NULL
;
2059 /* If this is just a stub, then we don't have the real name here. */
2061 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
2063 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
2064 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
2065 new_sublist
-> fn_field
.is_stub
= 1;
2067 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
2070 /* Set this member function's visibility fields. */
2073 case VISIBILITY_PRIVATE
:
2074 new_sublist
-> fn_field
.is_private
= 1;
2076 case VISIBILITY_PROTECTED
:
2077 new_sublist
-> fn_field
.is_protected
= 1;
2081 STABS_CONTINUE (pp
);
2084 case 'A': /* Normal functions. */
2085 new_sublist
-> fn_field
.is_const
= 0;
2086 new_sublist
-> fn_field
.is_volatile
= 0;
2089 case 'B': /* `const' member functions. */
2090 new_sublist
-> fn_field
.is_const
= 1;
2091 new_sublist
-> fn_field
.is_volatile
= 0;
2094 case 'C': /* `volatile' member function. */
2095 new_sublist
-> fn_field
.is_const
= 0;
2096 new_sublist
-> fn_field
.is_volatile
= 1;
2099 case 'D': /* `const volatile' member function. */
2100 new_sublist
-> fn_field
.is_const
= 1;
2101 new_sublist
-> fn_field
.is_volatile
= 1;
2104 case '*': /* File compiled with g++ version 1 -- no info */
2109 complain (&const_vol_complaint
, **pp
);
2118 /* virtual member function, followed by index.
2119 The sign bit is set to distinguish pointers-to-methods
2120 from virtual function indicies. Since the array is
2121 in words, the quantity must be shifted left by 1
2122 on 16 bit machine, and by 2 on 32 bit machine, forcing
2123 the sign bit out, and usable as a valid index into
2124 the array. Remove the sign bit here. */
2125 new_sublist
-> fn_field
.voffset
=
2126 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2130 STABS_CONTINUE (pp
);
2131 if (**pp
== ';' || **pp
== '\0')
2133 /* Must be g++ version 1. */
2134 new_sublist
-> fn_field
.fcontext
= 0;
2138 /* Figure out from whence this virtual function came.
2139 It may belong to virtual function table of
2140 one of its baseclasses. */
2141 look_ahead_type
= read_type (pp
, objfile
);
2144 /* g++ version 1 overloaded methods. */
2148 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
2157 look_ahead_type
= NULL
;
2163 /* static member function. */
2164 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
2165 if (strncmp (new_sublist
-> fn_field
.physname
,
2166 main_fn_name
, strlen (main_fn_name
)))
2168 new_sublist
-> fn_field
.is_stub
= 1;
2174 complain (&member_fn_complaint
, (*pp
)[-1]);
2175 /* Fall through into normal member function. */
2178 /* normal member function. */
2179 new_sublist
-> fn_field
.voffset
= 0;
2180 new_sublist
-> fn_field
.fcontext
= 0;
2184 new_sublist
-> next
= sublist
;
2185 sublist
= new_sublist
;
2187 STABS_CONTINUE (pp
);
2189 while (**pp
!= ';' && **pp
!= '\0');
2193 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
2194 obstack_alloc (&objfile
-> type_obstack
,
2195 sizeof (struct fn_field
) * length
);
2196 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
2197 sizeof (struct fn_field
) * length
);
2198 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
2200 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
2203 new_fnlist
-> fn_fieldlist
.length
= length
;
2204 new_fnlist
-> next
= fip
-> fnlist
;
2205 fip
-> fnlist
= new_fnlist
;
2207 total_length
+= length
;
2208 STABS_CONTINUE (pp
);
2213 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2214 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2215 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2216 memset (TYPE_FN_FIELDLISTS (type
), 0,
2217 sizeof (struct fn_fieldlist
) * nfn_fields
);
2218 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2219 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2225 /* Special GNU C++ name.
2227 Returns 1 for success, 0 for failure. "failure" means that we can't
2228 keep parsing and it's time for error_type(). */
2231 read_cpp_abbrev (fip
, pp
, type
, objfile
)
2232 struct field_info
*fip
;
2235 struct objfile
*objfile
;
2240 struct type
*context
;
2250 /* At this point, *pp points to something like "22:23=*22...",
2251 where the type number before the ':' is the "context" and
2252 everything after is a regular type definition. Lookup the
2253 type, find it's name, and construct the field name. */
2255 context
= read_type (pp
, objfile
);
2259 case 'f': /* $vf -- a virtual function table pointer */
2260 fip
->list
->field
.name
=
2261 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
2264 case 'b': /* $vb -- a virtual bsomethingorother */
2265 name
= type_name_no_tag (context
);
2268 complain (&invalid_cpp_type_complaint
, symnum
);
2271 fip
->list
->field
.name
=
2272 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2276 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2277 fip
->list
->field
.name
=
2278 obconcat (&objfile
->type_obstack
,
2279 "INVALID_CPLUSPLUS_ABBREV", "", "");
2283 /* At this point, *pp points to the ':'. Skip it and read the
2289 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2292 fip
->list
->field
.type
= read_type (pp
, objfile
);
2294 (*pp
)++; /* Skip the comma. */
2300 fip
->list
->field
.bitpos
= read_huge_number (pp
, ';', &nbits
);
2304 /* This field is unpacked. */
2305 fip
->list
->field
.bitsize
= 0;
2306 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2310 complain (&invalid_cpp_abbrev_complaint
, *pp
);
2311 /* We have no idea what syntax an unrecognized abbrev would have, so
2312 better return 0. If we returned 1, we would need to at least advance
2313 *pp to avoid an infinite loop. */
2320 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
2321 struct field_info
*fip
;
2325 struct objfile
*objfile
;
2327 fip
-> list
-> field
.name
=
2328 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
2331 /* This means we have a visibility for a field coming. */
2335 fip
-> list
-> visibility
= *(*pp
)++;
2339 /* normal dbx-style format, no explicit visibility */
2340 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
2343 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
2348 /* Possible future hook for nested types. */
2351 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
2357 /* Static class member. */
2358 fip
-> list
-> field
.bitpos
= (long) -1;
2364 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
2368 else if (**pp
!= ',')
2370 /* Bad structure-type format. */
2371 complain (&stabs_general_complaint
, "bad structure-type format");
2375 (*pp
)++; /* Skip the comma. */
2379 fip
-> list
-> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2382 complain (&stabs_general_complaint
, "bad structure-type format");
2385 fip
-> list
-> field
.bitsize
= read_huge_number (pp
, ';', &nbits
);
2388 complain (&stabs_general_complaint
, "bad structure-type format");
2393 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
2395 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2396 it is a field which has been optimized out. The correct stab for
2397 this case is to use VISIBILITY_IGNORE, but that is a recent
2398 invention. (2) It is a 0-size array. For example
2399 union { int num; char str[0]; } foo. Printing "<no value>" for
2400 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2401 will continue to work, and a 0-size array as a whole doesn't
2402 have any contents to print.
2404 I suspect this probably could also happen with gcc -gstabs (not
2405 -gstabs+) for static fields, and perhaps other C++ extensions.
2406 Hopefully few people use -gstabs with gdb, since it is intended
2407 for dbx compatibility. */
2409 /* Ignore this field. */
2410 fip
-> list
-> visibility
= VISIBILITY_IGNORE
;
2414 /* Detect an unpacked field and mark it as such.
2415 dbx gives a bit size for all fields.
2416 Note that forward refs cannot be packed,
2417 and treat enums as if they had the width of ints. */
2419 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
2420 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
2422 fip
-> list
-> field
.bitsize
= 0;
2424 if ((fip
-> list
-> field
.bitsize
2425 == TARGET_CHAR_BIT
* TYPE_LENGTH (fip
-> list
-> field
.type
)
2426 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
2427 && (fip
-> list
-> field
.bitsize
2432 fip
-> list
-> field
.bitpos
% 8 == 0)
2434 fip
-> list
-> field
.bitsize
= 0;
2440 /* Read struct or class data fields. They have the form:
2442 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2444 At the end, we see a semicolon instead of a field.
2446 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2449 The optional VISIBILITY is one of:
2451 '/0' (VISIBILITY_PRIVATE)
2452 '/1' (VISIBILITY_PROTECTED)
2453 '/2' (VISIBILITY_PUBLIC)
2454 '/9' (VISIBILITY_IGNORE)
2456 or nothing, for C style fields with public visibility.
2458 Returns 1 for success, 0 for failure. */
2461 read_struct_fields (fip
, pp
, type
, objfile
)
2462 struct field_info
*fip
;
2465 struct objfile
*objfile
;
2468 struct nextfield
*new;
2470 /* We better set p right now, in case there are no fields at all... */
2474 /* Read each data member type until we find the terminating ';' at the end of
2475 the data member list, or break for some other reason such as finding the
2476 start of the member function list. */
2480 if (os9k_stabs
&& **pp
== ',') break;
2481 STABS_CONTINUE (pp
);
2482 /* Get space to record the next field's data. */
2483 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2484 make_cleanup (free
, new);
2485 memset (new, 0, sizeof (struct nextfield
));
2486 new -> next
= fip
-> list
;
2489 /* Get the field name. */
2492 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2493 unless the CPLUS_MARKER is followed by an underscore, in
2494 which case it is just the name of an anonymous type, which we
2495 should handle like any other type name. We accept either '$'
2496 or '.', because a field name can never contain one of these
2497 characters except as a CPLUS_MARKER (we probably should be
2498 doing that in most parts of GDB). */
2500 if ((*p
== '$' || *p
== '.') && p
[1] != '_')
2502 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
2507 /* Look for the ':' that separates the field name from the field
2508 values. Data members are delimited by a single ':', while member
2509 functions are delimited by a pair of ':'s. When we hit the member
2510 functions (if any), terminate scan loop and return. */
2512 while (*p
!= ':' && *p
!= '\0')
2519 /* Check to see if we have hit the member functions yet. */
2524 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2526 if (p
[0] == ':' && p
[1] == ':')
2528 /* chill the list of fields: the last entry (at the head) is a
2529 partially constructed entry which we now scrub. */
2530 fip
-> list
= fip
-> list
-> next
;
2535 /* The stabs for C++ derived classes contain baseclass information which
2536 is marked by a '!' character after the total size. This function is
2537 called when we encounter the baseclass marker, and slurps up all the
2538 baseclass information.
2540 Immediately following the '!' marker is the number of base classes that
2541 the class is derived from, followed by information for each base class.
2542 For each base class, there are two visibility specifiers, a bit offset
2543 to the base class information within the derived class, a reference to
2544 the type for the base class, and a terminating semicolon.
2546 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2548 Baseclass information marker __________________|| | | | | | |
2549 Number of baseclasses __________________________| | | | | | |
2550 Visibility specifiers (2) ________________________| | | | | |
2551 Offset in bits from start of class _________________| | | | |
2552 Type number for base class ___________________________| | | |
2553 Visibility specifiers (2) _______________________________| | |
2554 Offset in bits from start of class ________________________| |
2555 Type number of base class ____________________________________|
2557 Return 1 for success, 0 for (error-type-inducing) failure. */
2560 read_baseclasses (fip
, pp
, type
, objfile
)
2561 struct field_info
*fip
;
2564 struct objfile
*objfile
;
2567 struct nextfield
*new;
2575 /* Skip the '!' baseclass information marker. */
2579 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2582 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
2588 /* Some stupid compilers have trouble with the following, so break
2589 it up into simpler expressions. */
2590 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2591 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2594 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2597 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2598 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2602 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2604 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2606 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2607 make_cleanup (free
, new);
2608 memset (new, 0, sizeof (struct nextfield
));
2609 new -> next
= fip
-> list
;
2611 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2613 STABS_CONTINUE (pp
);
2617 /* Nothing to do. */
2620 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2623 /* Unknown character. Complain and treat it as non-virtual. */
2625 static struct complaint msg
= {
2626 "Unknown virtual character `%c' for baseclass", 0, 0};
2627 complain (&msg
, **pp
);
2632 new -> visibility
= *(*pp
)++;
2633 switch (new -> visibility
)
2635 case VISIBILITY_PRIVATE
:
2636 case VISIBILITY_PROTECTED
:
2637 case VISIBILITY_PUBLIC
:
2640 /* Bad visibility format. Complain and treat it as
2643 static struct complaint msg
= {
2644 "Unknown visibility `%c' for baseclass", 0, 0};
2645 complain (&msg
, new -> visibility
);
2646 new -> visibility
= VISIBILITY_PUBLIC
;
2653 /* The remaining value is the bit offset of the portion of the object
2654 corresponding to this baseclass. Always zero in the absence of
2655 multiple inheritance. */
2657 new -> field
.bitpos
= read_huge_number (pp
, ',', &nbits
);
2662 /* The last piece of baseclass information is the type of the
2663 base class. Read it, and remember it's type name as this
2666 new -> field
.type
= read_type (pp
, objfile
);
2667 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2669 /* skip trailing ';' and bump count of number of fields seen */
2678 /* The tail end of stabs for C++ classes that contain a virtual function
2679 pointer contains a tilde, a %, and a type number.
2680 The type number refers to the base class (possibly this class itself) which
2681 contains the vtable pointer for the current class.
2683 This function is called when we have parsed all the method declarations,
2684 so we can look for the vptr base class info. */
2687 read_tilde_fields (fip
, pp
, type
, objfile
)
2688 struct field_info
*fip
;
2691 struct objfile
*objfile
;
2695 STABS_CONTINUE (pp
);
2697 /* If we are positioned at a ';', then skip it. */
2707 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2709 /* Obsolete flags that used to indicate the presence
2710 of constructors and/or destructors. */
2714 /* Read either a '%' or the final ';'. */
2715 if (*(*pp
)++ == '%')
2717 /* The next number is the type number of the base class
2718 (possibly our own class) which supplies the vtable for
2719 this class. Parse it out, and search that class to find
2720 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2721 and TYPE_VPTR_FIELDNO. */
2726 t
= read_type (pp
, objfile
);
2728 while (*p
!= '\0' && *p
!= ';')
2734 /* Premature end of symbol. */
2738 TYPE_VPTR_BASETYPE (type
) = t
;
2739 if (type
== t
) /* Our own class provides vtbl ptr */
2741 for (i
= TYPE_NFIELDS (t
) - 1;
2742 i
>= TYPE_N_BASECLASSES (t
);
2745 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2746 sizeof (vptr_name
) - 1))
2748 TYPE_VPTR_FIELDNO (type
) = i
;
2752 /* Virtual function table field not found. */
2753 complain (&vtbl_notfound_complaint
, TYPE_NAME (type
));
2758 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2769 attach_fn_fields_to_type (fip
, type
)
2770 struct field_info
*fip
;
2771 register struct type
*type
;
2775 for (n
= TYPE_NFN_FIELDS (type
);
2776 fip
-> fnlist
!= NULL
;
2777 fip
-> fnlist
= fip
-> fnlist
-> next
)
2779 --n
; /* Circumvent Sun3 compiler bug */
2780 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2785 /* Create the vector of fields, and record how big it is.
2786 We need this info to record proper virtual function table information
2787 for this class's virtual functions. */
2790 attach_fields_to_type (fip
, type
, objfile
)
2791 struct field_info
*fip
;
2792 register struct type
*type
;
2793 struct objfile
*objfile
;
2795 register int nfields
= 0;
2796 register int non_public_fields
= 0;
2797 register struct nextfield
*scan
;
2799 /* Count up the number of fields that we have, as well as taking note of
2800 whether or not there are any non-public fields, which requires us to
2801 allocate and build the private_field_bits and protected_field_bits
2804 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2807 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2809 non_public_fields
++;
2813 /* Now we know how many fields there are, and whether or not there are any
2814 non-public fields. Record the field count, allocate space for the
2815 array of fields, and create blank visibility bitfields if necessary. */
2817 TYPE_NFIELDS (type
) = nfields
;
2818 TYPE_FIELDS (type
) = (struct field
*)
2819 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2820 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2822 if (non_public_fields
)
2824 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2826 TYPE_FIELD_PRIVATE_BITS (type
) =
2827 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2828 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2830 TYPE_FIELD_PROTECTED_BITS (type
) =
2831 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2832 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2834 TYPE_FIELD_IGNORE_BITS (type
) =
2835 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2836 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
2839 /* Copy the saved-up fields into the field vector. Start from the head
2840 of the list, adding to the tail of the field array, so that they end
2841 up in the same order in the array in which they were added to the list. */
2843 while (nfields
-- > 0)
2845 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2846 switch (fip
-> list
-> visibility
)
2848 case VISIBILITY_PRIVATE
:
2849 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2852 case VISIBILITY_PROTECTED
:
2853 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2856 case VISIBILITY_IGNORE
:
2857 SET_TYPE_FIELD_IGNORE (type
, nfields
);
2860 case VISIBILITY_PUBLIC
:
2864 /* Unknown visibility. Complain and treat it as public. */
2866 static struct complaint msg
= {
2867 "Unknown visibility `%c' for field", 0, 0};
2868 complain (&msg
, fip
-> list
-> visibility
);
2872 fip
-> list
= fip
-> list
-> next
;
2877 /* Read the description of a structure (or union type) and return an object
2878 describing the type.
2880 PP points to a character pointer that points to the next unconsumed token
2881 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2882 *PP will point to "4a:1,0,32;;".
2884 TYPE points to an incomplete type that needs to be filled in.
2886 OBJFILE points to the current objfile from which the stabs information is
2887 being read. (Note that it is redundant in that TYPE also contains a pointer
2888 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2891 static struct type
*
2892 read_struct_type (pp
, type
, objfile
)
2895 struct objfile
*objfile
;
2897 struct cleanup
*back_to
;
2898 struct field_info fi
;
2903 back_to
= make_cleanup (null_cleanup
, 0);
2905 INIT_CPLUS_SPECIFIC (type
);
2906 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2908 /* First comes the total size in bytes. */
2912 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
2914 return error_type (pp
);
2917 /* Now read the baseclasses, if any, read the regular C struct or C++
2918 class member fields, attach the fields to the type, read the C++
2919 member functions, attach them to the type, and then read any tilde
2920 field (baseclass specifier for the class holding the main vtable). */
2922 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2923 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2924 || !attach_fields_to_type (&fi
, type
, objfile
)
2925 || !read_member_functions (&fi
, pp
, type
, objfile
)
2926 || !attach_fn_fields_to_type (&fi
, type
)
2927 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2929 do_cleanups (back_to
);
2930 return (error_type (pp
));
2933 do_cleanups (back_to
);
2937 /* Read a definition of an array type,
2938 and create and return a suitable type object.
2939 Also creates a range type which represents the bounds of that
2942 static struct type
*
2943 read_array_type (pp
, type
, objfile
)
2945 register struct type
*type
;
2946 struct objfile
*objfile
;
2948 struct type
*index_type
, *element_type
, *range_type
;
2953 /* Format of an array type:
2954 "ar<index type>;lower;upper;<array_contents_type>".
2955 OS9000: "arlower,upper;<array_contents_type>".
2957 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2958 for these, produce a type like float[][]. */
2961 index_type
= builtin_type_int
;
2964 index_type
= read_type (pp
, objfile
);
2966 /* Improper format of array type decl. */
2967 return error_type (pp
);
2971 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2976 lower
= read_huge_number (pp
, os9k_stabs
? ',' : ';', &nbits
);
2978 return error_type (pp
);
2980 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
2985 upper
= read_huge_number (pp
, ';', &nbits
);
2987 return error_type (pp
);
2989 element_type
= read_type (pp
, objfile
);
2998 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2999 type
= create_array_type (type
, element_type
, range_type
);
3001 /* If we have an array whose element type is not yet known, but whose
3002 bounds *are* known, record it to be adjusted at the end of the file. */
3004 if ((TYPE_FLAGS (element_type
) & TYPE_FLAG_STUB
) && !adjustable
)
3006 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
3007 add_undefined_type (type
);
3014 /* Read a definition of an enumeration type,
3015 and create and return a suitable type object.
3016 Also defines the symbols that represent the values of the type. */
3018 static struct type
*
3019 read_enum_type (pp
, type
, objfile
)
3021 register struct type
*type
;
3022 struct objfile
*objfile
;
3027 register struct symbol
*sym
;
3029 struct pending
**symlist
;
3030 struct pending
*osyms
, *syms
;
3035 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3036 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3037 to do? For now, force all enum values to file scope. */
3038 if (within_function
)
3039 symlist
= &local_symbols
;
3042 symlist
= &file_symbols
;
3044 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3048 /* Size. Perhaps this does not have to be conditionalized on
3049 os9k_stabs (assuming the name of an enum constant can't start
3051 read_huge_number (pp
, 0, &nbits
);
3053 return error_type (pp
);
3056 /* Read the value-names and their values.
3057 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3058 A semicolon or comma instead of a NAME means the end. */
3059 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3061 STABS_CONTINUE (pp
);
3063 while (*p
!= ':') p
++;
3064 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
3066 n
= read_huge_number (pp
, ',', &nbits
);
3068 return error_type (pp
);
3070 sym
= (struct symbol
*)
3071 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3072 memset (sym
, 0, sizeof (struct symbol
));
3073 SYMBOL_NAME (sym
) = name
;
3074 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
3075 SYMBOL_CLASS (sym
) = LOC_CONST
;
3076 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3077 SYMBOL_VALUE (sym
) = n
;
3078 add_symbol_to_list (sym
, symlist
);
3083 (*pp
)++; /* Skip the semicolon. */
3085 /* Now fill in the fields of the type-structure. */
3087 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3088 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3089 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3090 TYPE_NFIELDS (type
) = nsyms
;
3091 TYPE_FIELDS (type
) = (struct field
*)
3092 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3093 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3095 /* Find the symbols for the values and put them into the type.
3096 The symbols can be found in the symlist that we put them on
3097 to cause them to be defined. osyms contains the old value
3098 of that symlist; everything up to there was defined by us. */
3099 /* Note that we preserve the order of the enum constants, so
3100 that in something like "enum {FOO, LAST_THING=FOO}" we print
3101 FOO, not LAST_THING. */
3103 for (syms
= *symlist
, n
= nsyms
- 1; ; syms
= syms
->next
)
3105 int last
= syms
== osyms
? o_nsyms
: 0;
3106 int j
= syms
->nsyms
;
3107 for (; --j
>= last
; --n
)
3109 struct symbol
*xsym
= syms
->symbol
[j
];
3110 SYMBOL_TYPE (xsym
) = type
;
3111 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
3112 TYPE_FIELD_VALUE (type
, n
) = 0;
3113 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3114 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3123 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3124 typedefs in every file (for int, long, etc):
3126 type = b <signed> <width>; <offset>; <nbits>
3127 signed = u or s. Possible c in addition to u or s (for char?).
3128 offset = offset from high order bit to start bit of type.
3129 width is # bytes in object of this type, nbits is # bits in type.
3131 The width/offset stuff appears to be for small objects stored in
3132 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3135 static struct type
*
3136 read_sun_builtin_type (pp
, typenums
, objfile
)
3139 struct objfile
*objfile
;
3154 return error_type (pp
);
3158 /* For some odd reason, all forms of char put a c here. This is strange
3159 because no other type has this honor. We can safely ignore this because
3160 we actually determine 'char'acterness by the number of bits specified in
3166 /* The first number appears to be the number of bytes occupied
3167 by this type, except that unsigned short is 4 instead of 2.
3168 Since this information is redundant with the third number,
3169 we will ignore it. */
3170 read_huge_number (pp
, ';', &nbits
);
3172 return error_type (pp
);
3174 /* The second number is always 0, so ignore it too. */
3175 read_huge_number (pp
, ';', &nbits
);
3177 return error_type (pp
);
3179 /* The third number is the number of bits for this type. */
3180 type_bits
= read_huge_number (pp
, 0, &nbits
);
3182 return error_type (pp
);
3183 /* The type *should* end with a semicolon. If it are embedded
3184 in a larger type the semicolon may be the only way to know where
3185 the type ends. If this type is at the end of the stabstring we
3186 can deal with the omitted semicolon (but we don't have to like
3187 it). Don't bother to complain(), Sun's compiler omits the semicolon
3193 return init_type (TYPE_CODE_VOID
, 1,
3194 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3197 return init_type (TYPE_CODE_INT
,
3198 type_bits
/ TARGET_CHAR_BIT
,
3199 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *)NULL
,
3203 static struct type
*
3204 read_sun_floating_type (pp
, typenums
, objfile
)
3207 struct objfile
*objfile
;
3213 /* The first number has more details about the type, for example
3215 details
= read_huge_number (pp
, ';', &nbits
);
3217 return error_type (pp
);
3219 /* The second number is the number of bytes occupied by this type */
3220 nbytes
= read_huge_number (pp
, ';', &nbits
);
3222 return error_type (pp
);
3224 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3225 || details
== NF_COMPLEX32
)
3226 /* This is a type we can't handle, but we do know the size.
3227 We also will be able to give it a name. */
3228 return init_type (TYPE_CODE_ERROR
, nbytes
, 0, NULL
, objfile
);
3230 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3233 /* Read a number from the string pointed to by *PP.
3234 The value of *PP is advanced over the number.
3235 If END is nonzero, the character that ends the
3236 number must match END, or an error happens;
3237 and that character is skipped if it does match.
3238 If END is zero, *PP is left pointing to that character.
3240 If the number fits in a long, set *BITS to 0 and return the value.
3241 If not, set *BITS to be the number of bits in the number and return 0.
3243 If encounter garbage, set *BITS to -1 and return 0. */
3246 read_huge_number (pp
, end
, bits
)
3266 /* Leading zero means octal. GCC uses this to output values larger
3267 than an int (because that would be hard in decimal). */
3275 upper_limit
= ULONG_MAX
/ radix
;
3277 upper_limit
= LONG_MAX
/ radix
;
3279 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3281 if (n
<= upper_limit
)
3284 n
+= c
- '0'; /* FIXME this overflows anyway */
3289 /* This depends on large values being output in octal, which is
3296 /* Ignore leading zeroes. */
3300 else if (c
== '2' || c
== '3')
3326 /* Large decimal constants are an error (because it is hard to
3327 count how many bits are in them). */
3333 /* -0x7f is the same as 0x80. So deal with it by adding one to
3334 the number of bits. */
3346 /* It's *BITS which has the interesting information. */
3350 static struct type
*
3351 read_range_type (pp
, typenums
, objfile
)
3354 struct objfile
*objfile
;
3360 struct type
*result_type
;
3361 struct type
*index_type
;
3363 /* First comes a type we are a subrange of.
3364 In C it is usually 0, 1 or the type being defined. */
3365 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3366 not just a type number. */
3367 if (read_type_number (pp
, rangenums
) != 0)
3368 return error_type (pp
);
3369 self_subrange
= (rangenums
[0] == typenums
[0] &&
3370 rangenums
[1] == typenums
[1]);
3372 /* A semicolon should now follow; skip it. */
3376 /* The remaining two operands are usually lower and upper bounds
3377 of the range. But in some special cases they mean something else. */
3378 n2
= read_huge_number (pp
, ';', &n2bits
);
3379 n3
= read_huge_number (pp
, ';', &n3bits
);
3381 if (n2bits
== -1 || n3bits
== -1)
3382 return error_type (pp
);
3384 /* If limits are huge, must be large integral type. */
3385 if (n2bits
!= 0 || n3bits
!= 0)
3387 char got_signed
= 0;
3388 char got_unsigned
= 0;
3389 /* Number of bits in the type. */
3392 /* Range from 0 to <large number> is an unsigned large integral type. */
3393 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
3398 /* Range from <large number> to <large number>-1 is a large signed
3399 integral type. Take care of the case where <large number> doesn't
3400 fit in a long but <large number>-1 does. */
3401 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
3402 || (n2bits
!= 0 && n3bits
== 0
3403 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
3410 if (got_signed
|| got_unsigned
)
3412 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
3413 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
3417 return error_type (pp
);
3420 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3421 if (self_subrange
&& n2
== 0 && n3
== 0)
3422 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
3424 /* If n3 is zero and n2 is not, we want a floating type,
3425 and n2 is the width in bytes.
3427 Fortran programs appear to use this for complex types also,
3428 and they give no way to distinguish between double and single-complex!
3430 GDB does not have complex types.
3432 Just return the complex as a float of that size. It won't work right
3433 for the complex values, but at least it makes the file loadable. */
3435 if (n3
== 0 && n2
> 0)
3437 return init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
3440 /* If the upper bound is -1, it must really be an unsigned int. */
3442 else if (n2
== 0 && n3
== -1)
3444 /* It is unsigned int or unsigned long. */
3445 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3446 compatibility hack. */
3447 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3448 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3451 /* Special case: char is defined (Who knows why) as a subrange of
3452 itself with range 0-127. */
3453 else if (self_subrange
&& n2
== 0 && n3
== 127)
3454 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3456 /* We used to do this only for subrange of self or subrange of int. */
3460 /* n3 actually gives the size. */
3461 return init_type (TYPE_CODE_INT
, - n3
, TYPE_FLAG_UNSIGNED
,
3464 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3466 return init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
3468 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3469 "unsigned long", and we already checked for that,
3470 so don't need to test for it here. */
3472 /* I think this is for Convex "long long". Since I don't know whether
3473 Convex sets self_subrange, I also accept that particular size regardless
3474 of self_subrange. */
3475 else if (n3
== 0 && n2
< 0
3477 || n2
== - TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
3478 return init_type (TYPE_CODE_INT
, - n2
, 0, NULL
, objfile
);
3479 else if (n2
== -n3
-1)
3482 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
3484 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
3485 if (n3
== 0x7fffffff)
3486 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
3489 /* We have a real range type on our hands. Allocate space and
3490 return a real pointer. */
3492 /* At this point I don't have the faintest idea how to deal with
3493 a self_subrange type; I'm going to assume that this is used
3494 as an idiom, and that all of them are special cases. So . . . */
3496 return error_type (pp
);
3498 index_type
= *dbx_lookup_type (rangenums
);
3499 if (index_type
== NULL
)
3501 /* Does this actually ever happen? Is that why we are worrying
3502 about dealing with it rather than just calling error_type? */
3504 static struct type
*range_type_index
;
3506 complain (&range_type_base_complaint
, rangenums
[1]);
3507 if (range_type_index
== NULL
)
3509 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
3510 0, "range type index type", NULL
);
3511 index_type
= range_type_index
;
3514 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
3515 return (result_type
);
3518 /* Read in an argument list. This is a list of types, separated by commas
3519 and terminated with END. Return the list of types read in, or (struct type
3520 **)-1 if there is an error. */
3522 static struct type
**
3523 read_args (pp
, end
, objfile
)
3526 struct objfile
*objfile
;
3528 /* FIXME! Remove this arbitrary limit! */
3529 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3535 /* Invalid argument list: no ','. */
3536 return (struct type
**)-1;
3538 STABS_CONTINUE (pp
);
3539 types
[n
++] = read_type (pp
, objfile
);
3541 (*pp
)++; /* get past `end' (the ':' character) */
3545 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3547 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3549 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3550 memset (rval
+ n
, 0, sizeof (struct type
*));
3554 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3556 memcpy (rval
, types
, n
* sizeof (struct type
*));
3560 /* Common block handling. */
3562 /* List of symbols declared since the last BCOMM. This list is a tail
3563 of local_symbols. When ECOMM is seen, the symbols on the list
3564 are noted so their proper addresses can be filled in later,
3565 using the common block base address gotten from the assembler
3568 static struct pending
*common_block
;
3569 static int common_block_i
;
3571 /* Name of the current common block. We get it from the BCOMM instead of the
3572 ECOMM to match IBM documentation (even though IBM puts the name both places
3573 like everyone else). */
3574 static char *common_block_name
;
3576 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3577 to remain after this function returns. */
3580 common_block_start (name
, objfile
)
3582 struct objfile
*objfile
;
3584 if (common_block_name
!= NULL
)
3586 static struct complaint msg
= {
3587 "Invalid symbol data: common block within common block",
3591 common_block
= local_symbols
;
3592 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3593 common_block_name
= obsavestring (name
, strlen (name
),
3594 &objfile
-> symbol_obstack
);
3597 /* Process a N_ECOMM symbol. */
3600 common_block_end (objfile
)
3601 struct objfile
*objfile
;
3603 /* Symbols declared since the BCOMM are to have the common block
3604 start address added in when we know it. common_block and
3605 common_block_i point to the first symbol after the BCOMM in
3606 the local_symbols list; copy the list and hang it off the
3607 symbol for the common block name for later fixup. */
3610 struct pending
*new = 0;
3611 struct pending
*next
;
3614 if (common_block_name
== NULL
)
3616 static struct complaint msg
= {"ECOMM symbol unmatched by BCOMM", 0, 0};
3621 sym
= (struct symbol
*)
3622 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
3623 memset (sym
, 0, sizeof (struct symbol
));
3624 SYMBOL_NAME (sym
) = common_block_name
;
3625 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3627 /* Now we copy all the symbols which have been defined since the BCOMM. */
3629 /* Copy all the struct pendings before common_block. */
3630 for (next
= local_symbols
;
3631 next
!= NULL
&& next
!= common_block
;
3634 for (j
= 0; j
< next
->nsyms
; j
++)
3635 add_symbol_to_list (next
->symbol
[j
], &new);
3638 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3639 NULL, it means copy all the local symbols (which we already did
3642 if (common_block
!= NULL
)
3643 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
3644 add_symbol_to_list (common_block
->symbol
[j
], &new);
3646 SYMBOL_TYPE (sym
) = (struct type
*) new;
3648 /* Should we be putting local_symbols back to what it was?
3651 i
= hashname (SYMBOL_NAME (sym
));
3652 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3653 global_sym_chain
[i
] = sym
;
3654 common_block_name
= NULL
;
3657 /* Add a common block's start address to the offset of each symbol
3658 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3659 the common block name). */
3662 fix_common_block (sym
, valu
)
3666 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
3667 for ( ; next
; next
= next
->next
)
3670 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3671 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3677 /* What about types defined as forward references inside of a small lexical
3679 /* Add a type to the list of undefined types to be checked through
3680 once this file has been read in. */
3683 add_undefined_type (type
)
3686 if (undef_types_length
== undef_types_allocated
)
3688 undef_types_allocated
*= 2;
3689 undef_types
= (struct type
**)
3690 xrealloc ((char *) undef_types
,
3691 undef_types_allocated
* sizeof (struct type
*));
3693 undef_types
[undef_types_length
++] = type
;
3696 /* Go through each undefined type, see if it's still undefined, and fix it
3697 up if possible. We have two kinds of undefined types:
3699 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3700 Fix: update array length using the element bounds
3701 and the target type's length.
3702 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3703 yet defined at the time a pointer to it was made.
3704 Fix: Do a full lookup on the struct/union tag. */
3706 cleanup_undefined_types ()
3710 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3712 switch (TYPE_CODE (*type
))
3715 case TYPE_CODE_STRUCT
:
3716 case TYPE_CODE_UNION
:
3717 case TYPE_CODE_ENUM
:
3719 /* Check if it has been defined since. Need to do this here
3720 as well as in check_stub_type to deal with the (legitimate in
3721 C though not C++) case of several types with the same name
3722 in different source files. */
3723 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3725 struct pending
*ppt
;
3727 /* Name of the type, without "struct" or "union" */
3728 char *typename
= TYPE_TAG_NAME (*type
);
3730 if (typename
== NULL
)
3732 static struct complaint msg
= {"need a type name", 0, 0};
3736 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3738 for (i
= 0; i
< ppt
->nsyms
; i
++)
3740 struct symbol
*sym
= ppt
->symbol
[i
];
3742 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3743 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3744 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3746 && STREQ (SYMBOL_NAME (sym
), typename
))
3748 memcpy (*type
, SYMBOL_TYPE (sym
),
3749 sizeof (struct type
));
3757 case TYPE_CODE_ARRAY
:
3759 /* This is a kludge which is here for historical reasons
3760 because I suspect that check_stub_type does not get
3761 called everywhere it needs to be called for arrays. Even
3762 with this kludge, those places are broken for the case
3763 where the stub type is defined in another compilation
3764 unit, but this kludge at least deals with it for the case
3765 in which it is the same compilation unit.
3767 Don't try to do this by calling check_stub_type; it might
3768 cause symbols to be read in lookup_symbol, and the symbol
3769 reader is not reentrant. */
3771 struct type
*range_type
;
3774 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3776 if (TYPE_NFIELDS (*type
) != 1)
3778 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3779 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3782 /* Now recompute the length of the array type, based on its
3783 number of elements and the target type's length. */
3784 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3785 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3786 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3787 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3789 /* If the target type is not a stub, we could be clearing
3790 TYPE_FLAG_TARGET_STUB for *type. */
3797 static struct complaint msg
= {"\
3798 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3799 complain (&msg
, TYPE_CODE (*type
));
3805 undef_types_length
= 0;
3808 /* Scan through all of the global symbols defined in the object file,
3809 assigning values to the debugging symbols that need to be assigned
3810 to. Get these symbols from the minimal symbol table.
3811 Return 1 if there might still be unresolved debugging symbols, else 0. */
3813 static int scan_file_globals_1
PARAMS ((struct objfile
*));
3816 scan_file_globals_1 (objfile
)
3817 struct objfile
*objfile
;
3820 struct minimal_symbol
*msymbol
;
3821 struct symbol
*sym
, *prev
;
3823 /* Avoid expensive loop through all minimal symbols if there are
3824 no unresolved symbols. */
3825 for (hash
= 0; hash
< HASHSIZE
; hash
++)
3827 if (global_sym_chain
[hash
])
3830 if (hash
>= HASHSIZE
)
3833 if (objfile
->msymbols
== 0) /* Beware the null file. */
3836 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3840 /* Skip static symbols. */
3841 switch (MSYMBOL_TYPE (msymbol
))
3853 /* Get the hash index and check all the symbols
3854 under that hash index. */
3856 hash
= hashname (SYMBOL_NAME (msymbol
));
3858 for (sym
= global_sym_chain
[hash
]; sym
;)
3860 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3861 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3863 /* Splice this symbol out of the hash chain and
3864 assign the value we have to it. */
3867 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3871 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3874 /* Check to see whether we need to fix up a common block. */
3875 /* Note: this code might be executed several times for
3876 the same symbol if there are multiple references. */
3878 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3880 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3884 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3887 SYMBOL_SECTION (sym
) = SYMBOL_SECTION (msymbol
);
3891 sym
= SYMBOL_VALUE_CHAIN (prev
);
3895 sym
= global_sym_chain
[hash
];
3901 sym
= SYMBOL_VALUE_CHAIN (sym
);
3908 /* Assign values to global debugging symbols.
3909 Search the passed objfile first, then try the runtime common symbols.
3910 Complain about any remaining unresolved symbols and remove them
3914 scan_file_globals (objfile
)
3915 struct objfile
*objfile
;
3918 struct symbol
*sym
, *prev
;
3920 if (scan_file_globals_1 (objfile
) == 0)
3922 if (rt_common_objfile
&& scan_file_globals_1 (rt_common_objfile
) == 0)
3925 for (hash
= 0; hash
< HASHSIZE
; hash
++)
3927 sym
= global_sym_chain
[hash
];
3930 complain (&unresolved_sym_chain_complaint
,
3931 objfile
->name
, SYMBOL_NAME (sym
));
3933 /* Change the symbol address from the misleading chain value
3936 sym
= SYMBOL_VALUE_CHAIN (sym
);
3937 SYMBOL_VALUE_ADDRESS (prev
) = 0;
3940 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3943 /* Initialize anything that needs initializing when starting to read
3944 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3952 /* Initialize anything that needs initializing when a completely new
3953 symbol file is specified (not just adding some symbols from another
3954 file, e.g. a shared library). */
3957 stabsread_new_init ()
3959 /* Empty the hash table of global syms looking for values. */
3960 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3963 /* Initialize anything that needs initializing at the same time as
3964 start_symtab() is called. */
3968 global_stabs
= NULL
; /* AIX COFF */
3969 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3970 n_this_object_header_files
= 1;
3971 type_vector_length
= 0;
3972 type_vector
= (struct type
**) 0;
3974 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3975 common_block_name
= NULL
;
3980 /* Call after end_symtab() */
3986 free ((char *) type_vector
);
3989 type_vector_length
= 0;
3990 previous_stab_code
= 0;
3994 finish_global_stabs (objfile
)
3995 struct objfile
*objfile
;
3999 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
4000 free ((PTR
) global_stabs
);
4001 global_stabs
= NULL
;
4005 /* Initializer for this module */
4008 _initialize_stabsread ()
4010 undef_types_allocated
= 20;
4011 undef_types_length
= 0;
4012 undef_types
= (struct type
**)
4013 xmalloc (undef_types_allocated
* sizeof (struct type
*));