1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
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. */
32 #include "symfile.h" /* Needed for "struct complaint" */
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
37 /* Ask stabsread.h to define the vars it normally declares `extern'. */
39 #include "stabsread.h" /* Our own declarations */
42 /* The routines that read and process a complete stabs for a C struct or
43 C++ class pass lists of data member fields and lists of member function
44 fields in an instance of a field_info structure, as defined below.
45 This is part of some reorganization of low level C++ support and is
46 expected to eventually go away... (FIXME) */
52 struct nextfield
*next
;
56 struct next_fnfieldlist
58 struct next_fnfieldlist
*next
;
59 struct fn_fieldlist fn_fieldlist
;
64 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
67 read_huge_number
PARAMS ((char **, int, long *, int *));
70 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
74 fix_common_block
PARAMS ((struct symbol
*, int));
77 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
80 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
83 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
86 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
89 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
93 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
97 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
101 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
105 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
108 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
112 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
115 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
117 static struct type
**
118 read_args
PARAMS ((char **, int, struct objfile
*));
121 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
124 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
125 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
127 /* Define this as 1 if a pcc declaration of a char or short argument
128 gives the correct address. Otherwise assume pcc gives the
129 address of the corresponding int, which is not the same on a
130 big-endian machine. */
132 #ifndef BELIEVE_PCC_PROMOTION
133 #define BELIEVE_PCC_PROMOTION 0
136 /* During some calls to read_type (and thus to read_range_type), this
137 contains the name of the type being defined. Range types are only
138 used in C as basic types. We use the name to distinguish the otherwise
139 identical basic types "int" and "long" and their unsigned versions.
140 FIXME, this should disappear with better type management. */
142 static char *long_kludge_name
;
145 struct complaint dbx_class_complaint
=
147 "encountered DBX-style class variable debugging information.\n\
148 You seem to have compiled your program with \
149 \"g++ -g0\" instead of \"g++ -g\".\n\
150 Therefore GDB will not know about your class variables", 0, 0
154 struct complaint invalid_cpp_abbrev_complaint
=
155 {"invalid C++ abbreviation `%s'", 0, 0};
157 struct complaint invalid_cpp_type_complaint
=
158 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
160 struct complaint member_fn_complaint
=
161 {"member function type missing, got '%c'", 0, 0};
163 struct complaint const_vol_complaint
=
164 {"const/volatile indicator missing, got '%c'", 0, 0};
166 struct complaint error_type_complaint
=
167 {"debug info mismatch between compiler and debugger", 0, 0};
169 struct complaint invalid_member_complaint
=
170 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
172 struct complaint range_type_base_complaint
=
173 {"base type %d of range type is not defined", 0, 0};
175 struct complaint reg_value_complaint
=
176 {"register number too large in symbol %s", 0, 0};
178 struct complaint stabs_general_complaint
=
181 /* Make a list of forward references which haven't been defined. */
183 static struct type
**undef_types
;
184 static int undef_types_allocated
;
185 static int undef_types_length
;
187 /* Check for and handle cretinous stabs symbol name continuation! */
188 #define STABS_CONTINUE(pp) \
190 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
198 register char *p
= name
;
199 register int total
= p
[0];
214 /* Ensure result is positive. */
217 total
+= (1000 << 6);
219 return (total
% HASHSIZE
);
223 /* Look up a dbx type-number pair. Return the address of the slot
224 where the type for that number-pair is stored.
225 The number-pair is in TYPENUMS.
227 This can be used for finding the type associated with that pair
228 or for associating a new type with the pair. */
231 dbx_lookup_type (typenums
)
234 register int filenum
= typenums
[0];
235 register int index
= typenums
[1];
237 register int real_filenum
;
238 register struct header_file
*f
;
241 if (filenum
== -1) /* -1,-1 is for temporary types. */
244 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
245 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
246 filenum
, index
, symnum
);
250 /* Type is defined outside of header files.
251 Find it in this object file's type vector. */
252 if (index
>= type_vector_length
)
254 old_len
= type_vector_length
;
257 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
258 type_vector
= (struct type
**)
259 malloc (type_vector_length
* sizeof (struct type
*));
261 while (index
>= type_vector_length
)
263 type_vector_length
*= 2;
265 type_vector
= (struct type
**)
266 xrealloc ((char *) type_vector
,
267 (type_vector_length
* sizeof (struct type
*)));
268 memset (&type_vector
[old_len
], 0,
269 (type_vector_length
- old_len
) * sizeof (struct type
*));
271 return (&type_vector
[index
]);
275 real_filenum
= this_object_header_files
[filenum
];
277 if (real_filenum
>= n_header_files
)
282 f
= &header_files
[real_filenum
];
284 f_orig_length
= f
->length
;
285 if (index
>= f_orig_length
)
287 while (index
>= f
->length
)
291 f
->vector
= (struct type
**)
292 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
293 memset (&f
->vector
[f_orig_length
], 0,
294 (f
->length
- f_orig_length
) * sizeof (struct type
*));
296 return (&f
->vector
[index
]);
300 /* Make sure there is a type allocated for type numbers TYPENUMS
301 and return the type object.
302 This can create an empty (zeroed) type object.
303 TYPENUMS may be (-1, -1) to return a new type object that is not
304 put into the type vector, and so may not be referred to by number. */
307 dbx_alloc_type (typenums
, objfile
)
309 struct objfile
*objfile
;
311 register struct type
**type_addr
;
313 if (typenums
[0] == -1)
315 return (alloc_type (objfile
));
318 type_addr
= dbx_lookup_type (typenums
);
320 /* If we are referring to a type not known at all yet,
321 allocate an empty type for it.
322 We will fill it in later if we find out how. */
325 *type_addr
= alloc_type (objfile
);
331 /* for all the stabs in a given stab vector, build appropriate types
332 and fix their symbols in given symbol vector. */
335 patch_block_stabs (symbols
, stabs
, objfile
)
336 struct pending
*symbols
;
337 struct pending_stabs
*stabs
;
338 struct objfile
*objfile
;
348 /* for all the stab entries, find their corresponding symbols and
349 patch their types! */
351 for (ii
= 0; ii
< stabs
->count
; ++ii
)
353 name
= stabs
->stab
[ii
];
354 pp
= (char*) strchr (name
, ':');
355 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
358 #ifndef IBM6000_TARGET
359 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
365 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
368 lookup_function_type (read_type (&pp
, objfile
));
372 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
380 /* Read a number by which a type is referred to in dbx data,
381 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
382 Just a single number N is equivalent to (0,N).
383 Return the two numbers by storing them in the vector TYPENUMS.
384 TYPENUMS will then be used as an argument to dbx_lookup_type. */
387 read_type_number (pp
, typenums
)
389 register int *typenums
;
394 typenums
[0] = read_number (pp
, ',');
395 typenums
[1] = read_number (pp
, ')');
400 typenums
[1] = read_number (pp
, 0);
405 /* To handle GNU C++ typename abbreviation, we need to be able to
406 fill in a type's name as soon as space for that type is allocated.
407 `type_synonym_name' is the name of the type being allocated.
408 It is cleared as soon as it is used (lest all allocated types
411 static char *type_synonym_name
;
415 define_symbol (valu
, string
, desc
, type
, objfile
)
420 struct objfile
*objfile
;
422 register struct symbol
*sym
;
423 char *p
= (char *) strchr (string
, ':');
427 struct type
*temptype
;
429 /* We would like to eliminate nameless symbols, but keep their types.
430 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
431 to type 2, but, should not create a symbol to address that type. Since
432 the symbol will be nameless, there is no way any user can refer to it. */
436 /* Ignore syms with empty names. */
440 /* Ignore old-style symbols from cc -go */
444 /* If a nameless stab entry, all we need is the type, not the symbol.
445 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
446 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
448 sym
= (struct symbol
*)
449 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
450 memset (sym
, 0, sizeof (struct symbol
));
452 if (processing_gcc_compilation
)
454 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
455 number of bytes occupied by a type or object, which we ignore. */
456 SYMBOL_LINE(sym
) = desc
;
460 SYMBOL_LINE(sym
) = 0; /* unknown */
463 if (string
[0] == CPLUS_MARKER
)
465 /* Special GNU C++ names. */
469 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
470 &objfile
-> symbol_obstack
);
473 case 'v': /* $vtbl_ptr_type */
474 /* Was: SYMBOL_NAME (sym) = "vptr"; */
478 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
479 &objfile
-> symbol_obstack
);
483 /* This was an anonymous type that was never fixed up. */
493 SYMBOL_NAME (sym
) = (char *)
494 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
495 /* Open-coded bcopy--saves function call time. */
497 register char *p1
= string
;
498 register char *p2
= SYMBOL_NAME (sym
);
508 /* Determine the type of name being defined. */
509 /* The Acorn RISC machine's compiler can put out locals that don't
510 start with "234=" or "(3,4)=", so assume anything other than the
511 deftypes we know how to handle is a local. */
512 if (!strchr ("cfFGpPrStTvVXCR", *p
))
517 /* c is a special case, not followed by a type-number.
518 SYMBOL:c=iVALUE for an integer constant symbol.
519 SYMBOL:c=rVALUE for a floating constant symbol.
520 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
521 e.g. "b:c=e6,0" for "const b = blob1"
522 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
526 error ("Invalid symbol data at symtab pos %d.", symnum
);
534 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
537 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (double));
538 memcpy (dbl_valu
, &d
, sizeof (double));
539 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
540 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
541 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
546 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
548 SYMBOL_VALUE (sym
) = atoi (p
);
549 SYMBOL_CLASS (sym
) = LOC_CONST
;
553 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
554 e.g. "b:c=e6,0" for "const b = blob1"
555 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
559 read_type_number (&p
, typenums
);
561 error ("Invalid symbol data: no comma in enum const symbol");
563 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
564 SYMBOL_VALUE (sym
) = atoi (p
);
565 SYMBOL_CLASS (sym
) = LOC_CONST
;
569 error ("Invalid symbol data at symtab pos %d.", symnum
);
571 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
572 add_symbol_to_list (sym
, &file_symbols
);
576 /* Now usually comes a number that says which data type,
577 and possibly more stuff to define the type
578 (all of which is handled by read_type) */
580 if (deftype
== 'p' && *p
== 'F')
581 /* pF is a two-letter code that means a function parameter in Fortran.
582 The type-number specifies the type of the return value.
583 Translate it into a pointer-to-function type. */
587 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
591 /* The symbol class letter is followed by a type (typically the
592 type of the symbol, or its return-type, or etc). Read it. */
599 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
600 strlen (SYMBOL_NAME (sym
)),
601 &objfile
-> symbol_obstack
);
604 /* Here we save the name of the symbol for read_range_type, which
605 ends up reading in the basic types. In stabs, unfortunately there
606 is no distinction between "int" and "long" types except their
607 names. Until we work out a saner type policy (eliminating most
608 builtin types and using the names specified in the files), we
609 save away the name so that far away from here in read_range_type,
610 we can examine it to decide between "int" and "long". FIXME. */
611 long_kludge_name
= SYMBOL_NAME (sym
);
613 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
619 /* The name of a caught exception. */
620 SYMBOL_CLASS (sym
) = LOC_LABEL
;
621 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
622 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
623 add_symbol_to_list (sym
, &local_symbols
);
627 /* A static function definition. */
628 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
629 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
630 add_symbol_to_list (sym
, &file_symbols
);
631 /* fall into process_function_types. */
633 process_function_types
:
634 /* Function result types are described as the result type in stabs.
635 We need to convert this to the function-returning-type-X type
636 in GDB. E.g. "int" is converted to "function returning int". */
637 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
640 /* This code doesn't work -- it needs to realloc and can't. */
641 /* Attempt to set up to record a function prototype... */
642 struct type
*new = alloc_type (objfile
);
644 /* Generate a template for the type of this function. The
645 types of the arguments will be added as we read the symbol
647 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
648 SYMBOL_TYPE(sym
) = new;
649 TYPE_OBJFILE (new) = objfile
;
650 in_function_type
= new;
652 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
655 /* fall into process_prototype_types */
657 process_prototype_types
:
658 /* Sun acc puts declared types of arguments here. We don't care
659 about their actual types (FIXME -- we should remember the whole
660 function prototype), but the list may define some new types
661 that we have to remember, so we must scan it now. */
664 read_type (&p
, objfile
);
669 /* A global function definition. */
670 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
671 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
672 add_symbol_to_list (sym
, &global_symbols
);
673 goto process_function_types
;
676 /* For a class G (global) symbol, it appears that the
677 value is not correct. It is necessary to search for the
678 corresponding linker definition to find the value.
679 These definitions appear at the end of the namelist. */
680 i
= hashname (SYMBOL_NAME (sym
));
681 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
682 global_sym_chain
[i
] = sym
;
683 SYMBOL_CLASS (sym
) = LOC_STATIC
;
684 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
685 add_symbol_to_list (sym
, &global_symbols
);
688 /* This case is faked by a conditional above,
689 when there is no code letter in the dbx data.
690 Dbx data never actually contains 'l'. */
692 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
693 SYMBOL_VALUE (sym
) = valu
;
694 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
695 add_symbol_to_list (sym
, &local_symbols
);
699 /* Normally this is a parameter, a LOC_ARG. On the i960, it
700 can also be a LOC_LOCAL_ARG depending on symbol type. */
701 #ifndef DBX_PARM_SYMBOL_CLASS
702 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
704 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
705 SYMBOL_VALUE (sym
) = valu
;
706 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
708 /* This doesn't work yet. */
709 add_param_to_type (&in_function_type
, sym
);
711 add_symbol_to_list (sym
, &local_symbols
);
713 /* If it's gcc-compiled, if it says `short', believe it. */
714 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
717 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
718 /* This macro is defined on machines (e.g. sparc) where
719 we should believe the type of a PCC 'short' argument,
720 but shouldn't believe the address (the address is
721 the address of the corresponding int). Note that
722 this is only different from the BELIEVE_PCC_PROMOTION
723 case on big-endian machines.
725 My guess is that this correction, as opposed to changing
726 the parameter to an 'int' (as done below, for PCC
727 on most machines), is the right thing to do
728 on all machines, but I don't want to risk breaking
729 something that already works. On most PCC machines,
730 the sparc problem doesn't come up because the calling
731 function has to zero the top bytes (not knowing whether
732 the called function wants an int or a short), so there
733 is no practical difference between an int and a short
734 (except perhaps what happens when the GDB user types
735 "print short_arg = 0x10000;").
737 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
738 actually produces the correct address (we don't need to fix it
739 up). I made this code adapt so that it will offset the symbol
740 if it was pointing at an int-aligned location and not
741 otherwise. This way you can use the same gdb for 4.0.x and
744 If the parameter is shorter than an int, and is integral
745 (e.g. char, short, or unsigned equivalent), and is claimed to
746 be passed on an integer boundary, don't believe it! Offset the
747 parameter's address to the tail-end of that integer. */
749 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
750 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
751 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
752 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
754 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
755 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
759 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
761 /* If PCC says a parameter is a short or a char,
762 it is really an int. */
763 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
764 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
765 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
767 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
768 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
773 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
776 /* acc seems to use P to delare the prototypes of functions that
777 are referenced by this file. gdb is not prepared to deal
778 with this extra information. FIXME, it ought to. */
780 goto process_prototype_types
;
782 /* Parameter which is in a register. */
783 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
784 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
785 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
787 complain (®_value_complaint
, SYMBOL_NAME (sym
));
788 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
790 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
791 add_symbol_to_list (sym
, &local_symbols
);
796 /* Register variable (either global or local). */
797 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
798 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
799 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
801 complain (®_value_complaint
, SYMBOL_NAME (sym
));
802 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
804 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
806 add_symbol_to_list (sym
, &local_symbols
);
808 add_symbol_to_list (sym
, &file_symbols
);
812 /* Static symbol at top level of file */
813 SYMBOL_CLASS (sym
) = LOC_STATIC
;
814 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
815 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
816 add_symbol_to_list (sym
, &file_symbols
);
820 /* For a nameless type, we don't want a create a symbol, thus we
821 did not use `sym'. Return without further processing. */
822 if (nameless
) return NULL
;
824 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
825 SYMBOL_VALUE (sym
) = valu
;
826 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
827 /* C++ vagaries: we may have a type which is derived from
828 a base type which did not have its name defined when the
829 derived class was output. We fill in the derived class's
830 base part member's name here in that case. */
831 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
832 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
833 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
834 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
837 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
838 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
839 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
840 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
843 add_symbol_to_list (sym
, &file_symbols
);
847 /* For a nameless type, we don't want a create a symbol, thus we
848 did not use `sym'. Return without further processing. */
849 if (nameless
) return NULL
;
851 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
852 SYMBOL_VALUE (sym
) = valu
;
853 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
854 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
855 TYPE_NAME (SYMBOL_TYPE (sym
))
856 = obconcat (&objfile
-> type_obstack
, "",
857 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
859 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
860 ? "struct " : "union ")),
862 add_symbol_to_list (sym
, &file_symbols
);
866 register struct symbol
*typedef_sym
= (struct symbol
*)
867 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
868 memset (typedef_sym
, 0, sizeof (struct symbol
));
869 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
870 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
872 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
873 SYMBOL_VALUE (typedef_sym
) = valu
;
874 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
875 add_symbol_to_list (typedef_sym
, &file_symbols
);
880 /* Static symbol of local scope */
881 SYMBOL_CLASS (sym
) = LOC_STATIC
;
882 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
883 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
884 add_symbol_to_list (sym
, &local_symbols
);
888 /* Reference parameter */
889 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
890 SYMBOL_VALUE (sym
) = valu
;
891 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
892 add_symbol_to_list (sym
, &local_symbols
);
896 /* This is used by Sun FORTRAN for "function result value".
897 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
898 that Pascal uses it too, but when I tried it Pascal used
899 "x:3" (local symbol) instead. */
900 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
901 SYMBOL_VALUE (sym
) = valu
;
902 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
903 add_symbol_to_list (sym
, &local_symbols
);
907 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
913 /* Skip rest of this symbol and return an error type.
915 General notes on error recovery: error_type always skips to the
916 end of the symbol (modulo cretinous dbx symbol name continuation).
920 return error_type (pp);
922 is wrong because if *pp starts out pointing at '\0' (typically as the
923 result of an earlier error), it will be incremented to point to the
924 start of the next symbol, which might produce strange results, at least
925 if you run off the end of the string table. Instead use
928 return error_type (pp);
934 foo = error_type (pp);
938 And in case it isn't obvious, the point of all this hair is so the compiler
939 can define new types and new syntaxes, and old versions of the
940 debugger will be able to read the new symbol tables. */
946 complain (&error_type_complaint
, 0);
949 /* Skip to end of symbol. */
955 /* Check for and handle cretinous dbx symbol name continuation! */
956 if ((*pp
)[-1] == '\\')
958 *pp
= next_symbol_text ();
965 return (builtin_type_error
);
969 /* Read a dbx type reference or definition;
970 return the type that is meant.
971 This can be just a number, in which case it references
972 a type already defined and placed in type_vector.
973 Or the number can be followed by an =, in which case
974 it means to define a new type according to the text that
978 read_type (pp
, objfile
)
980 struct objfile
*objfile
;
982 register struct type
*type
= 0;
986 char type_descriptor
;
988 /* Read type number if present. The type number may be omitted.
989 for instance in a two-dimensional array declared with type
990 "ar1;1;10;ar1;1;10;4". */
991 if ((**pp
>= '0' && **pp
<= '9')
994 read_type_number (pp
, typenums
);
996 /* Type is not being defined here. Either it already exists,
997 or this is a forward reference to it. dbx_alloc_type handles
1000 return dbx_alloc_type (typenums
, objfile
);
1002 /* Type is being defined here. */
1003 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1007 /* if such a type already exists, this is an unnecessary duplication
1008 of the stab string, which is common in (RS/6000) xlc generated
1009 objects. In that case, simply return NULL and let the caller take
1012 tt
= *dbx_lookup_type (typenums
);
1013 if (tt
&& tt
->length
&& tt
->code
)
1022 /* 'typenums=' not present, type is anonymous. Read and return
1023 the definition, but don't put it in the type vector. */
1024 typenums
[0] = typenums
[1] = -1;
1028 type_descriptor
= (*pp
)[-1];
1029 switch (type_descriptor
)
1033 enum type_code code
;
1035 /* Used to index through file_symbols. */
1036 struct pending
*ppt
;
1039 /* Name including "struct", etc. */
1042 /* Name without "struct", etc. */
1043 char *type_name_only
;
1049 /* Set the type code according to the following letter. */
1053 code
= TYPE_CODE_STRUCT
;
1057 code
= TYPE_CODE_UNION
;
1061 code
= TYPE_CODE_ENUM
;
1065 return error_type (pp
);
1068 to
= type_name
= (char *)
1069 obstack_alloc (&objfile
-> type_obstack
,
1071 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1073 /* Copy the prefix. */
1075 while (*to
++ = *from
++)
1079 type_name_only
= to
;
1081 /* Copy the name. */
1083 while ((*to
++ = *from
++) != ':')
1087 /* Set the pointer ahead of the name which we just read. */
1091 /* The following hack is clearly wrong, because it doesn't
1092 check whether we are in a baseclass. I tried to reproduce
1093 the case that it is trying to fix, but I couldn't get
1094 g++ to put out a cross reference to a basetype. Perhaps
1095 it doesn't do it anymore. */
1096 /* Note: for C++, the cross reference may be to a base type which
1097 has not yet been seen. In this case, we skip to the comma,
1098 which will mark the end of the base class name. (The ':'
1099 at the end of the base class name will be skipped as well.)
1100 But sometimes (ie. when the cross ref is the last thing on
1101 the line) there will be no ','. */
1102 from
= (char *) strchr (*pp
, ',');
1108 /* Now check to see whether the type has already been declared. */
1109 /* This is necessary at least in the case where the
1110 program says something like
1112 The compiler puts out a cross-reference; we better find
1113 set the length of the structure correctly so we can
1114 set the length of the array. */
1115 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1116 for (i
= 0; i
< ppt
->nsyms
; i
++)
1118 struct symbol
*sym
= ppt
->symbol
[i
];
1120 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1121 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1122 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1123 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1125 obstack_free (&objfile
-> type_obstack
, type_name
);
1126 type
= SYMBOL_TYPE (sym
);
1131 /* Didn't find the type to which this refers, so we must
1132 be dealing with a forward reference. Allocate a type
1133 structure for it, and keep track of it so we can
1134 fill in the rest of the fields when we get the full
1136 type
= dbx_alloc_type (typenums
, objfile
);
1137 TYPE_CODE (type
) = code
;
1138 TYPE_NAME (type
) = type_name
;
1139 INIT_CPLUS_SPECIFIC(type
);
1140 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1142 add_undefined_type (type
);
1146 case '-': /* RS/6000 built-in type */
1148 type
= builtin_type (pp
); /* (in xcoffread.c) */
1163 read_type_number (pp
, xtypenums
);
1164 type
= *dbx_lookup_type (xtypenums
);
1169 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1170 if (typenums
[0] != -1)
1171 *dbx_lookup_type (typenums
) = type
;
1174 /* In the following types, we must be sure to overwrite any existing
1175 type that the typenums refer to, rather than allocating a new one
1176 and making the typenums point to the new one. This is because there
1177 may already be pointers to the existing type (if it had been
1178 forward-referenced), and we must change it to a pointer, function,
1179 reference, or whatever, *in-place*. */
1182 type1
= read_type (pp
, objfile
);
1183 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1186 case '&': /* Reference to another type */
1187 type1
= read_type (pp
, objfile
);
1188 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1191 case 'f': /* Function returning another type */
1192 type1
= read_type (pp
, objfile
);
1193 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1196 case 'k': /* Const qualifier on some type (Sun) */
1197 type
= read_type (pp
, objfile
);
1198 /* FIXME! For now, we ignore const and volatile qualifiers. */
1201 case 'B': /* Volatile qual on some type (Sun) */
1202 type
= read_type (pp
, objfile
);
1203 /* FIXME! For now, we ignore const and volatile qualifiers. */
1206 /* FIXME -- we should be doing smash_to_XXX types here. */
1207 case '@': /* Member (class & variable) type */
1209 struct type
*domain
= read_type (pp
, objfile
);
1210 struct type
*memtype
;
1213 /* Invalid member type data format. */
1214 return error_type (pp
);
1217 memtype
= read_type (pp
, objfile
);
1218 type
= dbx_alloc_type (typenums
, objfile
);
1219 smash_to_member_type (type
, domain
, memtype
);
1223 case '#': /* Method (class & fn) type */
1224 if ((*pp
)[0] == '#')
1226 /* We'll get the parameter types from the name. */
1227 struct type
*return_type
;
1230 return_type
= read_type (pp
, objfile
);
1231 if (*(*pp
)++ != ';')
1232 complain (&invalid_member_complaint
, (char *) symnum
);
1233 type
= allocate_stub_method (return_type
);
1234 if (typenums
[0] != -1)
1235 *dbx_lookup_type (typenums
) = type
;
1239 struct type
*domain
= read_type (pp
, objfile
);
1240 struct type
*return_type
;
1243 if (*(*pp
)++ != ',')
1244 error ("invalid member type data format, at symtab pos %d.",
1247 return_type
= read_type (pp
, objfile
);
1248 args
= read_args (pp
, ';', objfile
);
1249 type
= dbx_alloc_type (typenums
, objfile
);
1250 smash_to_method_type (type
, domain
, return_type
, args
);
1254 case 'r': /* Range type */
1255 type
= read_range_type (pp
, typenums
, objfile
);
1256 if (typenums
[0] != -1)
1257 *dbx_lookup_type (typenums
) = type
;
1260 case 'b': /* Sun ACC builtin int type */
1261 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1262 if (typenums
[0] != -1)
1263 *dbx_lookup_type (typenums
) = type
;
1266 case 'R': /* Sun ACC builtin float type */
1267 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1268 if (typenums
[0] != -1)
1269 *dbx_lookup_type (typenums
) = type
;
1272 case 'e': /* Enumeration type */
1273 type
= dbx_alloc_type (typenums
, objfile
);
1274 type
= read_enum_type (pp
, type
, objfile
);
1275 *dbx_lookup_type (typenums
) = type
;
1278 case 's': /* Struct type */
1279 case 'u': /* Union type */
1280 type
= dbx_alloc_type (typenums
, objfile
);
1281 if (!TYPE_NAME (type
))
1283 TYPE_NAME (type
) = type_synonym_name
;
1285 type_synonym_name
= NULL
;
1286 switch (type_descriptor
)
1289 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1292 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1295 type
= read_struct_type (pp
, type
, objfile
);
1298 case 'a': /* Array type */
1300 return error_type (pp
);
1303 type
= dbx_alloc_type (typenums
, objfile
);
1304 type
= read_array_type (pp
, type
, objfile
);
1308 --*pp
; /* Go back to the symbol in error */
1309 /* Particularly important if it was \0! */
1310 return error_type (pp
);
1319 /* This page contains subroutines of read_type. */
1321 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1322 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1323 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1325 /* Read member function stabs info for C++ classes. The form of each member
1328 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1330 An example with two member functions is:
1332 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1334 For the case of overloaded operators, the format is op$::*.funcs, where
1335 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1336 name (such as `+=') and `.' marks the end of the operator name. */
1339 read_member_functions (fip
, pp
, type
, objfile
)
1340 struct field_info
*fip
;
1343 struct objfile
*objfile
;
1347 /* Total number of member functions defined in this class. If the class
1348 defines two `f' functions, and one `g' function, then this will have
1350 int total_length
= 0;
1354 struct next_fnfield
*next
;
1355 struct fn_field fn_field
;
1357 struct type
*look_ahead_type
;
1358 struct next_fnfieldlist
*new_fnlist
;
1359 struct next_fnfield
*new_sublist
;
1363 /* Process each list until we find something that is not a member function
1364 or find the end of the functions. */
1368 /* We should be positioned at the start of the function name.
1369 Scan forward to find the first ':' and if it is not the
1370 first of a "::" delimiter, then this is not a member function. */
1382 look_ahead_type
= NULL
;
1385 new_fnlist
= (struct next_fnfieldlist
*)
1386 xmalloc (sizeof (struct next_fnfieldlist
));
1387 make_cleanup (free
, new_fnlist
);
1388 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1390 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1392 /* This is a completely wierd case. In order to stuff in the
1393 names that might contain colons (the usual name delimiter),
1394 Mike Tiemann defined a different name format which is
1395 signalled if the identifier is "op$". In that case, the
1396 format is "op$::XXXX." where XXXX is the name. This is
1397 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1398 /* This lets the user type "break operator+".
1399 We could just put in "+" as the name, but that wouldn't
1401 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1402 char *o
= opname
+ 3;
1404 /* Skip past '::'. */
1407 STABS_CONTINUE (pp
);
1413 main_fn_name
= savestring (opname
, o
- opname
);
1419 main_fn_name
= savestring (*pp
, p
- *pp
);
1420 /* Skip past '::'. */
1423 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1428 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1429 make_cleanup (free
, new_sublist
);
1430 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1432 /* Check for and handle cretinous dbx symbol name continuation! */
1433 if (look_ahead_type
== NULL
)
1436 STABS_CONTINUE (pp
);
1438 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1441 /* Invalid symtab info for member function. */
1447 /* g++ version 1 kludge */
1448 new_sublist
-> fn_field
.type
= look_ahead_type
;
1449 look_ahead_type
= NULL
;
1459 /* If this is just a stub, then we don't have the real name here. */
1461 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1463 new_sublist
-> fn_field
.is_stub
= 1;
1465 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1468 /* Set this member function's visibility fields. */
1471 case VISIBILITY_PRIVATE
:
1472 new_sublist
-> fn_field
.is_private
= 1;
1474 case VISIBILITY_PROTECTED
:
1475 new_sublist
-> fn_field
.is_protected
= 1;
1479 STABS_CONTINUE (pp
);
1482 case 'A': /* Normal functions. */
1483 new_sublist
-> fn_field
.is_const
= 0;
1484 new_sublist
-> fn_field
.is_volatile
= 0;
1487 case 'B': /* `const' member functions. */
1488 new_sublist
-> fn_field
.is_const
= 1;
1489 new_sublist
-> fn_field
.is_volatile
= 0;
1492 case 'C': /* `volatile' member function. */
1493 new_sublist
-> fn_field
.is_const
= 0;
1494 new_sublist
-> fn_field
.is_volatile
= 1;
1497 case 'D': /* `const volatile' member function. */
1498 new_sublist
-> fn_field
.is_const
= 1;
1499 new_sublist
-> fn_field
.is_volatile
= 1;
1502 case '*': /* File compiled with g++ version 1 -- no info */
1507 complain (&const_vol_complaint
, (char *) (long) **pp
);
1514 /* virtual member function, followed by index.
1515 The sign bit is set to distinguish pointers-to-methods
1516 from virtual function indicies. Since the array is
1517 in words, the quantity must be shifted left by 1
1518 on 16 bit machine, and by 2 on 32 bit machine, forcing
1519 the sign bit out, and usable as a valid index into
1520 the array. Remove the sign bit here. */
1521 new_sublist
-> fn_field
.voffset
=
1522 (0x7fffffff & read_number (pp
, ';')) + 2;
1524 STABS_CONTINUE (pp
);
1525 if (**pp
== ';' || **pp
== '\0')
1527 /* Must be g++ version 1. */
1528 new_sublist
-> fn_field
.fcontext
= 0;
1532 /* Figure out from whence this virtual function came.
1533 It may belong to virtual function table of
1534 one of its baseclasses. */
1535 look_ahead_type
= read_type (pp
, objfile
);
1538 /* g++ version 1 overloaded methods. */
1542 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1551 look_ahead_type
= NULL
;
1557 /* static member function. */
1558 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
1559 if (strncmp (new_sublist
-> fn_field
.physname
,
1560 main_fn_name
, strlen (main_fn_name
)))
1562 new_sublist
-> fn_field
.is_stub
= 1;
1568 complain (&member_fn_complaint
, (char *) (long) (*pp
)[-1]);
1569 /* Fall through into normal member function. */
1572 /* normal member function. */
1573 new_sublist
-> fn_field
.voffset
= 0;
1574 new_sublist
-> fn_field
.fcontext
= 0;
1578 new_sublist
-> next
= sublist
;
1579 sublist
= new_sublist
;
1581 STABS_CONTINUE (pp
);
1583 while (**pp
!= ';' && **pp
!= '\0');
1587 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
1588 obstack_alloc (&objfile
-> type_obstack
,
1589 sizeof (struct fn_field
) * length
);
1590 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
1591 sizeof (struct fn_field
) * length
);
1592 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
1594 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
1597 new_fnlist
-> fn_fieldlist
.length
= length
;
1598 new_fnlist
-> next
= fip
-> fnlist
;
1599 fip
-> fnlist
= new_fnlist
;
1601 total_length
+= length
;
1602 STABS_CONTINUE (pp
);
1607 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1608 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
1609 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
1610 memset (TYPE_FN_FIELDLISTS (type
), 0,
1611 sizeof (struct fn_fieldlist
) * nfn_fields
);
1612 TYPE_NFN_FIELDS (type
) = nfn_fields
;
1613 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
1619 /* Special GNU C++ name.
1620 FIXME: Still need to properly handle parse error conditions. */
1623 read_cpp_abbrev (fip
, pp
, type
, objfile
)
1624 struct field_info
*fip
;
1627 struct objfile
*objfile
;
1632 struct type
*context
;
1647 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1648 prefix
= "INVALID_C++_ABBREV";
1653 /* At this point, *pp points to something like "22:23=*22...",
1654 where the type number before the ':' is the "context" and
1655 everything after is a regular type definition. Lookup the
1656 type, find it's name, and construct the field name. */
1658 context
= read_type (pp
, objfile
);
1659 name
= type_name_no_tag (context
);
1662 complain (&invalid_cpp_type_complaint
, (char *) symnum
);
1665 fip
-> list
-> field
.name
=
1666 obconcat (&objfile
-> type_obstack
, prefix
, name
, "");
1668 /* At this point, *pp points to the ':'. Skip it and read the
1674 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1676 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
1677 (*pp
)++; /* Skip the comma. */
1678 fip
-> list
-> field
.bitpos
= read_number (pp
, ';');
1679 /* This field is unpacked. */
1680 fip
-> list
-> field
.bitsize
= 0;
1681 fip
-> list
-> visibility
= VISIBILITY_PRIVATE
;
1685 /* GNU C++ anonymous type. */
1686 complain (&stabs_general_complaint
, "g++ anonymous type $_ not handled");
1690 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1695 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
1696 struct field_info
*fip
;
1700 struct objfile
*objfile
;
1702 fip
-> list
-> field
.name
=
1703 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
1706 /* This means we have a visibility for a field coming. */
1710 fip
-> list
-> visibility
= *(*pp
)++;
1711 switch (fip
-> list
-> visibility
)
1713 case VISIBILITY_PRIVATE
:
1714 case VISIBILITY_PROTECTED
:
1717 case VISIBILITY_PUBLIC
:
1722 /* Unknown visibility specifier. */
1723 complain (&stabs_general_complaint
,
1724 "unknown visibility specifier");
1731 /* normal dbx-style format, no explicit visibility */
1732 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
1735 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
1740 /* Possible future hook for nested types. */
1743 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
1749 /* Static class member. */
1750 fip
-> list
-> field
.bitpos
= (long) -1;
1756 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
1760 else if (**pp
!= ',')
1762 /* Bad structure-type format. */
1763 complain (&stabs_general_complaint
, "bad structure-type format");
1767 (*pp
)++; /* Skip the comma. */
1768 fip
-> list
-> field
.bitpos
= read_number (pp
, ',');
1769 fip
-> list
-> field
.bitsize
= read_number (pp
, ';');
1772 /* FIXME-tiemann: Can't the compiler put out something which
1773 lets us distinguish these? (or maybe just not put out anything
1774 for the field). What is the story here? What does the compiler
1775 really do? Also, patch gdb.texinfo for this case; I document
1776 it as a possible problem there. Search for "DBX-style". */
1778 /* This is wrong because this is identical to the symbols
1779 produced for GCC 0-size arrays. For example:
1784 The code which dumped core in such circumstances should be
1785 fixed not to dump core. */
1787 /* g++ -g0 can put out bitpos & bitsize zero for a static
1788 field. This does not give us any way of getting its
1789 class, so we can't know its name. But we can just
1790 ignore the field so we don't dump core and other nasty
1792 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
1794 complain (&dbx_class_complaint
, 0);
1795 /* Ignore this field. */
1796 fip
-> list
= fip
-> list
-> next
;
1801 /* Detect an unpacked field and mark it as such.
1802 dbx gives a bit size for all fields.
1803 Note that forward refs cannot be packed,
1804 and treat enums as if they had the width of ints. */
1806 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
1807 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
1809 fip
-> list
-> field
.bitsize
= 0;
1811 if ((fip
-> list
-> field
.bitsize
1812 == 8 * TYPE_LENGTH (fip
-> list
-> field
.type
)
1813 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
1814 && (fip
-> list
-> field
.bitsize
1815 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
1819 fip
-> list
-> field
.bitpos
% 8 == 0)
1821 fip
-> list
-> field
.bitsize
= 0;
1827 /* Read struct or class data fields. They have the form:
1829 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
1831 At the end, we see a semicolon instead of a field.
1833 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1836 The optional VISIBILITY is one of:
1838 '/0' (VISIBILITY_PRIVATE)
1839 '/1' (VISIBILITY_PROTECTED)
1840 '/2' (VISIBILITY_PUBLIC)
1842 or nothing, for C style fields with public visibility. */
1845 read_struct_fields (fip
, pp
, type
, objfile
)
1846 struct field_info
*fip
;
1849 struct objfile
*objfile
;
1852 struct nextfield
*new;
1854 /* We better set p right now, in case there are no fields at all... */
1858 /* Read each data member type until we find the terminating ';' at the end of
1859 the data member list, or break for some other reason such as finding the
1860 start of the member function list. */
1864 STABS_CONTINUE (pp
);
1865 /* Get space to record the next field's data. */
1866 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1867 make_cleanup (free
, new);
1868 memset (new, 0, sizeof (struct nextfield
));
1869 new -> next
= fip
-> list
;
1872 /* Get the field name. */
1874 if (*p
== CPLUS_MARKER
)
1876 read_cpp_abbrev (fip
, pp
, type
, objfile
);
1880 /* Look for the ':' that separates the field name from the field
1881 values. Data members are delimited by a single ':', while member
1882 functions are delimited by a pair of ':'s. When we hit the member
1883 functions (if any), terminate scan loop and return. */
1890 /* Check to see if we have hit the member functions yet. */
1895 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
1899 /* chill the list of fields: the last entry (at the head) is a
1900 partially constructed entry which we now scrub. */
1901 fip
-> list
= fip
-> list
-> next
;
1906 /* The stabs for C++ derived classes contain baseclass information which
1907 is marked by a '!' character after the total size. This function is
1908 called when we encounter the baseclass marker, and slurps up all the
1909 baseclass information.
1911 Immediately following the '!' marker is the number of base classes that
1912 the class is derived from, followed by information for each base class.
1913 For each base class, there are two visibility specifiers, a bit offset
1914 to the base class information within the derived class, a reference to
1915 the type for the base class, and a terminating semicolon.
1917 A typical example, with two base classes, would be "!2,020,19;0264,21;".
1919 Baseclass information marker __________________|| | | | | | |
1920 Number of baseclasses __________________________| | | | | | |
1921 Visibility specifiers (2) ________________________| | | | | |
1922 Offset in bits from start of class _________________| | | | |
1923 Type number for base class ___________________________| | | |
1924 Visibility specifiers (2) _______________________________| | |
1925 Offset in bits from start of class ________________________| |
1926 Type number of base class ____________________________________|
1930 read_baseclasses (fip
, pp
, type
, objfile
)
1931 struct field_info
*fip
;
1934 struct objfile
*objfile
;
1937 struct nextfield
*new;
1945 /* Skip the '!' baseclass information marker. */
1949 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1950 TYPE_N_BASECLASSES (type
) = read_number (pp
, ',');
1953 /* Some stupid compilers have trouble with the following, so break
1954 it up into simpler expressions. */
1955 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
1956 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
1959 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
1962 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1963 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1967 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
1969 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1971 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1972 make_cleanup (free
, new);
1973 memset (new, 0, sizeof (struct nextfield
));
1974 new -> next
= fip
-> list
;
1976 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
1978 STABS_CONTINUE (pp
);
1982 /* Nothing to do. */
1985 SET_TYPE_FIELD_VIRTUAL (type
, i
);
1988 /* Bad visibility format. */
1992 new -> visibility
= *(*pp
)++;
1993 switch (new -> visibility
)
1995 case VISIBILITY_PRIVATE
:
1996 case VISIBILITY_PROTECTED
:
1997 case VISIBILITY_PUBLIC
:
2000 /* Bad visibility format. */
2004 /* The remaining value is the bit offset of the portion of the object
2005 corresponding to this baseclass. Always zero in the absence of
2006 multiple inheritance. */
2008 new -> field
.bitpos
= read_number (pp
, ',');
2010 /* The last piece of baseclass information is the type of the base
2011 class. Read it, and remember it's type name as this field's name. */
2013 new -> field
.type
= read_type (pp
, objfile
);
2014 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2016 /* skip trailing ';' and bump count of number of fields seen */
2023 read_tilde_fields (fip
, pp
, type
, objfile
)
2024 struct field_info
*fip
;
2027 struct objfile
*objfile
;
2031 STABS_CONTINUE (pp
);
2033 /* If we are positioned at a ';', then skip it. */
2043 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2045 /* Obsolete flags that used to indicate the presence
2046 of constructors and/or destructors. */
2050 /* Read either a '%' or the final ';'. */
2051 if (*(*pp
)++ == '%')
2053 /* We'd like to be able to derive the vtable pointer field
2054 from the type information, but when it's inherited, that's
2055 hard. A reason it's hard is because we may read in the
2056 info about a derived class before we read in info about
2057 the base class that provides the vtable pointer field.
2058 Once the base info has been read, we could fill in the info
2059 for the derived classes, but for the fact that by then,
2060 we don't remember who needs what. */
2063 int predicted_fieldno
= -1;
2066 /* Now we must record the virtual function table pointer's
2067 field information. */
2074 /* In version 2, we derive the vfield ourselves. */
2075 for (n
= 0; n
< TYPE_NFIELDS (type
); n
++)
2077 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2078 sizeof (vptr_name
) - 1))
2080 predicted_fieldno
= n
;
2084 if (predicted_fieldno
< 0)
2086 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2088 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2089 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2092 TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2100 t
= read_type (pp
, objfile
);
2102 while (*p
!= '\0' && *p
!= ';')
2108 /* Premature end of symbol. */
2112 TYPE_VPTR_BASETYPE (type
) = t
;
2115 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2117 /* FIXME-tiemann: what's this? */
2119 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2126 for (i
= TYPE_NFIELDS (t
) - 1;
2127 i
>= TYPE_N_BASECLASSES (t
);
2130 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2131 sizeof (vptr_name
) - 1))
2133 TYPE_VPTR_FIELDNO (type
) = i
;
2140 /* Virtual function table field not found. */
2146 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2150 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2152 error ("TYPE_VPTR_FIELDNO miscalculated");
2163 attach_fn_fields_to_type (fip
, type
)
2164 struct field_info
*fip
;
2165 register struct type
*type
;
2169 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2171 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2173 /* @@ Memory leak on objfile -> type_obstack? */
2176 TYPE_NFN_FIELDS_TOTAL (type
) +=
2177 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2180 for (n
= TYPE_NFN_FIELDS (type
);
2181 fip
-> fnlist
!= NULL
;
2182 fip
-> fnlist
= fip
-> fnlist
-> next
)
2184 --n
; /* Circumvent Sun3 compiler bug */
2185 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2190 /* Create the vector of fields, and record how big it is.
2191 We need this info to record proper virtual function table information
2192 for this class's virtual functions. */
2195 attach_fields_to_type (fip
, type
, objfile
)
2196 struct field_info
*fip
;
2197 register struct type
*type
;
2198 struct objfile
*objfile
;
2200 register int nfields
= 0;
2201 register int non_public_fields
= 0;
2202 register struct nextfield
*scan
;
2204 /* Count up the number of fields that we have, as well as taking note of
2205 whether or not there are any non-public fields, which requires us to
2206 allocate and build the private_field_bits and protected_field_bits
2209 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2212 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2214 non_public_fields
++;
2218 /* Now we know how many fields there are, and whether or not there are any
2219 non-public fields. Record the field count, allocate space for the
2220 array of fields, and create blank visibility bitfields if necessary. */
2222 TYPE_NFIELDS (type
) = nfields
;
2223 TYPE_FIELDS (type
) = (struct field
*)
2224 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2225 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2227 if (non_public_fields
)
2229 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2231 TYPE_FIELD_PRIVATE_BITS (type
) =
2232 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2233 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2235 TYPE_FIELD_PROTECTED_BITS (type
) =
2236 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2237 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2240 /* Copy the saved-up fields into the field vector. Start from the head
2241 of the list, adding to the tail of the field array, so that they end
2242 up in the same order in the array in which they were added to the list. */
2244 while (nfields
-- > 0)
2246 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2247 switch (fip
-> list
-> visibility
)
2249 case VISIBILITY_PRIVATE
:
2250 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2253 case VISIBILITY_PROTECTED
:
2254 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2257 case VISIBILITY_PUBLIC
:
2261 /* Should warn about this unknown visibility? */
2264 fip
-> list
= fip
-> list
-> next
;
2269 /* Read the description of a structure (or union type) and return an object
2270 describing the type.
2272 PP points to a character pointer that points to the next unconsumed token
2273 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2274 *PP will point to "4a:1,0,32;;".
2276 TYPE points to an incomplete type that needs to be filled in.
2278 OBJFILE points to the current objfile from which the stabs information is
2279 being read. (Note that it is redundant in that TYPE also contains a pointer
2280 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2283 static struct type
*
2284 read_struct_type (pp
, type
, objfile
)
2287 struct objfile
*objfile
;
2289 struct cleanup
*back_to
;
2290 struct field_info fi
;
2295 back_to
= make_cleanup (null_cleanup
, 0);
2297 INIT_CPLUS_SPECIFIC (type
);
2298 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2300 /* First comes the total size in bytes. */
2302 TYPE_LENGTH (type
) = read_number (pp
, 0);
2304 /* Now read the baseclasses, if any, read the regular C struct or C++
2305 class member fields, attach the fields to the type, read the C++
2306 member functions, attach them to the type, and then read any tilde
2309 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2310 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2311 || !attach_fields_to_type (&fi
, type
, objfile
)
2312 || !read_member_functions (&fi
, pp
, type
, objfile
)
2313 || !attach_fn_fields_to_type (&fi
, type
)
2314 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2316 do_cleanups (back_to
);
2317 return (error_type (pp
));
2320 do_cleanups (back_to
);
2324 /* Read a definition of an array type,
2325 and create and return a suitable type object.
2326 Also creates a range type which represents the bounds of that
2329 static struct type
*
2330 read_array_type (pp
, type
, objfile
)
2332 register struct type
*type
;
2333 struct objfile
*objfile
;
2335 struct type
*index_type
, *element_type
, *range_type
;
2339 /* Format of an array type:
2340 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2343 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2344 for these, produce a type like float[][]. */
2346 index_type
= read_type (pp
, objfile
);
2348 /* Improper format of array type decl. */
2349 return error_type (pp
);
2352 if (!(**pp
>= '0' && **pp
<= '9'))
2357 lower
= read_number (pp
, ';');
2359 if (!(**pp
>= '0' && **pp
<= '9'))
2364 upper
= read_number (pp
, ';');
2366 element_type
= read_type (pp
, objfile
);
2374 type
= create_array_type (type
, element_type
, index_type
, lower
, upper
);
2376 /* If we have an array whose element type is not yet known, but whose
2377 bounds *are* known, record it to be adjusted at the end of the file. */
2379 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2381 add_undefined_type (type
);
2388 /* Read a definition of an enumeration type,
2389 and create and return a suitable type object.
2390 Also defines the symbols that represent the values of the type. */
2392 static struct type
*
2393 read_enum_type (pp
, type
, objfile
)
2395 register struct type
*type
;
2396 struct objfile
*objfile
;
2401 register struct symbol
*sym
;
2403 struct pending
**symlist
;
2404 struct pending
*osyms
, *syms
;
2408 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2409 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2410 to do? For now, force all enum values to file scope. */
2411 if (within_function
)
2412 symlist
= &local_symbols
;
2415 symlist
= &file_symbols
;
2417 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2419 /* Read the value-names and their values.
2420 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2421 A semicolon or comma instead of a NAME means the end. */
2422 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2424 STABS_CONTINUE (pp
);
2426 while (*p
!= ':') p
++;
2427 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2429 n
= read_number (pp
, ',');
2431 sym
= (struct symbol
*)
2432 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2433 memset (sym
, 0, sizeof (struct symbol
));
2434 SYMBOL_NAME (sym
) = name
;
2435 SYMBOL_CLASS (sym
) = LOC_CONST
;
2436 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2437 SYMBOL_VALUE (sym
) = n
;
2438 add_symbol_to_list (sym
, symlist
);
2443 (*pp
)++; /* Skip the semicolon. */
2445 /* Now fill in the fields of the type-structure. */
2447 TYPE_LENGTH (type
) = sizeof (int);
2448 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2449 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2450 TYPE_NFIELDS (type
) = nsyms
;
2451 TYPE_FIELDS (type
) = (struct field
*)
2452 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2453 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2455 /* Find the symbols for the values and put them into the type.
2456 The symbols can be found in the symlist that we put them on
2457 to cause them to be defined. osyms contains the old value
2458 of that symlist; everything up to there was defined by us. */
2459 /* Note that we preserve the order of the enum constants, so
2460 that in something like "enum {FOO, LAST_THING=FOO}" we print
2461 FOO, not LAST_THING. */
2463 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2468 for (; j
< syms
->nsyms
; j
++,n
++)
2470 struct symbol
*xsym
= syms
->symbol
[j
];
2471 SYMBOL_TYPE (xsym
) = type
;
2472 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2473 TYPE_FIELD_VALUE (type
, n
) = 0;
2474 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2475 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2482 /* This screws up perfectly good C programs with enums. FIXME. */
2483 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2484 if(TYPE_NFIELDS(type
) == 2 &&
2485 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2486 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2487 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2488 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2489 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2495 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2496 typedefs in every file (for int, long, etc):
2498 type = b <signed> <width>; <offset>; <nbits>
2499 signed = u or s. Possible c in addition to u or s (for char?).
2500 offset = offset from high order bit to start bit of type.
2501 width is # bytes in object of this type, nbits is # bits in type.
2503 The width/offset stuff appears to be for small objects stored in
2504 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2507 static struct type
*
2508 read_sun_builtin_type (pp
, typenums
, objfile
)
2511 struct objfile
*objfile
;
2525 return error_type (pp
);
2529 /* For some odd reason, all forms of char put a c here. This is strange
2530 because no other type has this honor. We can safely ignore this because
2531 we actually determine 'char'acterness by the number of bits specified in
2537 /* The first number appears to be the number of bytes occupied
2538 by this type, except that unsigned short is 4 instead of 2.
2539 Since this information is redundant with the third number,
2540 we will ignore it. */
2541 read_number (pp
, ';');
2543 /* The second number is always 0, so ignore it too. */
2544 read_number (pp
, ';');
2546 /* The third number is the number of bits for this type. */
2547 nbits
= read_number (pp
, 0);
2549 /* FIXME. Here we should just be able to make a type of the right
2550 number of bits and signedness. FIXME. */
2552 if (nbits
== TARGET_LONG_LONG_BIT
)
2553 return (lookup_fundamental_type (objfile
,
2554 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
2556 if (nbits
== TARGET_INT_BIT
)
2558 /* FIXME -- the only way to distinguish `int' from `long'
2559 is to look at its name! */
2562 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2563 return lookup_fundamental_type (objfile
, FT_LONG
);
2565 return lookup_fundamental_type (objfile
, FT_INTEGER
);
2569 if (long_kludge_name
2570 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2571 long_kludge_name
[9] == 'l' /* long */)
2572 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2573 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
2575 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
2579 if (nbits
== TARGET_SHORT_BIT
)
2580 return (lookup_fundamental_type (objfile
,
2581 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
2583 if (nbits
== TARGET_CHAR_BIT
)
2584 return (lookup_fundamental_type (objfile
,
2585 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
2588 return lookup_fundamental_type (objfile
, FT_VOID
);
2590 return error_type (pp
);
2593 static struct type
*
2594 read_sun_floating_type (pp
, typenums
, objfile
)
2597 struct objfile
*objfile
;
2601 /* The first number has more details about the type, for example
2602 FN_COMPLEX. See the sun stab.h. */
2603 read_number (pp
, ';');
2605 /* The second number is the number of bytes occupied by this type */
2606 nbytes
= read_number (pp
, ';');
2609 return error_type (pp
);
2611 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
2612 return lookup_fundamental_type (objfile
, FT_FLOAT
);
2614 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2615 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
2617 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2618 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
2620 return error_type (pp
);
2623 /* Read a number from the string pointed to by *PP.
2624 The value of *PP is advanced over the number.
2625 If END is nonzero, the character that ends the
2626 number must match END, or an error happens;
2627 and that character is skipped if it does match.
2628 If END is zero, *PP is left pointing to that character.
2630 If the number fits in a long, set *VALUE and set *BITS to 0.
2631 If not, set *BITS to be the number of bits in the number.
2633 If encounter garbage, set *BITS to -1. */
2636 read_huge_number (pp
, end
, valu
, bits
)
2657 /* Leading zero means octal. GCC uses this to output values larger
2658 than an int (because that would be hard in decimal). */
2665 upper_limit
= LONG_MAX
/ radix
;
2666 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2668 if (n
<= upper_limit
)
2671 n
+= c
- '0'; /* FIXME this overflows anyway */
2676 /* This depends on large values being output in octal, which is
2683 /* Ignore leading zeroes. */
2687 else if (c
== '2' || c
== '3')
2713 /* Large decimal constants are an error (because it is hard to
2714 count how many bits are in them). */
2720 /* -0x7f is the same as 0x80. So deal with it by adding one to
2721 the number of bits. */
2736 static struct type
*
2737 read_range_type (pp
, typenums
, objfile
)
2740 struct objfile
*objfile
;
2746 struct type
*result_type
;
2748 /* First comes a type we are a subrange of.
2749 In C it is usually 0, 1 or the type being defined. */
2750 read_type_number (pp
, rangenums
);
2751 self_subrange
= (rangenums
[0] == typenums
[0] &&
2752 rangenums
[1] == typenums
[1]);
2754 /* A semicolon should now follow; skip it. */
2758 /* The remaining two operands are usually lower and upper bounds
2759 of the range. But in some special cases they mean something else. */
2760 read_huge_number (pp
, ';', &n2
, &n2bits
);
2761 read_huge_number (pp
, ';', &n3
, &n3bits
);
2763 if (n2bits
== -1 || n3bits
== -1)
2764 return error_type (pp
);
2766 /* If limits are huge, must be large integral type. */
2767 if (n2bits
!= 0 || n3bits
!= 0)
2769 char got_signed
= 0;
2770 char got_unsigned
= 0;
2771 /* Number of bits in the type. */
2774 /* Range from 0 to <large number> is an unsigned large integral type. */
2775 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2780 /* Range from <large number> to <large number>-1 is a large signed
2782 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2788 /* Check for "long long". */
2789 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2790 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2791 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2792 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2794 if (got_signed
|| got_unsigned
)
2796 result_type
= alloc_type (objfile
);
2797 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2798 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2800 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2804 return error_type (pp
);
2807 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2808 if (self_subrange
&& n2
== 0 && n3
== 0)
2809 return (lookup_fundamental_type (objfile
, FT_VOID
));
2811 /* If n3 is zero and n2 is not, we want a floating type,
2812 and n2 is the width in bytes.
2814 Fortran programs appear to use this for complex types also,
2815 and they give no way to distinguish between double and single-complex!
2816 We don't have complex types, so we would lose on all fortran files!
2817 So return type `double' for all of those. It won't work right
2818 for the complex values, but at least it makes the file loadable.
2820 FIXME, we may be able to distinguish these by their names. FIXME. */
2822 if (n3
== 0 && n2
> 0)
2824 if (n2
== sizeof (float))
2825 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
2826 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
2829 /* If the upper bound is -1, it must really be an unsigned int. */
2831 else if (n2
== 0 && n3
== -1)
2833 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2834 long' is to look at its name! */
2836 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2837 long_kludge_name
[9] == 'l' /* long */)
2838 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2839 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2841 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2844 /* Special case: char is defined (Who knows why) as a subrange of
2845 itself with range 0-127. */
2846 else if (self_subrange
&& n2
== 0 && n3
== 127)
2847 return (lookup_fundamental_type (objfile
, FT_CHAR
));
2849 /* Assumptions made here: Subrange of self is equivalent to subrange
2850 of int. FIXME: Host and target type-sizes assumed the same. */
2851 /* FIXME: This is the *only* place in GDB that depends on comparing
2852 some type to a builtin type with ==. Fix it! */
2854 && (self_subrange
||
2855 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
2857 /* an unsigned type */
2859 if (n3
== - sizeof (long long))
2860 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2862 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2863 long' is to look at its name! */
2864 if (n3
== (unsigned long)~0L &&
2865 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2866 long_kludge_name
[9] == 'l' /* long */)
2867 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2868 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2869 if (n3
== (unsigned int)~0L)
2870 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2871 if (n3
== (unsigned short)~0L)
2872 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
2873 if (n3
== (unsigned char)~0L)
2874 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
2877 else if (n3
== 0 && n2
== -sizeof (long long))
2878 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2880 else if (n2
== -n3
-1)
2883 /* FIXME -- the only way to distinguish `int' from `long' is to look
2885 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2886 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2887 return (lookup_fundamental_type (objfile
, FT_LONG
));
2888 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2889 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
2890 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
2891 return (lookup_fundamental_type (objfile
, FT_SHORT
));
2892 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
2893 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
2896 /* We have a real range type on our hands. Allocate space and
2897 return a real pointer. */
2899 /* At this point I don't have the faintest idea how to deal with
2900 a self_subrange type; I'm going to assume that this is used
2901 as an idiom, and that all of them are special cases. So . . . */
2903 return error_type (pp
);
2905 result_type
= alloc_type (objfile
);
2907 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
2909 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
2910 if (TYPE_TARGET_TYPE (result_type
) == 0) {
2911 complain (&range_type_base_complaint
, (char *) rangenums
[1]);
2912 TYPE_TARGET_TYPE (result_type
) = lookup_fundamental_type (objfile
, FT_INTEGER
);
2915 TYPE_NFIELDS (result_type
) = 2;
2916 TYPE_FIELDS (result_type
) = (struct field
*)
2917 TYPE_ALLOC (result_type
, 2 * sizeof (struct field
));
2918 memset (TYPE_FIELDS (result_type
), 0, 2 * sizeof (struct field
));
2919 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
2920 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
2922 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
2927 /* Read a number from the string pointed to by *PP.
2928 The value of *PP is advanced over the number.
2929 If END is nonzero, the character that ends the
2930 number must match END, or an error happens;
2931 and that character is skipped if it does match.
2932 If END is zero, *PP is left pointing to that character. */
2935 read_number (pp
, end
)
2939 register char *p
= *pp
;
2940 register long n
= 0;
2944 /* Handle an optional leading minus sign. */
2952 /* Read the digits, as far as they go. */
2954 while ((c
= *p
++) >= '0' && c
<= '9')
2962 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
2971 /* Read in an argument list. This is a list of types, separated by commas
2972 and terminated with END. Return the list of types read in, or (struct type
2973 **)-1 if there is an error. */
2975 static struct type
**
2976 read_args (pp
, end
, objfile
)
2979 struct objfile
*objfile
;
2981 /* FIXME! Remove this arbitrary limit! */
2982 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
2988 /* Invalid argument list: no ','. */
2989 return (struct type
**)-1;
2991 STABS_CONTINUE (pp
);
2992 types
[n
++] = read_type (pp
, objfile
);
2994 (*pp
)++; /* get past `end' (the ':' character) */
2998 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3000 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3002 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3003 memset (rval
+ n
, 0, sizeof (struct type
*));
3007 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3009 memcpy (rval
, types
, n
* sizeof (struct type
*));
3013 /* Add a common block's start address to the offset of each symbol
3014 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3015 the common block name). */
3018 fix_common_block (sym
, valu
)
3022 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3023 for ( ; next
; next
= next
->next
)
3026 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3027 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3033 /* What about types defined as forward references inside of a small lexical
3035 /* Add a type to the list of undefined types to be checked through
3036 once this file has been read in. */
3039 add_undefined_type (type
)
3042 if (undef_types_length
== undef_types_allocated
)
3044 undef_types_allocated
*= 2;
3045 undef_types
= (struct type
**)
3046 xrealloc ((char *) undef_types
,
3047 undef_types_allocated
* sizeof (struct type
*));
3049 undef_types
[undef_types_length
++] = type
;
3052 /* Go through each undefined type, see if it's still undefined, and fix it
3053 up if possible. We have two kinds of undefined types:
3055 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3056 Fix: update array length using the element bounds
3057 and the target type's length.
3058 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3059 yet defined at the time a pointer to it was made.
3060 Fix: Do a full lookup on the struct/union tag. */
3062 cleanup_undefined_types ()
3066 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3068 switch (TYPE_CODE (*type
))
3071 case TYPE_CODE_STRUCT
:
3072 case TYPE_CODE_UNION
:
3073 case TYPE_CODE_ENUM
:
3075 /* Check if it has been defined since. */
3076 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3078 struct pending
*ppt
;
3080 /* Name of the type, without "struct" or "union" */
3081 char *typename
= TYPE_NAME (*type
);
3083 if (!strncmp (typename
, "struct ", 7))
3085 if (!strncmp (typename
, "union ", 6))
3087 if (!strncmp (typename
, "enum ", 5))
3090 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3092 for (i
= 0; i
< ppt
->nsyms
; i
++)
3094 struct symbol
*sym
= ppt
->symbol
[i
];
3096 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3097 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3098 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3100 && !strcmp (SYMBOL_NAME (sym
), typename
))
3102 memcpy (*type
, SYMBOL_TYPE (sym
),
3103 sizeof (struct type
));
3111 case TYPE_CODE_ARRAY
:
3113 struct type
*range_type
;
3116 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3118 if (TYPE_NFIELDS (*type
) != 1)
3120 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3121 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3124 /* Now recompute the length of the array type, based on its
3125 number of elements and the target type's length. */
3126 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3127 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3128 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3129 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3135 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type
));
3139 undef_types_length
= 0;
3142 /* Scan through all of the global symbols defined in the object file,
3143 assigning values to the debugging symbols that need to be assigned
3144 to. Get these symbols from the minimal symbol table. */
3147 scan_file_globals (objfile
)
3148 struct objfile
*objfile
;
3151 struct minimal_symbol
*msymbol
;
3152 struct symbol
*sym
, *prev
;
3154 if (objfile
->msymbols
== 0) /* Beware the null file. */
3157 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
3163 /* Get the hash index and check all the symbols
3164 under that hash index. */
3166 hash
= hashname (msymbol
-> name
);
3168 for (sym
= global_sym_chain
[hash
]; sym
;)
3170 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
3171 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
3173 /* Splice this symbol out of the hash chain and
3174 assign the value we have to it. */
3177 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3181 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3184 /* Check to see whether we need to fix up a common block. */
3185 /* Note: this code might be executed several times for
3186 the same symbol if there are multiple references. */
3188 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3190 fix_common_block (sym
, msymbol
-> address
);
3194 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
3199 sym
= SYMBOL_VALUE_CHAIN (prev
);
3203 sym
= global_sym_chain
[hash
];
3209 sym
= SYMBOL_VALUE_CHAIN (sym
);
3215 /* Initialize anything that needs initializing when starting to read
3216 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3224 /* Initialize anything that needs initializing when a completely new
3225 symbol file is specified (not just adding some symbols from another
3226 file, e.g. a shared library). */
3229 stabsread_new_init ()
3231 /* Empty the hash table of global syms looking for values. */
3232 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3235 /* Initialize anything that needs initializing at the same time as
3236 start_symtab() is called. */
3240 global_stabs
= NULL
; /* AIX COFF */
3241 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3242 n_this_object_header_files
= 1;
3243 type_vector_length
= 0;
3244 type_vector
= (struct type
**) 0;
3247 /* Call after end_symtab() */
3253 free ((char *) type_vector
);
3256 type_vector_length
= 0;
3257 previous_stab_code
= 0;
3261 finish_global_stabs (objfile
)
3262 struct objfile
*objfile
;
3266 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3267 free ((PTR
) global_stabs
);
3268 global_stabs
= NULL
;
3272 /* Initializer for this module */
3275 _initialize_stabsread ()
3277 undef_types_allocated
= 20;
3278 undef_types_length
= 0;
3279 undef_types
= (struct type
**)
3280 xmalloc (undef_types_allocated
* sizeof (struct type
*));