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. */
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
36 #include "complaints.h"
38 /* Ask stabsread.h to define the vars it normally declares `extern'. */
40 #include "stabsread.h" /* Our own declarations */
43 /* The routines that read and process a complete stabs for a C struct or
44 C++ class pass lists of data member fields and lists of member function
45 fields in an instance of a field_info structure, as defined below.
46 This is part of some reorganization of low level C++ support and is
47 expected to eventually go away... (FIXME) */
53 struct nextfield
*next
;
57 struct next_fnfieldlist
59 struct next_fnfieldlist
*next
;
60 struct fn_fieldlist fn_fieldlist
;
65 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
68 read_huge_number
PARAMS ((char **, int, long *, int *));
71 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
75 fix_common_block
PARAMS ((struct symbol
*, int));
78 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
81 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
84 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
87 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
90 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
94 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
98 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
102 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
106 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
109 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
113 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
116 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
118 static struct type
**
119 read_args
PARAMS ((char **, int, struct objfile
*));
122 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
125 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
126 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
128 /* Define this as 1 if a pcc declaration of a char or short argument
129 gives the correct address. Otherwise assume pcc gives the
130 address of the corresponding int, which is not the same on a
131 big-endian machine. */
133 #ifndef BELIEVE_PCC_PROMOTION
134 #define BELIEVE_PCC_PROMOTION 0
137 /* During some calls to read_type (and thus to read_range_type), this
138 contains the name of the type being defined. Range types are only
139 used in C as basic types. We use the name to distinguish the otherwise
140 identical basic types "int" and "long" and their unsigned versions.
141 FIXME, this should disappear with better type management. */
143 static char *long_kludge_name
;
146 struct complaint dbx_class_complaint
=
148 "encountered DBX-style class variable debugging information.\n\
149 You seem to have compiled your program with \
150 \"g++ -g0\" instead of \"g++ -g\".\n\
151 Therefore GDB will not know about your class variables", 0, 0
155 struct complaint invalid_cpp_abbrev_complaint
=
156 {"invalid C++ abbreviation `%s'", 0, 0};
158 struct complaint invalid_cpp_type_complaint
=
159 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
161 struct complaint member_fn_complaint
=
162 {"member function type missing, got '%c'", 0, 0};
164 struct complaint const_vol_complaint
=
165 {"const/volatile indicator missing, got '%c'", 0, 0};
167 struct complaint error_type_complaint
=
168 {"debug info mismatch between compiler and debugger", 0, 0};
170 struct complaint invalid_member_complaint
=
171 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
173 struct complaint range_type_base_complaint
=
174 {"base type %d of range type is not defined", 0, 0};
176 struct complaint reg_value_complaint
=
177 {"register number too large in symbol %s", 0, 0};
179 struct complaint stabs_general_complaint
=
182 /* Make a list of forward references which haven't been defined. */
184 static struct type
**undef_types
;
185 static int undef_types_allocated
;
186 static int undef_types_length
;
188 /* Check for and handle cretinous stabs symbol name continuation! */
189 #define STABS_CONTINUE(pp) \
191 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
199 register char *p
= name
;
200 register int total
= p
[0];
215 /* Ensure result is positive. */
218 total
+= (1000 << 6);
220 return (total
% HASHSIZE
);
224 /* Look up a dbx type-number pair. Return the address of the slot
225 where the type for that number-pair is stored.
226 The number-pair is in TYPENUMS.
228 This can be used for finding the type associated with that pair
229 or for associating a new type with the pair. */
232 dbx_lookup_type (typenums
)
235 register int filenum
= typenums
[0];
236 register int index
= typenums
[1];
238 register int real_filenum
;
239 register struct header_file
*f
;
242 if (filenum
== -1) /* -1,-1 is for temporary types. */
245 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
246 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
247 filenum
, index
, symnum
);
251 /* Type is defined outside of header files.
252 Find it in this object file's type vector. */
253 if (index
>= type_vector_length
)
255 old_len
= type_vector_length
;
258 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
259 type_vector
= (struct type
**)
260 malloc (type_vector_length
* sizeof (struct type
*));
262 while (index
>= type_vector_length
)
264 type_vector_length
*= 2;
266 type_vector
= (struct type
**)
267 xrealloc ((char *) type_vector
,
268 (type_vector_length
* sizeof (struct type
*)));
269 memset (&type_vector
[old_len
], 0,
270 (type_vector_length
- old_len
) * sizeof (struct type
*));
272 return (&type_vector
[index
]);
276 real_filenum
= this_object_header_files
[filenum
];
278 if (real_filenum
>= n_header_files
)
283 f
= &header_files
[real_filenum
];
285 f_orig_length
= f
->length
;
286 if (index
>= f_orig_length
)
288 while (index
>= f
->length
)
292 f
->vector
= (struct type
**)
293 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
294 memset (&f
->vector
[f_orig_length
], 0,
295 (f
->length
- f_orig_length
) * sizeof (struct type
*));
297 return (&f
->vector
[index
]);
301 /* Make sure there is a type allocated for type numbers TYPENUMS
302 and return the type object.
303 This can create an empty (zeroed) type object.
304 TYPENUMS may be (-1, -1) to return a new type object that is not
305 put into the type vector, and so may not be referred to by number. */
308 dbx_alloc_type (typenums
, objfile
)
310 struct objfile
*objfile
;
312 register struct type
**type_addr
;
314 if (typenums
[0] == -1)
316 return (alloc_type (objfile
));
319 type_addr
= dbx_lookup_type (typenums
);
321 /* If we are referring to a type not known at all yet,
322 allocate an empty type for it.
323 We will fill it in later if we find out how. */
326 *type_addr
= alloc_type (objfile
);
332 /* for all the stabs in a given stab vector, build appropriate types
333 and fix their symbols in given symbol vector. */
336 patch_block_stabs (symbols
, stabs
, objfile
)
337 struct pending
*symbols
;
338 struct pending_stabs
*stabs
;
339 struct objfile
*objfile
;
349 /* for all the stab entries, find their corresponding symbols and
350 patch their types! */
352 for (ii
= 0; ii
< stabs
->count
; ++ii
)
354 name
= stabs
->stab
[ii
];
355 pp
= (char*) strchr (name
, ':');
356 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
359 #ifndef IBM6000_TARGET
360 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
366 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
369 lookup_function_type (read_type (&pp
, objfile
));
373 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
381 /* Read a number by which a type is referred to in dbx data,
382 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
383 Just a single number N is equivalent to (0,N).
384 Return the two numbers by storing them in the vector TYPENUMS.
385 TYPENUMS will then be used as an argument to dbx_lookup_type. */
388 read_type_number (pp
, typenums
)
390 register int *typenums
;
395 typenums
[0] = read_number (pp
, ',');
396 typenums
[1] = read_number (pp
, ')');
401 typenums
[1] = read_number (pp
, 0);
406 /* To handle GNU C++ typename abbreviation, we need to be able to
407 fill in a type's name as soon as space for that type is allocated.
408 `type_synonym_name' is the name of the type being allocated.
409 It is cleared as soon as it is used (lest all allocated types
412 static char *type_synonym_name
;
416 define_symbol (valu
, string
, desc
, type
, objfile
)
421 struct objfile
*objfile
;
423 register struct symbol
*sym
;
424 char *p
= (char *) strchr (string
, ':');
428 struct type
*temptype
;
430 /* We would like to eliminate nameless symbols, but keep their types.
431 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
432 to type 2, but, should not create a symbol to address that type. Since
433 the symbol will be nameless, there is no way any user can refer to it. */
437 /* Ignore syms with empty names. */
441 /* Ignore old-style symbols from cc -go */
445 /* If a nameless stab entry, all we need is the type, not the symbol.
446 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
447 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
449 sym
= (struct symbol
*)
450 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
451 memset (sym
, 0, sizeof (struct symbol
));
453 if (processing_gcc_compilation
)
455 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
456 number of bytes occupied by a type or object, which we ignore. */
457 SYMBOL_LINE(sym
) = desc
;
461 SYMBOL_LINE(sym
) = 0; /* unknown */
464 if (string
[0] == CPLUS_MARKER
)
466 /* Special GNU C++ names. */
470 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
471 &objfile
-> symbol_obstack
);
474 case 'v': /* $vtbl_ptr_type */
475 /* Was: SYMBOL_NAME (sym) = "vptr"; */
479 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
480 &objfile
-> symbol_obstack
);
484 /* This was an anonymous type that was never fixed up. */
494 SYMBOL_NAME (sym
) = (char *)
495 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
496 /* Open-coded bcopy--saves function call time. */
498 register char *p1
= string
;
499 register char *p2
= SYMBOL_NAME (sym
);
509 /* Determine the type of name being defined. */
510 /* The Acorn RISC machine's compiler can put out locals that don't
511 start with "234=" or "(3,4)=", so assume anything other than the
512 deftypes we know how to handle is a local. */
513 if (!strchr ("cfFGpPrStTvVXCR", *p
))
518 /* c is a special case, not followed by a type-number.
519 SYMBOL:c=iVALUE for an integer constant symbol.
520 SYMBOL:c=rVALUE for a floating constant symbol.
521 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
522 e.g. "b:c=e6,0" for "const b = blob1"
523 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
527 error ("Invalid symbol data at symtab pos %d.", symnum
);
535 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
538 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (double));
539 memcpy (dbl_valu
, &d
, sizeof (double));
540 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
541 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
542 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
547 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
549 SYMBOL_VALUE (sym
) = atoi (p
);
550 SYMBOL_CLASS (sym
) = LOC_CONST
;
554 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
555 e.g. "b:c=e6,0" for "const b = blob1"
556 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
560 read_type_number (&p
, typenums
);
562 error ("Invalid symbol data: no comma in enum const symbol");
564 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
565 SYMBOL_VALUE (sym
) = atoi (p
);
566 SYMBOL_CLASS (sym
) = LOC_CONST
;
570 error ("Invalid symbol data at symtab pos %d.", symnum
);
572 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
573 add_symbol_to_list (sym
, &file_symbols
);
577 /* Now usually comes a number that says which data type,
578 and possibly more stuff to define the type
579 (all of which is handled by read_type) */
581 if (deftype
== 'p' && *p
== 'F')
582 /* pF is a two-letter code that means a function parameter in Fortran.
583 The type-number specifies the type of the return value.
584 Translate it into a pointer-to-function type. */
588 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
592 /* The symbol class letter is followed by a type (typically the
593 type of the symbol, or its return-type, or etc). Read it. */
600 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
601 strlen (SYMBOL_NAME (sym
)),
602 &objfile
-> symbol_obstack
);
605 /* Here we save the name of the symbol for read_range_type, which
606 ends up reading in the basic types. In stabs, unfortunately there
607 is no distinction between "int" and "long" types except their
608 names. Until we work out a saner type policy (eliminating most
609 builtin types and using the names specified in the files), we
610 save away the name so that far away from here in read_range_type,
611 we can examine it to decide between "int" and "long". FIXME. */
612 long_kludge_name
= SYMBOL_NAME (sym
);
614 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
620 /* The name of a caught exception. */
621 SYMBOL_CLASS (sym
) = LOC_LABEL
;
622 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
623 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
624 add_symbol_to_list (sym
, &local_symbols
);
628 /* A static function definition. */
629 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
630 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
631 add_symbol_to_list (sym
, &file_symbols
);
632 /* fall into process_function_types. */
634 process_function_types
:
635 /* Function result types are described as the result type in stabs.
636 We need to convert this to the function-returning-type-X type
637 in GDB. E.g. "int" is converted to "function returning int". */
638 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
641 /* This code doesn't work -- it needs to realloc and can't. */
642 /* Attempt to set up to record a function prototype... */
643 struct type
*new = alloc_type (objfile
);
645 /* Generate a template for the type of this function. The
646 types of the arguments will be added as we read the symbol
648 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
649 SYMBOL_TYPE(sym
) = new;
650 TYPE_OBJFILE (new) = objfile
;
651 in_function_type
= new;
653 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
656 /* fall into process_prototype_types */
658 process_prototype_types
:
659 /* Sun acc puts declared types of arguments here. We don't care
660 about their actual types (FIXME -- we should remember the whole
661 function prototype), but the list may define some new types
662 that we have to remember, so we must scan it now. */
665 read_type (&p
, objfile
);
670 /* A global function definition. */
671 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
672 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
673 add_symbol_to_list (sym
, &global_symbols
);
674 goto process_function_types
;
677 /* For a class G (global) symbol, it appears that the
678 value is not correct. It is necessary to search for the
679 corresponding linker definition to find the value.
680 These definitions appear at the end of the namelist. */
681 i
= hashname (SYMBOL_NAME (sym
));
682 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
683 global_sym_chain
[i
] = sym
;
684 SYMBOL_CLASS (sym
) = LOC_STATIC
;
685 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
686 add_symbol_to_list (sym
, &global_symbols
);
689 /* This case is faked by a conditional above,
690 when there is no code letter in the dbx data.
691 Dbx data never actually contains 'l'. */
693 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
694 SYMBOL_VALUE (sym
) = valu
;
695 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
696 add_symbol_to_list (sym
, &local_symbols
);
700 /* Normally this is a parameter, a LOC_ARG. On the i960, it
701 can also be a LOC_LOCAL_ARG depending on symbol type. */
702 #ifndef DBX_PARM_SYMBOL_CLASS
703 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
705 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
706 SYMBOL_VALUE (sym
) = valu
;
707 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
709 /* This doesn't work yet. */
710 add_param_to_type (&in_function_type
, sym
);
712 add_symbol_to_list (sym
, &local_symbols
);
714 /* If it's gcc-compiled, if it says `short', believe it. */
715 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
718 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
719 /* This macro is defined on machines (e.g. sparc) where
720 we should believe the type of a PCC 'short' argument,
721 but shouldn't believe the address (the address is
722 the address of the corresponding int). Note that
723 this is only different from the BELIEVE_PCC_PROMOTION
724 case on big-endian machines.
726 My guess is that this correction, as opposed to changing
727 the parameter to an 'int' (as done below, for PCC
728 on most machines), is the right thing to do
729 on all machines, but I don't want to risk breaking
730 something that already works. On most PCC machines,
731 the sparc problem doesn't come up because the calling
732 function has to zero the top bytes (not knowing whether
733 the called function wants an int or a short), so there
734 is no practical difference between an int and a short
735 (except perhaps what happens when the GDB user types
736 "print short_arg = 0x10000;").
738 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
739 actually produces the correct address (we don't need to fix it
740 up). I made this code adapt so that it will offset the symbol
741 if it was pointing at an int-aligned location and not
742 otherwise. This way you can use the same gdb for 4.0.x and
745 If the parameter is shorter than an int, and is integral
746 (e.g. char, short, or unsigned equivalent), and is claimed to
747 be passed on an integer boundary, don't believe it! Offset the
748 parameter's address to the tail-end of that integer. */
750 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
751 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
752 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
753 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
755 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
756 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
760 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
762 /* If PCC says a parameter is a short or a char,
763 it is really an int. */
764 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
765 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
766 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
768 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
769 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
774 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
777 /* acc seems to use P to delare the prototypes of functions that
778 are referenced by this file. gdb is not prepared to deal
779 with this extra information. FIXME, it ought to. */
781 goto process_prototype_types
;
783 /* Parameter which is in a register. */
784 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
785 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
786 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
788 complain (®_value_complaint
, SYMBOL_NAME (sym
));
789 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
791 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
792 add_symbol_to_list (sym
, &local_symbols
);
797 /* Register variable (either global or local). */
798 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
799 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
800 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
802 complain (®_value_complaint
, SYMBOL_NAME (sym
));
803 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
805 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
807 add_symbol_to_list (sym
, &local_symbols
);
809 add_symbol_to_list (sym
, &file_symbols
);
813 /* Static symbol at top level of file */
814 SYMBOL_CLASS (sym
) = LOC_STATIC
;
815 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
816 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
817 add_symbol_to_list (sym
, &file_symbols
);
821 /* For a nameless type, we don't want a create a symbol, thus we
822 did not use `sym'. Return without further processing. */
823 if (nameless
) return NULL
;
825 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
826 SYMBOL_VALUE (sym
) = valu
;
827 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
828 /* C++ vagaries: we may have a type which is derived from
829 a base type which did not have its name defined when the
830 derived class was output. We fill in the derived class's
831 base part member's name here in that case. */
832 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
833 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
834 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
835 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
838 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
839 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
840 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
841 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
844 add_symbol_to_list (sym
, &file_symbols
);
848 /* For a nameless type, we don't want a create a symbol, thus we
849 did not use `sym'. Return without further processing. */
850 if (nameless
) return NULL
;
852 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
853 SYMBOL_VALUE (sym
) = valu
;
854 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
855 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
856 TYPE_NAME (SYMBOL_TYPE (sym
))
857 = obconcat (&objfile
-> type_obstack
, "",
858 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
860 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
861 ? "struct " : "union ")),
863 add_symbol_to_list (sym
, &file_symbols
);
867 register struct symbol
*typedef_sym
= (struct symbol
*)
868 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
869 memset (typedef_sym
, 0, sizeof (struct symbol
));
870 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
871 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
873 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
874 SYMBOL_VALUE (typedef_sym
) = valu
;
875 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
876 add_symbol_to_list (typedef_sym
, &file_symbols
);
881 /* Static symbol of local scope */
882 SYMBOL_CLASS (sym
) = LOC_STATIC
;
883 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
884 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
885 add_symbol_to_list (sym
, &local_symbols
);
889 /* Reference parameter */
890 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
891 SYMBOL_VALUE (sym
) = valu
;
892 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
893 add_symbol_to_list (sym
, &local_symbols
);
897 /* This is used by Sun FORTRAN for "function result value".
898 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
899 that Pascal uses it too, but when I tried it Pascal used
900 "x:3" (local symbol) instead. */
901 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
902 SYMBOL_VALUE (sym
) = valu
;
903 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
904 add_symbol_to_list (sym
, &local_symbols
);
908 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
914 /* Skip rest of this symbol and return an error type.
916 General notes on error recovery: error_type always skips to the
917 end of the symbol (modulo cretinous dbx symbol name continuation).
921 return error_type (pp);
923 is wrong because if *pp starts out pointing at '\0' (typically as the
924 result of an earlier error), it will be incremented to point to the
925 start of the next symbol, which might produce strange results, at least
926 if you run off the end of the string table. Instead use
929 return error_type (pp);
935 foo = error_type (pp);
939 And in case it isn't obvious, the point of all this hair is so the compiler
940 can define new types and new syntaxes, and old versions of the
941 debugger will be able to read the new symbol tables. */
947 complain (&error_type_complaint
);
950 /* Skip to end of symbol. */
956 /* Check for and handle cretinous dbx symbol name continuation! */
957 if ((*pp
)[-1] == '\\')
959 *pp
= next_symbol_text ();
966 return (builtin_type_error
);
970 /* Read a dbx type reference or definition;
971 return the type that is meant.
972 This can be just a number, in which case it references
973 a type already defined and placed in type_vector.
974 Or the number can be followed by an =, in which case
975 it means to define a new type according to the text that
979 read_type (pp
, objfile
)
981 struct objfile
*objfile
;
983 register struct type
*type
= 0;
987 char type_descriptor
;
989 /* Read type number if present. The type number may be omitted.
990 for instance in a two-dimensional array declared with type
991 "ar1;1;10;ar1;1;10;4". */
992 if ((**pp
>= '0' && **pp
<= '9')
995 read_type_number (pp
, typenums
);
997 /* Type is not being defined here. Either it already exists,
998 or this is a forward reference to it. dbx_alloc_type handles
1001 return dbx_alloc_type (typenums
, objfile
);
1003 /* Type is being defined here. */
1004 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1008 /* if such a type already exists, this is an unnecessary duplication
1009 of the stab string, which is common in (RS/6000) xlc generated
1010 objects. In that case, simply return NULL and let the caller take
1013 tt
= *dbx_lookup_type (typenums
);
1014 if (tt
&& tt
->length
&& tt
->code
)
1023 /* 'typenums=' not present, type is anonymous. Read and return
1024 the definition, but don't put it in the type vector. */
1025 typenums
[0] = typenums
[1] = -1;
1029 type_descriptor
= (*pp
)[-1];
1030 switch (type_descriptor
)
1034 enum type_code code
;
1036 /* Used to index through file_symbols. */
1037 struct pending
*ppt
;
1040 /* Name including "struct", etc. */
1043 /* Name without "struct", etc. */
1044 char *type_name_only
;
1050 /* Set the type code according to the following letter. */
1054 code
= TYPE_CODE_STRUCT
;
1058 code
= TYPE_CODE_UNION
;
1062 code
= TYPE_CODE_ENUM
;
1066 return error_type (pp
);
1069 to
= type_name
= (char *)
1070 obstack_alloc (&objfile
-> type_obstack
,
1072 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1074 /* Copy the prefix. */
1076 while ((*to
++ = *from
++) != '\0')
1080 type_name_only
= to
;
1082 /* Copy the name. */
1084 while ((*to
++ = *from
++) != ':')
1088 /* Set the pointer ahead of the name which we just read. */
1092 /* The following hack is clearly wrong, because it doesn't
1093 check whether we are in a baseclass. I tried to reproduce
1094 the case that it is trying to fix, but I couldn't get
1095 g++ to put out a cross reference to a basetype. Perhaps
1096 it doesn't do it anymore. */
1097 /* Note: for C++, the cross reference may be to a base type which
1098 has not yet been seen. In this case, we skip to the comma,
1099 which will mark the end of the base class name. (The ':'
1100 at the end of the base class name will be skipped as well.)
1101 But sometimes (ie. when the cross ref is the last thing on
1102 the line) there will be no ','. */
1103 from
= (char *) strchr (*pp
, ',');
1109 /* Now check to see whether the type has already been declared. */
1110 /* This is necessary at least in the case where the
1111 program says something like
1113 The compiler puts out a cross-reference; we better find
1114 set the length of the structure correctly so we can
1115 set the length of the array. */
1116 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1117 for (i
= 0; i
< ppt
->nsyms
; i
++)
1119 struct symbol
*sym
= ppt
->symbol
[i
];
1121 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1122 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1123 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1124 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1126 obstack_free (&objfile
-> type_obstack
, type_name
);
1127 type
= SYMBOL_TYPE (sym
);
1132 /* Didn't find the type to which this refers, so we must
1133 be dealing with a forward reference. Allocate a type
1134 structure for it, and keep track of it so we can
1135 fill in the rest of the fields when we get the full
1137 type
= dbx_alloc_type (typenums
, objfile
);
1138 TYPE_CODE (type
) = code
;
1139 TYPE_NAME (type
) = type_name
;
1140 INIT_CPLUS_SPECIFIC(type
);
1141 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1143 add_undefined_type (type
);
1147 case '-': /* RS/6000 built-in type */
1149 type
= builtin_type (pp
); /* (in xcoffread.c) */
1164 read_type_number (pp
, xtypenums
);
1165 type
= *dbx_lookup_type (xtypenums
);
1170 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1171 if (typenums
[0] != -1)
1172 *dbx_lookup_type (typenums
) = type
;
1175 /* In the following types, we must be sure to overwrite any existing
1176 type that the typenums refer to, rather than allocating a new one
1177 and making the typenums point to the new one. This is because there
1178 may already be pointers to the existing type (if it had been
1179 forward-referenced), and we must change it to a pointer, function,
1180 reference, or whatever, *in-place*. */
1183 type1
= read_type (pp
, objfile
);
1184 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1187 case '&': /* Reference to another type */
1188 type1
= read_type (pp
, objfile
);
1189 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1192 case 'f': /* Function returning another type */
1193 type1
= read_type (pp
, objfile
);
1194 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1197 case 'k': /* Const qualifier on some type (Sun) */
1198 type
= read_type (pp
, objfile
);
1199 /* FIXME! For now, we ignore const and volatile qualifiers. */
1202 case 'B': /* Volatile qual on some type (Sun) */
1203 type
= read_type (pp
, objfile
);
1204 /* FIXME! For now, we ignore const and volatile qualifiers. */
1207 /* FIXME -- we should be doing smash_to_XXX types here. */
1208 case '@': /* Member (class & variable) type */
1210 struct type
*domain
= read_type (pp
, objfile
);
1211 struct type
*memtype
;
1214 /* Invalid member type data format. */
1215 return error_type (pp
);
1218 memtype
= read_type (pp
, objfile
);
1219 type
= dbx_alloc_type (typenums
, objfile
);
1220 smash_to_member_type (type
, domain
, memtype
);
1224 case '#': /* Method (class & fn) type */
1225 if ((*pp
)[0] == '#')
1227 /* We'll get the parameter types from the name. */
1228 struct type
*return_type
;
1231 return_type
= read_type (pp
, objfile
);
1232 if (*(*pp
)++ != ';')
1233 complain (&invalid_member_complaint
, symnum
);
1234 type
= allocate_stub_method (return_type
);
1235 if (typenums
[0] != -1)
1236 *dbx_lookup_type (typenums
) = type
;
1240 struct type
*domain
= read_type (pp
, objfile
);
1241 struct type
*return_type
;
1244 if (*(*pp
)++ != ',')
1245 error ("invalid member type data format, at symtab pos %d.",
1248 return_type
= read_type (pp
, objfile
);
1249 args
= read_args (pp
, ';', objfile
);
1250 type
= dbx_alloc_type (typenums
, objfile
);
1251 smash_to_method_type (type
, domain
, return_type
, args
);
1255 case 'r': /* Range type */
1256 type
= read_range_type (pp
, typenums
, objfile
);
1257 if (typenums
[0] != -1)
1258 *dbx_lookup_type (typenums
) = type
;
1261 case 'b': /* Sun ACC builtin int type */
1262 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1263 if (typenums
[0] != -1)
1264 *dbx_lookup_type (typenums
) = type
;
1267 case 'R': /* Sun ACC builtin float type */
1268 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1269 if (typenums
[0] != -1)
1270 *dbx_lookup_type (typenums
) = type
;
1273 case 'e': /* Enumeration type */
1274 type
= dbx_alloc_type (typenums
, objfile
);
1275 type
= read_enum_type (pp
, type
, objfile
);
1276 *dbx_lookup_type (typenums
) = type
;
1279 case 's': /* Struct type */
1280 case 'u': /* Union type */
1281 type
= dbx_alloc_type (typenums
, objfile
);
1282 if (!TYPE_NAME (type
))
1284 TYPE_NAME (type
) = type_synonym_name
;
1286 type_synonym_name
= NULL
;
1287 switch (type_descriptor
)
1290 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1293 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1296 type
= read_struct_type (pp
, type
, objfile
);
1299 case 'a': /* Array type */
1301 return error_type (pp
);
1304 type
= dbx_alloc_type (typenums
, objfile
);
1305 type
= read_array_type (pp
, type
, objfile
);
1309 --*pp
; /* Go back to the symbol in error */
1310 /* Particularly important if it was \0! */
1311 return error_type (pp
);
1320 /* This page contains subroutines of read_type. */
1322 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1323 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1324 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1326 /* Read member function stabs info for C++ classes. The form of each member
1329 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1331 An example with two member functions is:
1333 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1335 For the case of overloaded operators, the format is op$::*.funcs, where
1336 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1337 name (such as `+=') and `.' marks the end of the operator name. */
1340 read_member_functions (fip
, pp
, type
, objfile
)
1341 struct field_info
*fip
;
1344 struct objfile
*objfile
;
1348 /* Total number of member functions defined in this class. If the class
1349 defines two `f' functions, and one `g' function, then this will have
1351 int total_length
= 0;
1355 struct next_fnfield
*next
;
1356 struct fn_field fn_field
;
1358 struct type
*look_ahead_type
;
1359 struct next_fnfieldlist
*new_fnlist
;
1360 struct next_fnfield
*new_sublist
;
1364 /* Process each list until we find something that is not a member function
1365 or find the end of the functions. */
1369 /* We should be positioned at the start of the function name.
1370 Scan forward to find the first ':' and if it is not the
1371 first of a "::" delimiter, then this is not a member function. */
1383 look_ahead_type
= NULL
;
1386 new_fnlist
= (struct next_fnfieldlist
*)
1387 xmalloc (sizeof (struct next_fnfieldlist
));
1388 make_cleanup (free
, new_fnlist
);
1389 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1391 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1393 /* This is a completely wierd case. In order to stuff in the
1394 names that might contain colons (the usual name delimiter),
1395 Mike Tiemann defined a different name format which is
1396 signalled if the identifier is "op$". In that case, the
1397 format is "op$::XXXX." where XXXX is the name. This is
1398 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1399 /* This lets the user type "break operator+".
1400 We could just put in "+" as the name, but that wouldn't
1402 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1403 char *o
= opname
+ 3;
1405 /* Skip past '::'. */
1408 STABS_CONTINUE (pp
);
1414 main_fn_name
= savestring (opname
, o
- opname
);
1420 main_fn_name
= savestring (*pp
, p
- *pp
);
1421 /* Skip past '::'. */
1424 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1429 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1430 make_cleanup (free
, new_sublist
);
1431 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1433 /* Check for and handle cretinous dbx symbol name continuation! */
1434 if (look_ahead_type
== NULL
)
1437 STABS_CONTINUE (pp
);
1439 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1442 /* Invalid symtab info for member function. */
1448 /* g++ version 1 kludge */
1449 new_sublist
-> fn_field
.type
= look_ahead_type
;
1450 look_ahead_type
= NULL
;
1460 /* If this is just a stub, then we don't have the real name here. */
1462 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1464 new_sublist
-> fn_field
.is_stub
= 1;
1466 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1469 /* Set this member function's visibility fields. */
1472 case VISIBILITY_PRIVATE
:
1473 new_sublist
-> fn_field
.is_private
= 1;
1475 case VISIBILITY_PROTECTED
:
1476 new_sublist
-> fn_field
.is_protected
= 1;
1480 STABS_CONTINUE (pp
);
1483 case 'A': /* Normal functions. */
1484 new_sublist
-> fn_field
.is_const
= 0;
1485 new_sublist
-> fn_field
.is_volatile
= 0;
1488 case 'B': /* `const' member functions. */
1489 new_sublist
-> fn_field
.is_const
= 1;
1490 new_sublist
-> fn_field
.is_volatile
= 0;
1493 case 'C': /* `volatile' member function. */
1494 new_sublist
-> fn_field
.is_const
= 0;
1495 new_sublist
-> fn_field
.is_volatile
= 1;
1498 case 'D': /* `const volatile' member function. */
1499 new_sublist
-> fn_field
.is_const
= 1;
1500 new_sublist
-> fn_field
.is_volatile
= 1;
1503 case '*': /* File compiled with g++ version 1 -- no info */
1508 complain (&const_vol_complaint
, **pp
);
1515 /* virtual member function, followed by index.
1516 The sign bit is set to distinguish pointers-to-methods
1517 from virtual function indicies. Since the array is
1518 in words, the quantity must be shifted left by 1
1519 on 16 bit machine, and by 2 on 32 bit machine, forcing
1520 the sign bit out, and usable as a valid index into
1521 the array. Remove the sign bit here. */
1522 new_sublist
-> fn_field
.voffset
=
1523 (0x7fffffff & read_number (pp
, ';')) + 2;
1525 STABS_CONTINUE (pp
);
1526 if (**pp
== ';' || **pp
== '\0')
1528 /* Must be g++ version 1. */
1529 new_sublist
-> fn_field
.fcontext
= 0;
1533 /* Figure out from whence this virtual function came.
1534 It may belong to virtual function table of
1535 one of its baseclasses. */
1536 look_ahead_type
= read_type (pp
, objfile
);
1539 /* g++ version 1 overloaded methods. */
1543 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1552 look_ahead_type
= NULL
;
1558 /* static member function. */
1559 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
1560 if (strncmp (new_sublist
-> fn_field
.physname
,
1561 main_fn_name
, strlen (main_fn_name
)))
1563 new_sublist
-> fn_field
.is_stub
= 1;
1569 complain (&member_fn_complaint
, (*pp
)[-1]);
1570 /* Fall through into normal member function. */
1573 /* normal member function. */
1574 new_sublist
-> fn_field
.voffset
= 0;
1575 new_sublist
-> fn_field
.fcontext
= 0;
1579 new_sublist
-> next
= sublist
;
1580 sublist
= new_sublist
;
1582 STABS_CONTINUE (pp
);
1584 while (**pp
!= ';' && **pp
!= '\0');
1588 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
1589 obstack_alloc (&objfile
-> type_obstack
,
1590 sizeof (struct fn_field
) * length
);
1591 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
1592 sizeof (struct fn_field
) * length
);
1593 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
1595 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
1598 new_fnlist
-> fn_fieldlist
.length
= length
;
1599 new_fnlist
-> next
= fip
-> fnlist
;
1600 fip
-> fnlist
= new_fnlist
;
1602 total_length
+= length
;
1603 STABS_CONTINUE (pp
);
1608 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1609 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
1610 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
1611 memset (TYPE_FN_FIELDLISTS (type
), 0,
1612 sizeof (struct fn_fieldlist
) * nfn_fields
);
1613 TYPE_NFN_FIELDS (type
) = nfn_fields
;
1614 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
1620 /* Special GNU C++ name.
1621 FIXME: Still need to properly handle parse error conditions. */
1624 read_cpp_abbrev (fip
, pp
, type
, objfile
)
1625 struct field_info
*fip
;
1628 struct objfile
*objfile
;
1633 struct type
*context
;
1648 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1649 prefix
= "INVALID_C++_ABBREV";
1654 /* At this point, *pp points to something like "22:23=*22...",
1655 where the type number before the ':' is the "context" and
1656 everything after is a regular type definition. Lookup the
1657 type, find it's name, and construct the field name. */
1659 context
= read_type (pp
, objfile
);
1660 name
= type_name_no_tag (context
);
1663 complain (&invalid_cpp_type_complaint
, symnum
);
1666 fip
-> list
-> field
.name
=
1667 obconcat (&objfile
-> type_obstack
, prefix
, name
, "");
1669 /* At this point, *pp points to the ':'. Skip it and read the
1675 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1677 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
1678 (*pp
)++; /* Skip the comma. */
1679 fip
-> list
-> field
.bitpos
= read_number (pp
, ';');
1680 /* This field is unpacked. */
1681 fip
-> list
-> field
.bitsize
= 0;
1682 fip
-> list
-> visibility
= VISIBILITY_PRIVATE
;
1686 /* GNU C++ anonymous type. */
1687 complain (&stabs_general_complaint
, "g++ anonymous type $_ not handled");
1691 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1696 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
1697 struct field_info
*fip
;
1701 struct objfile
*objfile
;
1703 fip
-> list
-> field
.name
=
1704 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
1707 /* This means we have a visibility for a field coming. */
1711 fip
-> list
-> visibility
= *(*pp
)++;
1712 switch (fip
-> list
-> visibility
)
1714 case VISIBILITY_PRIVATE
:
1715 case VISIBILITY_PROTECTED
:
1718 case VISIBILITY_PUBLIC
:
1723 /* Unknown visibility specifier. */
1724 complain (&stabs_general_complaint
,
1725 "unknown visibility specifier");
1732 /* normal dbx-style format, no explicit visibility */
1733 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
1736 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
1741 /* Possible future hook for nested types. */
1744 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
1750 /* Static class member. */
1751 fip
-> list
-> field
.bitpos
= (long) -1;
1757 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
1761 else if (**pp
!= ',')
1763 /* Bad structure-type format. */
1764 complain (&stabs_general_complaint
, "bad structure-type format");
1768 (*pp
)++; /* Skip the comma. */
1769 fip
-> list
-> field
.bitpos
= read_number (pp
, ',');
1770 fip
-> list
-> field
.bitsize
= read_number (pp
, ';');
1773 /* FIXME-tiemann: Can't the compiler put out something which
1774 lets us distinguish these? (or maybe just not put out anything
1775 for the field). What is the story here? What does the compiler
1776 really do? Also, patch gdb.texinfo for this case; I document
1777 it as a possible problem there. Search for "DBX-style". */
1779 /* This is wrong because this is identical to the symbols
1780 produced for GCC 0-size arrays. For example:
1785 The code which dumped core in such circumstances should be
1786 fixed not to dump core. */
1788 /* g++ -g0 can put out bitpos & bitsize zero for a static
1789 field. This does not give us any way of getting its
1790 class, so we can't know its name. But we can just
1791 ignore the field so we don't dump core and other nasty
1793 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
1795 complain (&dbx_class_complaint
);
1796 /* Ignore this field. */
1797 fip
-> list
= fip
-> list
-> next
;
1802 /* Detect an unpacked field and mark it as such.
1803 dbx gives a bit size for all fields.
1804 Note that forward refs cannot be packed,
1805 and treat enums as if they had the width of ints. */
1807 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
1808 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
1810 fip
-> list
-> field
.bitsize
= 0;
1812 if ((fip
-> list
-> field
.bitsize
1813 == 8 * TYPE_LENGTH (fip
-> list
-> field
.type
)
1814 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
1815 && (fip
-> list
-> field
.bitsize
1816 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
1820 fip
-> list
-> field
.bitpos
% 8 == 0)
1822 fip
-> list
-> field
.bitsize
= 0;
1828 /* Read struct or class data fields. They have the form:
1830 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
1832 At the end, we see a semicolon instead of a field.
1834 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1837 The optional VISIBILITY is one of:
1839 '/0' (VISIBILITY_PRIVATE)
1840 '/1' (VISIBILITY_PROTECTED)
1841 '/2' (VISIBILITY_PUBLIC)
1843 or nothing, for C style fields with public visibility. */
1846 read_struct_fields (fip
, pp
, type
, objfile
)
1847 struct field_info
*fip
;
1850 struct objfile
*objfile
;
1853 struct nextfield
*new;
1855 /* We better set p right now, in case there are no fields at all... */
1859 /* Read each data member type until we find the terminating ';' at the end of
1860 the data member list, or break for some other reason such as finding the
1861 start of the member function list. */
1865 STABS_CONTINUE (pp
);
1866 /* Get space to record the next field's data. */
1867 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1868 make_cleanup (free
, new);
1869 memset (new, 0, sizeof (struct nextfield
));
1870 new -> next
= fip
-> list
;
1873 /* Get the field name. */
1875 if (*p
== CPLUS_MARKER
)
1877 read_cpp_abbrev (fip
, pp
, type
, objfile
);
1881 /* Look for the ':' that separates the field name from the field
1882 values. Data members are delimited by a single ':', while member
1883 functions are delimited by a pair of ':'s. When we hit the member
1884 functions (if any), terminate scan loop and return. */
1891 /* Check to see if we have hit the member functions yet. */
1896 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
1900 /* chill the list of fields: the last entry (at the head) is a
1901 partially constructed entry which we now scrub. */
1902 fip
-> list
= fip
-> list
-> next
;
1907 /* The stabs for C++ derived classes contain baseclass information which
1908 is marked by a '!' character after the total size. This function is
1909 called when we encounter the baseclass marker, and slurps up all the
1910 baseclass information.
1912 Immediately following the '!' marker is the number of base classes that
1913 the class is derived from, followed by information for each base class.
1914 For each base class, there are two visibility specifiers, a bit offset
1915 to the base class information within the derived class, a reference to
1916 the type for the base class, and a terminating semicolon.
1918 A typical example, with two base classes, would be "!2,020,19;0264,21;".
1920 Baseclass information marker __________________|| | | | | | |
1921 Number of baseclasses __________________________| | | | | | |
1922 Visibility specifiers (2) ________________________| | | | | |
1923 Offset in bits from start of class _________________| | | | |
1924 Type number for base class ___________________________| | | |
1925 Visibility specifiers (2) _______________________________| | |
1926 Offset in bits from start of class ________________________| |
1927 Type number of base class ____________________________________|
1931 read_baseclasses (fip
, pp
, type
, objfile
)
1932 struct field_info
*fip
;
1935 struct objfile
*objfile
;
1938 struct nextfield
*new;
1946 /* Skip the '!' baseclass information marker. */
1950 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1951 TYPE_N_BASECLASSES (type
) = read_number (pp
, ',');
1954 /* Some stupid compilers have trouble with the following, so break
1955 it up into simpler expressions. */
1956 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
1957 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
1960 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
1963 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1964 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1968 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
1970 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1972 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1973 make_cleanup (free
, new);
1974 memset (new, 0, sizeof (struct nextfield
));
1975 new -> next
= fip
-> list
;
1977 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
1979 STABS_CONTINUE (pp
);
1983 /* Nothing to do. */
1986 SET_TYPE_FIELD_VIRTUAL (type
, i
);
1989 /* Bad visibility format. */
1993 new -> visibility
= *(*pp
)++;
1994 switch (new -> visibility
)
1996 case VISIBILITY_PRIVATE
:
1997 case VISIBILITY_PROTECTED
:
1998 case VISIBILITY_PUBLIC
:
2001 /* Bad visibility format. */
2005 /* The remaining value is the bit offset of the portion of the object
2006 corresponding to this baseclass. Always zero in the absence of
2007 multiple inheritance. */
2009 new -> field
.bitpos
= read_number (pp
, ',');
2011 /* The last piece of baseclass information is the type of the base
2012 class. Read it, and remember it's type name as this field's name. */
2014 new -> field
.type
= read_type (pp
, objfile
);
2015 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2017 /* skip trailing ';' and bump count of number of fields seen */
2024 read_tilde_fields (fip
, pp
, type
, objfile
)
2025 struct field_info
*fip
;
2028 struct objfile
*objfile
;
2032 STABS_CONTINUE (pp
);
2034 /* If we are positioned at a ';', then skip it. */
2044 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2046 /* Obsolete flags that used to indicate the presence
2047 of constructors and/or destructors. */
2051 /* Read either a '%' or the final ';'. */
2052 if (*(*pp
)++ == '%')
2054 /* We'd like to be able to derive the vtable pointer field
2055 from the type information, but when it's inherited, that's
2056 hard. A reason it's hard is because we may read in the
2057 info about a derived class before we read in info about
2058 the base class that provides the vtable pointer field.
2059 Once the base info has been read, we could fill in the info
2060 for the derived classes, but for the fact that by then,
2061 we don't remember who needs what. */
2064 int predicted_fieldno
= -1;
2067 /* Now we must record the virtual function table pointer's
2068 field information. */
2075 /* In version 2, we derive the vfield ourselves. */
2076 for (n
= 0; n
< TYPE_NFIELDS (type
); n
++)
2078 if (! strncmp (TYPE_FIELD_NAME (type
, n
), vptr_name
,
2079 sizeof (vptr_name
) - 1))
2081 predicted_fieldno
= n
;
2085 if (predicted_fieldno
< 0)
2087 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2089 if (! TYPE_FIELD_VIRTUAL (type
, n
)
2090 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
)) >= 0)
2093 TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type
, n
));
2101 t
= read_type (pp
, objfile
);
2103 while (*p
!= '\0' && *p
!= ';')
2109 /* Premature end of symbol. */
2113 TYPE_VPTR_BASETYPE (type
) = t
;
2116 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2118 /* FIXME-tiemann: what's this? */
2120 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2127 for (i
= TYPE_NFIELDS (t
) - 1;
2128 i
>= TYPE_N_BASECLASSES (t
);
2131 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2132 sizeof (vptr_name
) - 1))
2134 TYPE_VPTR_FIELDNO (type
) = i
;
2141 /* Virtual function table field not found. */
2147 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2151 if (TYPE_VPTR_FIELDNO (type
) != predicted_fieldno
)
2153 error ("TYPE_VPTR_FIELDNO miscalculated");
2164 attach_fn_fields_to_type (fip
, type
)
2165 struct field_info
*fip
;
2166 register struct type
*type
;
2170 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2172 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2174 /* @@ Memory leak on objfile -> type_obstack? */
2177 TYPE_NFN_FIELDS_TOTAL (type
) +=
2178 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2181 for (n
= TYPE_NFN_FIELDS (type
);
2182 fip
-> fnlist
!= NULL
;
2183 fip
-> fnlist
= fip
-> fnlist
-> next
)
2185 --n
; /* Circumvent Sun3 compiler bug */
2186 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2191 /* Create the vector of fields, and record how big it is.
2192 We need this info to record proper virtual function table information
2193 for this class's virtual functions. */
2196 attach_fields_to_type (fip
, type
, objfile
)
2197 struct field_info
*fip
;
2198 register struct type
*type
;
2199 struct objfile
*objfile
;
2201 register int nfields
= 0;
2202 register int non_public_fields
= 0;
2203 register struct nextfield
*scan
;
2205 /* Count up the number of fields that we have, as well as taking note of
2206 whether or not there are any non-public fields, which requires us to
2207 allocate and build the private_field_bits and protected_field_bits
2210 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2213 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2215 non_public_fields
++;
2219 /* Now we know how many fields there are, and whether or not there are any
2220 non-public fields. Record the field count, allocate space for the
2221 array of fields, and create blank visibility bitfields if necessary. */
2223 TYPE_NFIELDS (type
) = nfields
;
2224 TYPE_FIELDS (type
) = (struct field
*)
2225 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2226 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2228 if (non_public_fields
)
2230 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2232 TYPE_FIELD_PRIVATE_BITS (type
) =
2233 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2234 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2236 TYPE_FIELD_PROTECTED_BITS (type
) =
2237 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2238 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2241 /* Copy the saved-up fields into the field vector. Start from the head
2242 of the list, adding to the tail of the field array, so that they end
2243 up in the same order in the array in which they were added to the list. */
2245 while (nfields
-- > 0)
2247 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2248 switch (fip
-> list
-> visibility
)
2250 case VISIBILITY_PRIVATE
:
2251 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2254 case VISIBILITY_PROTECTED
:
2255 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2258 case VISIBILITY_PUBLIC
:
2262 /* Should warn about this unknown visibility? */
2265 fip
-> list
= fip
-> list
-> next
;
2270 /* Read the description of a structure (or union type) and return an object
2271 describing the type.
2273 PP points to a character pointer that points to the next unconsumed token
2274 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2275 *PP will point to "4a:1,0,32;;".
2277 TYPE points to an incomplete type that needs to be filled in.
2279 OBJFILE points to the current objfile from which the stabs information is
2280 being read. (Note that it is redundant in that TYPE also contains a pointer
2281 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2284 static struct type
*
2285 read_struct_type (pp
, type
, objfile
)
2288 struct objfile
*objfile
;
2290 struct cleanup
*back_to
;
2291 struct field_info fi
;
2296 back_to
= make_cleanup (null_cleanup
, 0);
2298 INIT_CPLUS_SPECIFIC (type
);
2299 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2301 /* First comes the total size in bytes. */
2303 TYPE_LENGTH (type
) = read_number (pp
, 0);
2305 /* Now read the baseclasses, if any, read the regular C struct or C++
2306 class member fields, attach the fields to the type, read the C++
2307 member functions, attach them to the type, and then read any tilde
2310 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2311 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2312 || !attach_fields_to_type (&fi
, type
, objfile
)
2313 || !read_member_functions (&fi
, pp
, type
, objfile
)
2314 || !attach_fn_fields_to_type (&fi
, type
)
2315 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2317 do_cleanups (back_to
);
2318 return (error_type (pp
));
2321 do_cleanups (back_to
);
2325 /* Read a definition of an array type,
2326 and create and return a suitable type object.
2327 Also creates a range type which represents the bounds of that
2330 static struct type
*
2331 read_array_type (pp
, type
, objfile
)
2333 register struct type
*type
;
2334 struct objfile
*objfile
;
2336 struct type
*index_type
, *element_type
, *range_type
;
2340 /* Format of an array type:
2341 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2344 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2345 for these, produce a type like float[][]. */
2347 index_type
= read_type (pp
, objfile
);
2349 /* Improper format of array type decl. */
2350 return error_type (pp
);
2353 if (!(**pp
>= '0' && **pp
<= '9'))
2358 lower
= read_number (pp
, ';');
2360 if (!(**pp
>= '0' && **pp
<= '9'))
2365 upper
= read_number (pp
, ';');
2367 element_type
= read_type (pp
, objfile
);
2376 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2377 type
= create_array_type (type
, element_type
, range_type
);
2379 /* If we have an array whose element type is not yet known, but whose
2380 bounds *are* known, record it to be adjusted at the end of the file. */
2382 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2384 add_undefined_type (type
);
2391 /* Read a definition of an enumeration type,
2392 and create and return a suitable type object.
2393 Also defines the symbols that represent the values of the type. */
2395 static struct type
*
2396 read_enum_type (pp
, type
, objfile
)
2398 register struct type
*type
;
2399 struct objfile
*objfile
;
2404 register struct symbol
*sym
;
2406 struct pending
**symlist
;
2407 struct pending
*osyms
, *syms
;
2411 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2412 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2413 to do? For now, force all enum values to file scope. */
2414 if (within_function
)
2415 symlist
= &local_symbols
;
2418 symlist
= &file_symbols
;
2420 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2422 /* Read the value-names and their values.
2423 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2424 A semicolon or comma instead of a NAME means the end. */
2425 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2427 STABS_CONTINUE (pp
);
2429 while (*p
!= ':') p
++;
2430 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2432 n
= read_number (pp
, ',');
2434 sym
= (struct symbol
*)
2435 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2436 memset (sym
, 0, sizeof (struct symbol
));
2437 SYMBOL_NAME (sym
) = name
;
2438 SYMBOL_CLASS (sym
) = LOC_CONST
;
2439 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2440 SYMBOL_VALUE (sym
) = n
;
2441 add_symbol_to_list (sym
, symlist
);
2446 (*pp
)++; /* Skip the semicolon. */
2448 /* Now fill in the fields of the type-structure. */
2450 TYPE_LENGTH (type
) = sizeof (int);
2451 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2452 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2453 TYPE_NFIELDS (type
) = nsyms
;
2454 TYPE_FIELDS (type
) = (struct field
*)
2455 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2456 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2458 /* Find the symbols for the values and put them into the type.
2459 The symbols can be found in the symlist that we put them on
2460 to cause them to be defined. osyms contains the old value
2461 of that symlist; everything up to there was defined by us. */
2462 /* Note that we preserve the order of the enum constants, so
2463 that in something like "enum {FOO, LAST_THING=FOO}" we print
2464 FOO, not LAST_THING. */
2466 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2471 for (; j
< syms
->nsyms
; j
++,n
++)
2473 struct symbol
*xsym
= syms
->symbol
[j
];
2474 SYMBOL_TYPE (xsym
) = type
;
2475 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2476 TYPE_FIELD_VALUE (type
, n
) = 0;
2477 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2478 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2485 /* This screws up perfectly good C programs with enums. FIXME. */
2486 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2487 if(TYPE_NFIELDS(type
) == 2 &&
2488 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2489 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2490 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2491 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2492 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2498 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2499 typedefs in every file (for int, long, etc):
2501 type = b <signed> <width>; <offset>; <nbits>
2502 signed = u or s. Possible c in addition to u or s (for char?).
2503 offset = offset from high order bit to start bit of type.
2504 width is # bytes in object of this type, nbits is # bits in type.
2506 The width/offset stuff appears to be for small objects stored in
2507 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2510 static struct type
*
2511 read_sun_builtin_type (pp
, typenums
, objfile
)
2514 struct objfile
*objfile
;
2528 return error_type (pp
);
2532 /* For some odd reason, all forms of char put a c here. This is strange
2533 because no other type has this honor. We can safely ignore this because
2534 we actually determine 'char'acterness by the number of bits specified in
2540 /* The first number appears to be the number of bytes occupied
2541 by this type, except that unsigned short is 4 instead of 2.
2542 Since this information is redundant with the third number,
2543 we will ignore it. */
2544 read_number (pp
, ';');
2546 /* The second number is always 0, so ignore it too. */
2547 read_number (pp
, ';');
2549 /* The third number is the number of bits for this type. */
2550 nbits
= read_number (pp
, 0);
2552 /* FIXME. Here we should just be able to make a type of the right
2553 number of bits and signedness. FIXME. */
2555 if (nbits
== TARGET_LONG_LONG_BIT
)
2556 return (lookup_fundamental_type (objfile
,
2557 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
2559 if (nbits
== TARGET_INT_BIT
)
2561 /* FIXME -- the only way to distinguish `int' from `long'
2562 is to look at its name! */
2565 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2566 return lookup_fundamental_type (objfile
, FT_LONG
);
2568 return lookup_fundamental_type (objfile
, FT_INTEGER
);
2572 if (long_kludge_name
2573 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2574 long_kludge_name
[9] == 'l' /* long */)
2575 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2576 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
2578 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
2582 if (nbits
== TARGET_SHORT_BIT
)
2583 return (lookup_fundamental_type (objfile
,
2584 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
2586 if (nbits
== TARGET_CHAR_BIT
)
2587 return (lookup_fundamental_type (objfile
,
2588 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
2591 return lookup_fundamental_type (objfile
, FT_VOID
);
2593 return error_type (pp
);
2596 static struct type
*
2597 read_sun_floating_type (pp
, typenums
, objfile
)
2600 struct objfile
*objfile
;
2604 /* The first number has more details about the type, for example
2605 FN_COMPLEX. See the sun stab.h. */
2606 read_number (pp
, ';');
2608 /* The second number is the number of bytes occupied by this type */
2609 nbytes
= read_number (pp
, ';');
2612 return error_type (pp
);
2614 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
2615 return lookup_fundamental_type (objfile
, FT_FLOAT
);
2617 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2618 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
2620 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2621 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
2623 return error_type (pp
);
2626 /* Read a number from the string pointed to by *PP.
2627 The value of *PP is advanced over the number.
2628 If END is nonzero, the character that ends the
2629 number must match END, or an error happens;
2630 and that character is skipped if it does match.
2631 If END is zero, *PP is left pointing to that character.
2633 If the number fits in a long, set *VALUE and set *BITS to 0.
2634 If not, set *BITS to be the number of bits in the number.
2636 If encounter garbage, set *BITS to -1. */
2639 read_huge_number (pp
, end
, valu
, bits
)
2660 /* Leading zero means octal. GCC uses this to output values larger
2661 than an int (because that would be hard in decimal). */
2668 upper_limit
= LONG_MAX
/ radix
;
2669 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2671 if (n
<= upper_limit
)
2674 n
+= c
- '0'; /* FIXME this overflows anyway */
2679 /* This depends on large values being output in octal, which is
2686 /* Ignore leading zeroes. */
2690 else if (c
== '2' || c
== '3')
2716 /* Large decimal constants are an error (because it is hard to
2717 count how many bits are in them). */
2723 /* -0x7f is the same as 0x80. So deal with it by adding one to
2724 the number of bits. */
2739 static struct type
*
2740 read_range_type (pp
, typenums
, objfile
)
2743 struct objfile
*objfile
;
2749 struct type
*result_type
;
2750 struct type
*index_type
;
2752 /* First comes a type we are a subrange of.
2753 In C it is usually 0, 1 or the type being defined. */
2754 read_type_number (pp
, rangenums
);
2755 self_subrange
= (rangenums
[0] == typenums
[0] &&
2756 rangenums
[1] == typenums
[1]);
2758 /* A semicolon should now follow; skip it. */
2762 /* The remaining two operands are usually lower and upper bounds
2763 of the range. But in some special cases they mean something else. */
2764 read_huge_number (pp
, ';', &n2
, &n2bits
);
2765 read_huge_number (pp
, ';', &n3
, &n3bits
);
2767 if (n2bits
== -1 || n3bits
== -1)
2768 return error_type (pp
);
2770 /* If limits are huge, must be large integral type. */
2771 if (n2bits
!= 0 || n3bits
!= 0)
2773 char got_signed
= 0;
2774 char got_unsigned
= 0;
2775 /* Number of bits in the type. */
2778 /* Range from 0 to <large number> is an unsigned large integral type. */
2779 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2784 /* Range from <large number> to <large number>-1 is a large signed
2786 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2792 /* Check for "long long". */
2793 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2794 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2795 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2796 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2798 if (got_signed
|| got_unsigned
)
2800 result_type
= alloc_type (objfile
);
2801 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2802 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2804 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2808 return error_type (pp
);
2811 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2812 if (self_subrange
&& n2
== 0 && n3
== 0)
2813 return (lookup_fundamental_type (objfile
, FT_VOID
));
2815 /* If n3 is zero and n2 is not, we want a floating type,
2816 and n2 is the width in bytes.
2818 Fortran programs appear to use this for complex types also,
2819 and they give no way to distinguish between double and single-complex!
2820 We don't have complex types, so we would lose on all fortran files!
2821 So return type `double' for all of those. It won't work right
2822 for the complex values, but at least it makes the file loadable.
2824 FIXME, we may be able to distinguish these by their names. FIXME. */
2826 if (n3
== 0 && n2
> 0)
2828 if (n2
== sizeof (float))
2829 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
2830 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
2833 /* If the upper bound is -1, it must really be an unsigned int. */
2835 else if (n2
== 0 && n3
== -1)
2837 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2838 long' is to look at its name! */
2840 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2841 long_kludge_name
[9] == 'l' /* long */)
2842 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2843 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2845 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2848 /* Special case: char is defined (Who knows why) as a subrange of
2849 itself with range 0-127. */
2850 else if (self_subrange
&& n2
== 0 && n3
== 127)
2851 return (lookup_fundamental_type (objfile
, FT_CHAR
));
2853 /* Assumptions made here: Subrange of self is equivalent to subrange
2854 of int. FIXME: Host and target type-sizes assumed the same. */
2855 /* FIXME: This is the *only* place in GDB that depends on comparing
2856 some type to a builtin type with ==. Fix it! */
2858 && (self_subrange
||
2859 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
2861 /* an unsigned type */
2863 if (n3
== - sizeof (long long))
2864 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2866 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2867 long' is to look at its name! */
2868 if (n3
== (unsigned long)~0L &&
2869 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2870 long_kludge_name
[9] == 'l' /* long */)
2871 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2872 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2873 if (n3
== (unsigned int)~0L)
2874 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2875 if (n3
== (unsigned short)~0L)
2876 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
2877 if (n3
== (unsigned char)~0L)
2878 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
2881 else if (n3
== 0 && n2
== -sizeof (long long))
2882 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2884 else if (n2
== -n3
-1)
2887 /* FIXME -- the only way to distinguish `int' from `long' is to look
2889 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2890 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2891 return (lookup_fundamental_type (objfile
, FT_LONG
));
2892 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2893 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
2894 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
2895 return (lookup_fundamental_type (objfile
, FT_SHORT
));
2896 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
2897 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
2900 /* We have a real range type on our hands. Allocate space and
2901 return a real pointer. */
2903 /* At this point I don't have the faintest idea how to deal with
2904 a self_subrange type; I'm going to assume that this is used
2905 as an idiom, and that all of them are special cases. So . . . */
2907 return error_type (pp
);
2909 index_type
= *dbx_lookup_type (rangenums
);
2910 if (index_type
== NULL
)
2912 complain (&range_type_base_complaint
, rangenums
[1]);
2913 index_type
= lookup_fundamental_type (objfile
, FT_INTEGER
);
2916 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
2917 return (result_type
);
2920 /* Read a number from the string pointed to by *PP.
2921 The value of *PP is advanced over the number.
2922 If END is nonzero, the character that ends the
2923 number must match END, or an error happens;
2924 and that character is skipped if it does match.
2925 If END is zero, *PP is left pointing to that character. */
2928 read_number (pp
, end
)
2932 register char *p
= *pp
;
2933 register long n
= 0;
2937 /* Handle an optional leading minus sign. */
2945 /* Read the digits, as far as they go. */
2947 while ((c
= *p
++) >= '0' && c
<= '9')
2955 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
2964 /* Read in an argument list. This is a list of types, separated by commas
2965 and terminated with END. Return the list of types read in, or (struct type
2966 **)-1 if there is an error. */
2968 static struct type
**
2969 read_args (pp
, end
, objfile
)
2972 struct objfile
*objfile
;
2974 /* FIXME! Remove this arbitrary limit! */
2975 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
2981 /* Invalid argument list: no ','. */
2982 return (struct type
**)-1;
2984 STABS_CONTINUE (pp
);
2985 types
[n
++] = read_type (pp
, objfile
);
2987 (*pp
)++; /* get past `end' (the ':' character) */
2991 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
2993 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
2995 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
2996 memset (rval
+ n
, 0, sizeof (struct type
*));
3000 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3002 memcpy (rval
, types
, n
* sizeof (struct type
*));
3006 /* Add a common block's start address to the offset of each symbol
3007 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3008 the common block name). */
3011 fix_common_block (sym
, valu
)
3015 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3016 for ( ; next
; next
= next
->next
)
3019 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3020 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3026 /* What about types defined as forward references inside of a small lexical
3028 /* Add a type to the list of undefined types to be checked through
3029 once this file has been read in. */
3032 add_undefined_type (type
)
3035 if (undef_types_length
== undef_types_allocated
)
3037 undef_types_allocated
*= 2;
3038 undef_types
= (struct type
**)
3039 xrealloc ((char *) undef_types
,
3040 undef_types_allocated
* sizeof (struct type
*));
3042 undef_types
[undef_types_length
++] = type
;
3045 /* Go through each undefined type, see if it's still undefined, and fix it
3046 up if possible. We have two kinds of undefined types:
3048 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3049 Fix: update array length using the element bounds
3050 and the target type's length.
3051 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3052 yet defined at the time a pointer to it was made.
3053 Fix: Do a full lookup on the struct/union tag. */
3055 cleanup_undefined_types ()
3059 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3061 switch (TYPE_CODE (*type
))
3064 case TYPE_CODE_STRUCT
:
3065 case TYPE_CODE_UNION
:
3066 case TYPE_CODE_ENUM
:
3068 /* Check if it has been defined since. */
3069 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3071 struct pending
*ppt
;
3073 /* Name of the type, without "struct" or "union" */
3074 char *typename
= TYPE_NAME (*type
);
3076 if (!strncmp (typename
, "struct ", 7))
3078 if (!strncmp (typename
, "union ", 6))
3080 if (!strncmp (typename
, "enum ", 5))
3083 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3085 for (i
= 0; i
< ppt
->nsyms
; i
++)
3087 struct symbol
*sym
= ppt
->symbol
[i
];
3089 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3090 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3091 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3093 && !strcmp (SYMBOL_NAME (sym
), typename
))
3095 memcpy (*type
, SYMBOL_TYPE (sym
),
3096 sizeof (struct type
));
3104 case TYPE_CODE_ARRAY
:
3106 struct type
*range_type
;
3109 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3111 if (TYPE_NFIELDS (*type
) != 1)
3113 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3114 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3117 /* Now recompute the length of the array type, based on its
3118 number of elements and the target type's length. */
3119 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3120 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3121 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3122 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3128 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type
));
3132 undef_types_length
= 0;
3135 /* Scan through all of the global symbols defined in the object file,
3136 assigning values to the debugging symbols that need to be assigned
3137 to. Get these symbols from the minimal symbol table. */
3140 scan_file_globals (objfile
)
3141 struct objfile
*objfile
;
3144 struct minimal_symbol
*msymbol
;
3145 struct symbol
*sym
, *prev
;
3147 if (objfile
->msymbols
== 0) /* Beware the null file. */
3150 for (msymbol
= objfile
-> msymbols
; msymbol
-> name
!= NULL
; msymbol
++)
3156 /* Get the hash index and check all the symbols
3157 under that hash index. */
3159 hash
= hashname (msymbol
-> name
);
3161 for (sym
= global_sym_chain
[hash
]; sym
;)
3163 if (*(msymbol
-> name
) == SYMBOL_NAME (sym
)[0]
3164 && !strcmp(msymbol
-> name
+ 1, SYMBOL_NAME (sym
) + 1))
3166 /* Splice this symbol out of the hash chain and
3167 assign the value we have to it. */
3170 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3174 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3177 /* Check to see whether we need to fix up a common block. */
3178 /* Note: this code might be executed several times for
3179 the same symbol if there are multiple references. */
3181 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3183 fix_common_block (sym
, msymbol
-> address
);
3187 SYMBOL_VALUE_ADDRESS (sym
) = msymbol
-> address
;
3192 sym
= SYMBOL_VALUE_CHAIN (prev
);
3196 sym
= global_sym_chain
[hash
];
3202 sym
= SYMBOL_VALUE_CHAIN (sym
);
3208 /* Initialize anything that needs initializing when starting to read
3209 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3217 /* Initialize anything that needs initializing when a completely new
3218 symbol file is specified (not just adding some symbols from another
3219 file, e.g. a shared library). */
3222 stabsread_new_init ()
3224 /* Empty the hash table of global syms looking for values. */
3225 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3228 /* Initialize anything that needs initializing at the same time as
3229 start_symtab() is called. */
3233 global_stabs
= NULL
; /* AIX COFF */
3234 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3235 n_this_object_header_files
= 1;
3236 type_vector_length
= 0;
3237 type_vector
= (struct type
**) 0;
3240 /* Call after end_symtab() */
3246 free ((char *) type_vector
);
3249 type_vector_length
= 0;
3250 previous_stab_code
= 0;
3254 finish_global_stabs (objfile
)
3255 struct objfile
*objfile
;
3259 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3260 free ((PTR
) global_stabs
);
3261 global_stabs
= NULL
;
3265 /* Initializer for this module */
3268 _initialize_stabsread ()
3270 undef_types_allocated
= 20;
3271 undef_types_length
= 0;
3272 undef_types
= (struct type
**)
3273 xmalloc (undef_types_allocated
* sizeof (struct type
*));