1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
36 #include "complaints.h"
39 /* Ask stabsread.h to define the vars it normally declares `extern'. */
41 #include "stabsread.h" /* Our own declarations */
44 /* The routines that read and process a complete stabs for a C struct or
45 C++ class pass lists of data member fields and lists of member function
46 fields in an instance of a field_info structure, as defined below.
47 This is part of some reorganization of low level C++ support and is
48 expected to eventually go away... (FIXME) */
54 struct nextfield
*next
;
58 struct next_fnfieldlist
60 struct next_fnfieldlist
*next
;
61 struct fn_fieldlist fn_fieldlist
;
66 dbx_alloc_type
PARAMS ((int [2], struct objfile
*));
69 read_huge_number
PARAMS ((char **, int, long *, int *));
72 patch_block_stabs
PARAMS ((struct pending
*, struct pending_stabs
*,
76 fix_common_block
PARAMS ((struct symbol
*, int));
79 read_range_type
PARAMS ((char **, int [2], struct objfile
*));
82 read_sun_builtin_type
PARAMS ((char **, int [2], struct objfile
*));
85 read_sun_floating_type
PARAMS ((char **, int [2], struct objfile
*));
88 read_enum_type
PARAMS ((char **, struct type
*, struct objfile
*));
91 rs6000_builtin_type
PARAMS ((char **pp
));
94 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
98 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
102 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
106 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
110 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
113 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
117 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
120 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
122 static struct type
**
123 read_args
PARAMS ((char **, int, struct objfile
*));
126 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
129 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
130 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
132 /* Define this as 1 if a pcc declaration of a char or short argument
133 gives the correct address. Otherwise assume pcc gives the
134 address of the corresponding int, which is not the same on a
135 big-endian machine. */
137 #ifndef BELIEVE_PCC_PROMOTION
138 #define BELIEVE_PCC_PROMOTION 0
141 /* During some calls to read_type (and thus to read_range_type), this
142 contains the name of the type being defined. Range types are only
143 used in C as basic types. We use the name to distinguish the otherwise
144 identical basic types "int" and "long" and their unsigned versions.
145 FIXME, this should disappear with better type management. */
147 static char *long_kludge_name
;
150 struct complaint dbx_class_complaint
=
152 "encountered DBX-style class variable debugging information.\n\
153 You seem to have compiled your program with \
154 \"g++ -g0\" instead of \"g++ -g\".\n\
155 Therefore GDB will not know about your class variables", 0, 0
159 struct complaint invalid_cpp_abbrev_complaint
=
160 {"invalid C++ abbreviation `%s'", 0, 0};
162 struct complaint invalid_cpp_type_complaint
=
163 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
165 struct complaint member_fn_complaint
=
166 {"member function type missing, got '%c'", 0, 0};
168 struct complaint const_vol_complaint
=
169 {"const/volatile indicator missing, got '%c'", 0, 0};
171 struct complaint error_type_complaint
=
172 {"debug info mismatch between compiler and debugger", 0, 0};
174 struct complaint invalid_member_complaint
=
175 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
177 struct complaint range_type_base_complaint
=
178 {"base type %d of range type is not defined", 0, 0};
180 struct complaint reg_value_complaint
=
181 {"register number too large in symbol %s", 0, 0};
183 struct complaint vtbl_notfound_complaint
=
184 {"virtual function table pointer not found when defining class `%s'", 0, 0};
186 struct complaint unrecognized_cplus_name_complaint
=
187 {"Unknown C++ symbol name `%s'", 0, 0};
189 struct complaint rs6000_builtin_complaint
=
190 {"Unknown builtin type -%d", 0, 0};
192 struct complaint stabs_general_complaint
=
195 /* Make a list of forward references which haven't been defined. */
197 static struct type
**undef_types
;
198 static int undef_types_allocated
;
199 static int undef_types_length
;
201 /* Check for and handle cretinous stabs symbol name continuation! */
202 #define STABS_CONTINUE(pp) \
204 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
212 register char *p
= name
;
213 register int total
= p
[0];
228 /* Ensure result is positive. */
231 total
+= (1000 << 6);
233 return (total
% HASHSIZE
);
237 /* Look up a dbx type-number pair. Return the address of the slot
238 where the type for that number-pair is stored.
239 The number-pair is in TYPENUMS.
241 This can be used for finding the type associated with that pair
242 or for associating a new type with the pair. */
245 dbx_lookup_type (typenums
)
248 register int filenum
= typenums
[0];
249 register int index
= typenums
[1];
251 register int real_filenum
;
252 register struct header_file
*f
;
255 if (filenum
== -1) /* -1,-1 is for temporary types. */
258 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
259 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
260 filenum
, index
, symnum
);
264 /* Type is defined outside of header files.
265 Find it in this object file's type vector. */
266 if (index
>= type_vector_length
)
268 old_len
= type_vector_length
;
271 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
272 type_vector
= (struct type
**)
273 malloc (type_vector_length
* sizeof (struct type
*));
275 while (index
>= type_vector_length
)
277 type_vector_length
*= 2;
279 type_vector
= (struct type
**)
280 xrealloc ((char *) type_vector
,
281 (type_vector_length
* sizeof (struct type
*)));
282 memset (&type_vector
[old_len
], 0,
283 (type_vector_length
- old_len
) * sizeof (struct type
*));
285 return (&type_vector
[index
]);
289 real_filenum
= this_object_header_files
[filenum
];
291 if (real_filenum
>= n_header_files
)
296 f
= &header_files
[real_filenum
];
298 f_orig_length
= f
->length
;
299 if (index
>= f_orig_length
)
301 while (index
>= f
->length
)
305 f
->vector
= (struct type
**)
306 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
307 memset (&f
->vector
[f_orig_length
], 0,
308 (f
->length
- f_orig_length
) * sizeof (struct type
*));
310 return (&f
->vector
[index
]);
314 /* Make sure there is a type allocated for type numbers TYPENUMS
315 and return the type object.
316 This can create an empty (zeroed) type object.
317 TYPENUMS may be (-1, -1) to return a new type object that is not
318 put into the type vector, and so may not be referred to by number. */
321 dbx_alloc_type (typenums
, objfile
)
323 struct objfile
*objfile
;
325 register struct type
**type_addr
;
327 if (typenums
[0] == -1)
329 return (alloc_type (objfile
));
332 type_addr
= dbx_lookup_type (typenums
);
334 /* If we are referring to a type not known at all yet,
335 allocate an empty type for it.
336 We will fill it in later if we find out how. */
339 *type_addr
= alloc_type (objfile
);
345 /* for all the stabs in a given stab vector, build appropriate types
346 and fix their symbols in given symbol vector. */
349 patch_block_stabs (symbols
, stabs
, objfile
)
350 struct pending
*symbols
;
351 struct pending_stabs
*stabs
;
352 struct objfile
*objfile
;
362 /* for all the stab entries, find their corresponding symbols and
363 patch their types! */
365 for (ii
= 0; ii
< stabs
->count
; ++ii
)
367 name
= stabs
->stab
[ii
];
368 pp
= (char*) strchr (name
, ':');
369 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
372 #ifndef IBM6000_TARGET
373 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
379 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
382 lookup_function_type (read_type (&pp
, objfile
));
386 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
394 /* Read a number by which a type is referred to in dbx data,
395 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
396 Just a single number N is equivalent to (0,N).
397 Return the two numbers by storing them in the vector TYPENUMS.
398 TYPENUMS will then be used as an argument to dbx_lookup_type. */
401 read_type_number (pp
, typenums
)
403 register int *typenums
;
408 typenums
[0] = read_number (pp
, ',');
409 typenums
[1] = read_number (pp
, ')');
414 typenums
[1] = read_number (pp
, 0);
419 /* To handle GNU C++ typename abbreviation, we need to be able to
420 fill in a type's name as soon as space for that type is allocated.
421 `type_synonym_name' is the name of the type being allocated.
422 It is cleared as soon as it is used (lest all allocated types
425 static char *type_synonym_name
;
429 define_symbol (valu
, string
, desc
, type
, objfile
)
434 struct objfile
*objfile
;
436 register struct symbol
*sym
;
437 char *p
= (char *) strchr (string
, ':');
441 struct type
*temptype
;
443 /* We would like to eliminate nameless symbols, but keep their types.
444 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
445 to type 2, but, should not create a symbol to address that type. Since
446 the symbol will be nameless, there is no way any user can refer to it. */
450 /* Ignore syms with empty names. */
454 /* Ignore old-style symbols from cc -go */
458 /* If a nameless stab entry, all we need is the type, not the symbol.
459 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
460 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
462 sym
= (struct symbol
*)
463 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
464 memset (sym
, 0, sizeof (struct symbol
));
466 if (processing_gcc_compilation
)
468 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
469 number of bytes occupied by a type or object, which we ignore. */
470 SYMBOL_LINE(sym
) = desc
;
474 SYMBOL_LINE(sym
) = 0; /* unknown */
477 if (string
[0] == CPLUS_MARKER
)
479 /* Special GNU C++ names. */
483 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
484 &objfile
-> symbol_obstack
);
487 case 'v': /* $vtbl_ptr_type */
488 /* Was: SYMBOL_NAME (sym) = "vptr"; */
492 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
493 &objfile
-> symbol_obstack
);
497 /* This was an anonymous type that was never fixed up. */
501 complain (unrecognized_cplus_name_complaint
, string
);
502 goto normal
; /* Do *something* with it */
508 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
509 SYMBOL_NAME (sym
) = (char *)
510 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
511 /* Open-coded bcopy--saves function call time. */
512 /* FIXME: Does it really? Try replacing with simple strcpy and
513 try it on an executable with a large symbol table. */
515 register char *p1
= string
;
516 register char *p2
= SYMBOL_NAME (sym
);
524 /* If this symbol is from a C++ compilation, then attempt to cache the
525 demangled form for future reference. This is a typical time versus
526 space tradeoff, that was decided in favor of time because it sped up
527 C++ symbol lookups by a factor of about 20. */
529 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
533 /* Determine the type of name being defined. */
534 /* The Acorn RISC machine's compiler can put out locals that don't
535 start with "234=" or "(3,4)=", so assume anything other than the
536 deftypes we know how to handle is a local. */
537 if (!strchr ("cfFGpPrStTvVXCR", *p
))
542 /* c is a special case, not followed by a type-number.
543 SYMBOL:c=iVALUE for an integer constant symbol.
544 SYMBOL:c=rVALUE for a floating constant symbol.
545 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
546 e.g. "b:c=e6,0" for "const b = blob1"
547 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
551 error ("Invalid symbol data at symtab pos %d.", symnum
);
559 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
562 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (double));
563 memcpy (dbl_valu
, &d
, sizeof (double));
564 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
565 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
566 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
571 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
573 SYMBOL_VALUE (sym
) = atoi (p
);
574 SYMBOL_CLASS (sym
) = LOC_CONST
;
578 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
579 e.g. "b:c=e6,0" for "const b = blob1"
580 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
584 read_type_number (&p
, typenums
);
586 error ("Invalid symbol data: no comma in enum const symbol");
588 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
589 SYMBOL_VALUE (sym
) = atoi (p
);
590 SYMBOL_CLASS (sym
) = LOC_CONST
;
594 error ("Invalid symbol data at symtab pos %d.", symnum
);
596 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
597 add_symbol_to_list (sym
, &file_symbols
);
601 /* Now usually comes a number that says which data type,
602 and possibly more stuff to define the type
603 (all of which is handled by read_type) */
605 if (deftype
== 'p' && *p
== 'F')
606 /* pF is a two-letter code that means a function parameter in Fortran.
607 The type-number specifies the type of the return value.
608 Translate it into a pointer-to-function type. */
612 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
616 /* The symbol class letter is followed by a type (typically the
617 type of the symbol, or its return-type, or etc). Read it. */
624 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
625 strlen (SYMBOL_NAME (sym
)),
626 &objfile
-> symbol_obstack
);
629 /* Here we save the name of the symbol for read_range_type, which
630 ends up reading in the basic types. In stabs, unfortunately there
631 is no distinction between "int" and "long" types except their
632 names. Until we work out a saner type policy (eliminating most
633 builtin types and using the names specified in the files), we
634 save away the name so that far away from here in read_range_type,
635 we can examine it to decide between "int" and "long". FIXME. */
636 long_kludge_name
= SYMBOL_NAME (sym
);
638 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
644 /* The name of a caught exception. */
645 SYMBOL_CLASS (sym
) = LOC_LABEL
;
646 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
647 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
648 add_symbol_to_list (sym
, &local_symbols
);
652 /* A static function definition. */
653 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
654 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
655 add_symbol_to_list (sym
, &file_symbols
);
656 /* fall into process_function_types. */
658 process_function_types
:
659 /* Function result types are described as the result type in stabs.
660 We need to convert this to the function-returning-type-X type
661 in GDB. E.g. "int" is converted to "function returning int". */
662 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
665 /* This code doesn't work -- it needs to realloc and can't. */
666 /* Attempt to set up to record a function prototype... */
667 struct type
*new = alloc_type (objfile
);
669 /* Generate a template for the type of this function. The
670 types of the arguments will be added as we read the symbol
672 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
673 SYMBOL_TYPE(sym
) = new;
674 TYPE_OBJFILE (new) = objfile
;
675 in_function_type
= new;
677 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
680 /* fall into process_prototype_types */
682 process_prototype_types
:
683 /* Sun acc puts declared types of arguments here. We don't care
684 about their actual types (FIXME -- we should remember the whole
685 function prototype), but the list may define some new types
686 that we have to remember, so we must scan it now. */
689 read_type (&p
, objfile
);
694 /* A global function definition. */
695 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
696 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
697 add_symbol_to_list (sym
, &global_symbols
);
698 goto process_function_types
;
701 /* For a class G (global) symbol, it appears that the
702 value is not correct. It is necessary to search for the
703 corresponding linker definition to find the value.
704 These definitions appear at the end of the namelist. */
705 i
= hashname (SYMBOL_NAME (sym
));
706 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
707 global_sym_chain
[i
] = sym
;
708 SYMBOL_CLASS (sym
) = LOC_STATIC
;
709 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
710 add_symbol_to_list (sym
, &global_symbols
);
713 /* This case is faked by a conditional above,
714 when there is no code letter in the dbx data.
715 Dbx data never actually contains 'l'. */
717 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
718 SYMBOL_VALUE (sym
) = valu
;
719 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
720 add_symbol_to_list (sym
, &local_symbols
);
724 /* Normally this is a parameter, a LOC_ARG. On the i960, it
725 can also be a LOC_LOCAL_ARG depending on symbol type. */
726 #ifndef DBX_PARM_SYMBOL_CLASS
727 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
729 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
730 SYMBOL_VALUE (sym
) = valu
;
731 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
733 /* This doesn't work yet. */
734 add_param_to_type (&in_function_type
, sym
);
736 add_symbol_to_list (sym
, &local_symbols
);
738 /* If it's gcc-compiled, if it says `short', believe it. */
739 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
742 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
743 /* This macro is defined on machines (e.g. sparc) where
744 we should believe the type of a PCC 'short' argument,
745 but shouldn't believe the address (the address is
746 the address of the corresponding int). Note that
747 this is only different from the BELIEVE_PCC_PROMOTION
748 case on big-endian machines.
750 My guess is that this correction, as opposed to changing
751 the parameter to an 'int' (as done below, for PCC
752 on most machines), is the right thing to do
753 on all machines, but I don't want to risk breaking
754 something that already works. On most PCC machines,
755 the sparc problem doesn't come up because the calling
756 function has to zero the top bytes (not knowing whether
757 the called function wants an int or a short), so there
758 is no practical difference between an int and a short
759 (except perhaps what happens when the GDB user types
760 "print short_arg = 0x10000;").
762 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
763 actually produces the correct address (we don't need to fix it
764 up). I made this code adapt so that it will offset the symbol
765 if it was pointing at an int-aligned location and not
766 otherwise. This way you can use the same gdb for 4.0.x and
769 If the parameter is shorter than an int, and is integral
770 (e.g. char, short, or unsigned equivalent), and is claimed to
771 be passed on an integer boundary, don't believe it! Offset the
772 parameter's address to the tail-end of that integer. */
774 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
775 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
776 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
777 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
779 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
780 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
784 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
786 /* If PCC says a parameter is a short or a char,
787 it is really an int. */
788 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
789 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
790 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
792 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
793 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
798 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
801 /* acc seems to use P to delare the prototypes of functions that
802 are referenced by this file. gdb is not prepared to deal
803 with this extra information. FIXME, it ought to. */
805 goto process_prototype_types
;
807 /* Parameter which is in a register. */
808 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
809 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
810 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
812 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
813 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
815 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
816 add_symbol_to_list (sym
, &local_symbols
);
821 /* Register variable (either global or local). */
822 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
823 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
824 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
826 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
827 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
829 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
831 add_symbol_to_list (sym
, &local_symbols
);
833 add_symbol_to_list (sym
, &file_symbols
);
837 /* Static symbol at top level of file */
838 SYMBOL_CLASS (sym
) = LOC_STATIC
;
839 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
840 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
841 add_symbol_to_list (sym
, &file_symbols
);
845 /* For a nameless type, we don't want a create a symbol, thus we
846 did not use `sym'. Return without further processing. */
847 if (nameless
) return NULL
;
849 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
850 SYMBOL_VALUE (sym
) = valu
;
851 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
852 /* C++ vagaries: we may have a type which is derived from
853 a base type which did not have its name defined when the
854 derived class was output. We fill in the derived class's
855 base part member's name here in that case. */
856 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
857 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
858 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
859 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
862 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
863 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
864 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
865 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
868 add_symbol_to_list (sym
, &file_symbols
);
872 /* For a nameless type, we don't want a create a symbol, thus we
873 did not use `sym'. Return without further processing. */
874 if (nameless
) return NULL
;
876 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
877 SYMBOL_VALUE (sym
) = valu
;
878 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
879 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
880 TYPE_NAME (SYMBOL_TYPE (sym
))
881 = obconcat (&objfile
-> type_obstack
, "",
882 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
884 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
885 ? "struct " : "union ")),
887 add_symbol_to_list (sym
, &file_symbols
);
891 /* Clone the sym and then modify it. */
892 register struct symbol
*typedef_sym
= (struct symbol
*)
893 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
895 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
896 SYMBOL_VALUE (typedef_sym
) = valu
;
897 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
898 add_symbol_to_list (typedef_sym
, &file_symbols
);
903 /* Static symbol of local scope */
904 SYMBOL_CLASS (sym
) = LOC_STATIC
;
905 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
906 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
907 add_symbol_to_list (sym
, &local_symbols
);
911 /* Reference parameter */
912 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
913 SYMBOL_VALUE (sym
) = valu
;
914 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
915 add_symbol_to_list (sym
, &local_symbols
);
919 /* This is used by Sun FORTRAN for "function result value".
920 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
921 that Pascal uses it too, but when I tried it Pascal used
922 "x:3" (local symbol) instead. */
923 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
924 SYMBOL_VALUE (sym
) = valu
;
925 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
926 add_symbol_to_list (sym
, &local_symbols
);
930 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
936 /* Skip rest of this symbol and return an error type.
938 General notes on error recovery: error_type always skips to the
939 end of the symbol (modulo cretinous dbx symbol name continuation).
943 return error_type (pp);
945 is wrong because if *pp starts out pointing at '\0' (typically as the
946 result of an earlier error), it will be incremented to point to the
947 start of the next symbol, which might produce strange results, at least
948 if you run off the end of the string table. Instead use
951 return error_type (pp);
957 foo = error_type (pp);
961 And in case it isn't obvious, the point of all this hair is so the compiler
962 can define new types and new syntaxes, and old versions of the
963 debugger will be able to read the new symbol tables. */
969 complain (&error_type_complaint
);
972 /* Skip to end of symbol. */
978 /* Check for and handle cretinous dbx symbol name continuation! */
979 if ((*pp
)[-1] == '\\')
981 *pp
= next_symbol_text ();
988 return (builtin_type_error
);
992 /* Read a dbx type reference or definition;
993 return the type that is meant.
994 This can be just a number, in which case it references
995 a type already defined and placed in type_vector.
996 Or the number can be followed by an =, in which case
997 it means to define a new type according to the text that
1001 read_type (pp
, objfile
)
1003 struct objfile
*objfile
;
1005 register struct type
*type
= 0;
1009 char type_descriptor
;
1011 /* Read type number if present. The type number may be omitted.
1012 for instance in a two-dimensional array declared with type
1013 "ar1;1;10;ar1;1;10;4". */
1014 if ((**pp
>= '0' && **pp
<= '9')
1017 read_type_number (pp
, typenums
);
1019 /* Type is not being defined here. Either it already exists,
1020 or this is a forward reference to it. dbx_alloc_type handles
1023 return dbx_alloc_type (typenums
, objfile
);
1025 /* Type is being defined here. */
1026 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1030 /* if such a type already exists, this is an unnecessary duplication
1031 of the stab string, which is common in (RS/6000) xlc generated
1032 objects. In that case, simply return NULL and let the caller take
1035 tt
= *dbx_lookup_type (typenums
);
1036 if (tt
&& tt
->length
&& tt
->code
)
1045 /* 'typenums=' not present, type is anonymous. Read and return
1046 the definition, but don't put it in the type vector. */
1047 typenums
[0] = typenums
[1] = -1;
1051 type_descriptor
= (*pp
)[-1];
1052 switch (type_descriptor
)
1056 enum type_code code
;
1058 /* Used to index through file_symbols. */
1059 struct pending
*ppt
;
1062 /* Name including "struct", etc. */
1065 /* Name without "struct", etc. */
1066 char *type_name_only
;
1072 /* Set the type code according to the following letter. */
1076 code
= TYPE_CODE_STRUCT
;
1080 code
= TYPE_CODE_UNION
;
1084 code
= TYPE_CODE_ENUM
;
1088 return error_type (pp
);
1091 to
= type_name
= (char *)
1092 obstack_alloc (&objfile
-> type_obstack
,
1094 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1096 /* Copy the prefix. */
1098 while ((*to
++ = *from
++) != '\0')
1102 type_name_only
= to
;
1104 /* Copy the name. */
1106 while ((*to
++ = *from
++) != ':')
1110 /* Set the pointer ahead of the name which we just read. */
1114 /* The following hack is clearly wrong, because it doesn't
1115 check whether we are in a baseclass. I tried to reproduce
1116 the case that it is trying to fix, but I couldn't get
1117 g++ to put out a cross reference to a basetype. Perhaps
1118 it doesn't do it anymore. */
1119 /* Note: for C++, the cross reference may be to a base type which
1120 has not yet been seen. In this case, we skip to the comma,
1121 which will mark the end of the base class name. (The ':'
1122 at the end of the base class name will be skipped as well.)
1123 But sometimes (ie. when the cross ref is the last thing on
1124 the line) there will be no ','. */
1125 from
= (char *) strchr (*pp
, ',');
1131 /* Now check to see whether the type has already been declared. */
1132 /* This is necessary at least in the case where the
1133 program says something like
1135 The compiler puts out a cross-reference; we better find
1136 set the length of the structure correctly so we can
1137 set the length of the array. */
1138 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1139 for (i
= 0; i
< ppt
->nsyms
; i
++)
1141 struct symbol
*sym
= ppt
->symbol
[i
];
1143 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1144 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1145 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1146 && STREQ (SYMBOL_NAME (sym
), type_name_only
))
1148 obstack_free (&objfile
-> type_obstack
, type_name
);
1149 type
= SYMBOL_TYPE (sym
);
1154 /* Didn't find the type to which this refers, so we must
1155 be dealing with a forward reference. Allocate a type
1156 structure for it, and keep track of it so we can
1157 fill in the rest of the fields when we get the full
1159 type
= dbx_alloc_type (typenums
, objfile
);
1160 TYPE_CODE (type
) = code
;
1161 TYPE_NAME (type
) = type_name
;
1162 INIT_CPLUS_SPECIFIC(type
);
1163 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1165 add_undefined_type (type
);
1169 case '-': /* RS/6000 built-in type */
1170 type
= rs6000_builtin_type (pp
);
1185 read_type_number (pp
, xtypenums
);
1186 type
= *dbx_lookup_type (xtypenums
);
1191 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1192 if (typenums
[0] != -1)
1193 *dbx_lookup_type (typenums
) = type
;
1196 /* In the following types, we must be sure to overwrite any existing
1197 type that the typenums refer to, rather than allocating a new one
1198 and making the typenums point to the new one. This is because there
1199 may already be pointers to the existing type (if it had been
1200 forward-referenced), and we must change it to a pointer, function,
1201 reference, or whatever, *in-place*. */
1204 type1
= read_type (pp
, objfile
);
1205 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1208 case '&': /* Reference to another type */
1209 type1
= read_type (pp
, objfile
);
1210 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1213 case 'f': /* Function returning another type */
1214 type1
= read_type (pp
, objfile
);
1215 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1218 case 'k': /* Const qualifier on some type (Sun) */
1219 type
= read_type (pp
, objfile
);
1220 /* FIXME! For now, we ignore const and volatile qualifiers. */
1223 case 'B': /* Volatile qual on some type (Sun) */
1224 type
= read_type (pp
, objfile
);
1225 /* FIXME! For now, we ignore const and volatile qualifiers. */
1228 /* FIXME -- we should be doing smash_to_XXX types here. */
1229 case '@': /* Member (class & variable) type */
1231 struct type
*domain
= read_type (pp
, objfile
);
1232 struct type
*memtype
;
1235 /* Invalid member type data format. */
1236 return error_type (pp
);
1239 memtype
= read_type (pp
, objfile
);
1240 type
= dbx_alloc_type (typenums
, objfile
);
1241 smash_to_member_type (type
, domain
, memtype
);
1245 case '#': /* Method (class & fn) type */
1246 if ((*pp
)[0] == '#')
1248 /* We'll get the parameter types from the name. */
1249 struct type
*return_type
;
1252 return_type
= read_type (pp
, objfile
);
1253 if (*(*pp
)++ != ';')
1254 complain (&invalid_member_complaint
, symnum
);
1255 type
= allocate_stub_method (return_type
);
1256 if (typenums
[0] != -1)
1257 *dbx_lookup_type (typenums
) = type
;
1261 struct type
*domain
= read_type (pp
, objfile
);
1262 struct type
*return_type
;
1265 if (*(*pp
)++ != ',')
1266 error ("invalid member type data format, at symtab pos %d.",
1269 return_type
= read_type (pp
, objfile
);
1270 args
= read_args (pp
, ';', objfile
);
1271 type
= dbx_alloc_type (typenums
, objfile
);
1272 smash_to_method_type (type
, domain
, return_type
, args
);
1276 case 'r': /* Range type */
1277 type
= read_range_type (pp
, typenums
, objfile
);
1278 if (typenums
[0] != -1)
1279 *dbx_lookup_type (typenums
) = type
;
1282 case 'b': /* Sun ACC builtin int type */
1283 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1284 if (typenums
[0] != -1)
1285 *dbx_lookup_type (typenums
) = type
;
1288 case 'R': /* Sun ACC builtin float type */
1289 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1290 if (typenums
[0] != -1)
1291 *dbx_lookup_type (typenums
) = type
;
1294 case 'e': /* Enumeration type */
1295 type
= dbx_alloc_type (typenums
, objfile
);
1296 type
= read_enum_type (pp
, type
, objfile
);
1297 *dbx_lookup_type (typenums
) = type
;
1300 case 's': /* Struct type */
1301 case 'u': /* Union type */
1302 type
= dbx_alloc_type (typenums
, objfile
);
1303 if (!TYPE_NAME (type
))
1305 TYPE_NAME (type
) = type_synonym_name
;
1307 type_synonym_name
= NULL
;
1308 switch (type_descriptor
)
1311 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1314 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1317 type
= read_struct_type (pp
, type
, objfile
);
1320 case 'a': /* Array type */
1322 return error_type (pp
);
1325 type
= dbx_alloc_type (typenums
, objfile
);
1326 type
= read_array_type (pp
, type
, objfile
);
1330 --*pp
; /* Go back to the symbol in error */
1331 /* Particularly important if it was \0! */
1332 return error_type (pp
);
1341 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1342 Return the proper type node for a given builtin type number. */
1344 static struct type
*
1345 rs6000_builtin_type (pp
)
1350 read_type_number (pp
, typenums
);
1352 /* default types are defined in dbxstclass.h. */
1353 switch ( typenums
[1] ) {
1355 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1357 return lookup_fundamental_type (current_objfile
, FT_CHAR
);
1359 return lookup_fundamental_type (current_objfile
, FT_SHORT
);
1361 return lookup_fundamental_type (current_objfile
, FT_LONG
);
1363 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
1365 return lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
1367 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
1369 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1371 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1373 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
1375 return lookup_fundamental_type (current_objfile
, FT_VOID
);
1377 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1379 return lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
1381 return lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
1383 /* requires a builtin `integer' */
1384 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1386 return lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
1388 /* requires builtin `short real' */
1389 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1391 /* requires builtin `real' */
1392 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1394 complain (rs6000_builtin_complaint
, typenums
[1]);
1399 /* This page contains subroutines of read_type. */
1401 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1402 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1403 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1405 /* Read member function stabs info for C++ classes. The form of each member
1408 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1410 An example with two member functions is:
1412 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1414 For the case of overloaded operators, the format is op$::*.funcs, where
1415 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1416 name (such as `+=') and `.' marks the end of the operator name. */
1419 read_member_functions (fip
, pp
, type
, objfile
)
1420 struct field_info
*fip
;
1423 struct objfile
*objfile
;
1427 /* Total number of member functions defined in this class. If the class
1428 defines two `f' functions, and one `g' function, then this will have
1430 int total_length
= 0;
1434 struct next_fnfield
*next
;
1435 struct fn_field fn_field
;
1437 struct type
*look_ahead_type
;
1438 struct next_fnfieldlist
*new_fnlist
;
1439 struct next_fnfield
*new_sublist
;
1443 /* Process each list until we find something that is not a member function
1444 or find the end of the functions. */
1448 /* We should be positioned at the start of the function name.
1449 Scan forward to find the first ':' and if it is not the
1450 first of a "::" delimiter, then this is not a member function. */
1462 look_ahead_type
= NULL
;
1465 new_fnlist
= (struct next_fnfieldlist
*)
1466 xmalloc (sizeof (struct next_fnfieldlist
));
1467 make_cleanup (free
, new_fnlist
);
1468 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1470 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1472 /* This is a completely wierd case. In order to stuff in the
1473 names that might contain colons (the usual name delimiter),
1474 Mike Tiemann defined a different name format which is
1475 signalled if the identifier is "op$". In that case, the
1476 format is "op$::XXXX." where XXXX is the name. This is
1477 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1478 /* This lets the user type "break operator+".
1479 We could just put in "+" as the name, but that wouldn't
1481 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1482 char *o
= opname
+ 3;
1484 /* Skip past '::'. */
1487 STABS_CONTINUE (pp
);
1493 main_fn_name
= savestring (opname
, o
- opname
);
1499 main_fn_name
= savestring (*pp
, p
- *pp
);
1500 /* Skip past '::'. */
1503 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1508 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1509 make_cleanup (free
, new_sublist
);
1510 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1512 /* Check for and handle cretinous dbx symbol name continuation! */
1513 if (look_ahead_type
== NULL
)
1516 STABS_CONTINUE (pp
);
1518 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1521 /* Invalid symtab info for member function. */
1527 /* g++ version 1 kludge */
1528 new_sublist
-> fn_field
.type
= look_ahead_type
;
1529 look_ahead_type
= NULL
;
1539 /* If this is just a stub, then we don't have the real name here. */
1541 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1543 new_sublist
-> fn_field
.is_stub
= 1;
1545 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1548 /* Set this member function's visibility fields. */
1551 case VISIBILITY_PRIVATE
:
1552 new_sublist
-> fn_field
.is_private
= 1;
1554 case VISIBILITY_PROTECTED
:
1555 new_sublist
-> fn_field
.is_protected
= 1;
1559 STABS_CONTINUE (pp
);
1562 case 'A': /* Normal functions. */
1563 new_sublist
-> fn_field
.is_const
= 0;
1564 new_sublist
-> fn_field
.is_volatile
= 0;
1567 case 'B': /* `const' member functions. */
1568 new_sublist
-> fn_field
.is_const
= 1;
1569 new_sublist
-> fn_field
.is_volatile
= 0;
1572 case 'C': /* `volatile' member function. */
1573 new_sublist
-> fn_field
.is_const
= 0;
1574 new_sublist
-> fn_field
.is_volatile
= 1;
1577 case 'D': /* `const volatile' member function. */
1578 new_sublist
-> fn_field
.is_const
= 1;
1579 new_sublist
-> fn_field
.is_volatile
= 1;
1582 case '*': /* File compiled with g++ version 1 -- no info */
1587 complain (&const_vol_complaint
, **pp
);
1594 /* virtual member function, followed by index.
1595 The sign bit is set to distinguish pointers-to-methods
1596 from virtual function indicies. Since the array is
1597 in words, the quantity must be shifted left by 1
1598 on 16 bit machine, and by 2 on 32 bit machine, forcing
1599 the sign bit out, and usable as a valid index into
1600 the array. Remove the sign bit here. */
1601 new_sublist
-> fn_field
.voffset
=
1602 (0x7fffffff & read_number (pp
, ';')) + 2;
1604 STABS_CONTINUE (pp
);
1605 if (**pp
== ';' || **pp
== '\0')
1607 /* Must be g++ version 1. */
1608 new_sublist
-> fn_field
.fcontext
= 0;
1612 /* Figure out from whence this virtual function came.
1613 It may belong to virtual function table of
1614 one of its baseclasses. */
1615 look_ahead_type
= read_type (pp
, objfile
);
1618 /* g++ version 1 overloaded methods. */
1622 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1631 look_ahead_type
= NULL
;
1637 /* static member function. */
1638 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
1639 if (strncmp (new_sublist
-> fn_field
.physname
,
1640 main_fn_name
, strlen (main_fn_name
)))
1642 new_sublist
-> fn_field
.is_stub
= 1;
1648 complain (&member_fn_complaint
, (*pp
)[-1]);
1649 /* Fall through into normal member function. */
1652 /* normal member function. */
1653 new_sublist
-> fn_field
.voffset
= 0;
1654 new_sublist
-> fn_field
.fcontext
= 0;
1658 new_sublist
-> next
= sublist
;
1659 sublist
= new_sublist
;
1661 STABS_CONTINUE (pp
);
1663 while (**pp
!= ';' && **pp
!= '\0');
1667 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
1668 obstack_alloc (&objfile
-> type_obstack
,
1669 sizeof (struct fn_field
) * length
);
1670 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
1671 sizeof (struct fn_field
) * length
);
1672 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
1674 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
1677 new_fnlist
-> fn_fieldlist
.length
= length
;
1678 new_fnlist
-> next
= fip
-> fnlist
;
1679 fip
-> fnlist
= new_fnlist
;
1681 total_length
+= length
;
1682 STABS_CONTINUE (pp
);
1687 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1688 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
1689 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
1690 memset (TYPE_FN_FIELDLISTS (type
), 0,
1691 sizeof (struct fn_fieldlist
) * nfn_fields
);
1692 TYPE_NFN_FIELDS (type
) = nfn_fields
;
1693 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
1699 /* Special GNU C++ name.
1700 FIXME: Still need to properly handle parse error conditions. */
1703 read_cpp_abbrev (fip
, pp
, type
, objfile
)
1704 struct field_info
*fip
;
1707 struct objfile
*objfile
;
1713 struct type
*context
;
1723 /* At this point, *pp points to something like "22:23=*22...",
1724 where the type number before the ':' is the "context" and
1725 everything after is a regular type definition. Lookup the
1726 type, find it's name, and construct the field name. */
1728 context
= read_type (pp
, objfile
);
1732 case 'f': /* $vf -- a virtual function table pointer */
1733 fip
->list
->field
.name
=
1734 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
1737 case 'b': /* $vb -- a virtual bsomethingorother */
1738 name
= type_name_no_tag (context
);
1741 complain (&invalid_cpp_type_complaint
, symnum
);
1744 fip
->list
->field
.name
=
1745 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
1749 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1750 fip
->list
->field
.name
=
1751 obconcat (&objfile
->type_obstack
,
1752 "INVALID_CPLUSPLUS_ABBREV", "", "");
1756 /* At this point, *pp points to the ':'. Skip it and read the
1762 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1764 fip
->list
->field
.type
= read_type (pp
, objfile
);
1765 (*pp
)++; /* Skip the comma. */
1766 fip
->list
->field
.bitpos
= read_number (pp
, ';');
1767 /* This field is unpacked. */
1768 fip
->list
->field
.bitsize
= 0;
1769 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
1773 /* GNU C++ anonymous type. */
1774 complain (&stabs_general_complaint
, "g++ anonymous type $_ not handled");
1778 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1783 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
1784 struct field_info
*fip
;
1788 struct objfile
*objfile
;
1790 fip
-> list
-> field
.name
=
1791 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
1794 /* This means we have a visibility for a field coming. */
1798 fip
-> list
-> visibility
= *(*pp
)++;
1799 switch (fip
-> list
-> visibility
)
1801 case VISIBILITY_PRIVATE
:
1802 case VISIBILITY_PROTECTED
:
1805 case VISIBILITY_PUBLIC
:
1810 /* Unknown visibility specifier. */
1811 complain (&stabs_general_complaint
,
1812 "unknown visibility specifier");
1819 /* normal dbx-style format, no explicit visibility */
1820 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
1823 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
1828 /* Possible future hook for nested types. */
1831 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
1837 /* Static class member. */
1838 fip
-> list
-> field
.bitpos
= (long) -1;
1844 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
1848 else if (**pp
!= ',')
1850 /* Bad structure-type format. */
1851 complain (&stabs_general_complaint
, "bad structure-type format");
1855 (*pp
)++; /* Skip the comma. */
1856 fip
-> list
-> field
.bitpos
= read_number (pp
, ',');
1857 fip
-> list
-> field
.bitsize
= read_number (pp
, ';');
1860 /* FIXME-tiemann: Can't the compiler put out something which
1861 lets us distinguish these? (or maybe just not put out anything
1862 for the field). What is the story here? What does the compiler
1863 really do? Also, patch gdb.texinfo for this case; I document
1864 it as a possible problem there. Search for "DBX-style". */
1866 /* This is wrong because this is identical to the symbols
1867 produced for GCC 0-size arrays. For example:
1872 The code which dumped core in such circumstances should be
1873 fixed not to dump core. */
1875 /* g++ -g0 can put out bitpos & bitsize zero for a static
1876 field. This does not give us any way of getting its
1877 class, so we can't know its name. But we can just
1878 ignore the field so we don't dump core and other nasty
1880 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
1882 complain (&dbx_class_complaint
);
1883 /* Ignore this field. */
1884 fip
-> list
= fip
-> list
-> next
;
1889 /* Detect an unpacked field and mark it as such.
1890 dbx gives a bit size for all fields.
1891 Note that forward refs cannot be packed,
1892 and treat enums as if they had the width of ints. */
1894 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
1895 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
1897 fip
-> list
-> field
.bitsize
= 0;
1899 if ((fip
-> list
-> field
.bitsize
1900 == 8 * TYPE_LENGTH (fip
-> list
-> field
.type
)
1901 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
1902 && (fip
-> list
-> field
.bitsize
1903 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
1907 fip
-> list
-> field
.bitpos
% 8 == 0)
1909 fip
-> list
-> field
.bitsize
= 0;
1915 /* Read struct or class data fields. They have the form:
1917 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
1919 At the end, we see a semicolon instead of a field.
1921 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1924 The optional VISIBILITY is one of:
1926 '/0' (VISIBILITY_PRIVATE)
1927 '/1' (VISIBILITY_PROTECTED)
1928 '/2' (VISIBILITY_PUBLIC)
1930 or nothing, for C style fields with public visibility. */
1933 read_struct_fields (fip
, pp
, type
, objfile
)
1934 struct field_info
*fip
;
1937 struct objfile
*objfile
;
1940 struct nextfield
*new;
1942 /* We better set p right now, in case there are no fields at all... */
1946 /* Read each data member type until we find the terminating ';' at the end of
1947 the data member list, or break for some other reason such as finding the
1948 start of the member function list. */
1952 STABS_CONTINUE (pp
);
1953 /* Get space to record the next field's data. */
1954 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1955 make_cleanup (free
, new);
1956 memset (new, 0, sizeof (struct nextfield
));
1957 new -> next
= fip
-> list
;
1960 /* Get the field name. */
1962 if (*p
== CPLUS_MARKER
)
1964 read_cpp_abbrev (fip
, pp
, type
, objfile
);
1968 /* Look for the ':' that separates the field name from the field
1969 values. Data members are delimited by a single ':', while member
1970 functions are delimited by a pair of ':'s. When we hit the member
1971 functions (if any), terminate scan loop and return. */
1978 /* Check to see if we have hit the member functions yet. */
1983 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
1987 /* chill the list of fields: the last entry (at the head) is a
1988 partially constructed entry which we now scrub. */
1989 fip
-> list
= fip
-> list
-> next
;
1994 /* The stabs for C++ derived classes contain baseclass information which
1995 is marked by a '!' character after the total size. This function is
1996 called when we encounter the baseclass marker, and slurps up all the
1997 baseclass information.
1999 Immediately following the '!' marker is the number of base classes that
2000 the class is derived from, followed by information for each base class.
2001 For each base class, there are two visibility specifiers, a bit offset
2002 to the base class information within the derived class, a reference to
2003 the type for the base class, and a terminating semicolon.
2005 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2007 Baseclass information marker __________________|| | | | | | |
2008 Number of baseclasses __________________________| | | | | | |
2009 Visibility specifiers (2) ________________________| | | | | |
2010 Offset in bits from start of class _________________| | | | |
2011 Type number for base class ___________________________| | | |
2012 Visibility specifiers (2) _______________________________| | |
2013 Offset in bits from start of class ________________________| |
2014 Type number of base class ____________________________________|
2018 read_baseclasses (fip
, pp
, type
, objfile
)
2019 struct field_info
*fip
;
2022 struct objfile
*objfile
;
2025 struct nextfield
*new;
2033 /* Skip the '!' baseclass information marker. */
2037 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2038 TYPE_N_BASECLASSES (type
) = read_number (pp
, ',');
2041 /* Some stupid compilers have trouble with the following, so break
2042 it up into simpler expressions. */
2043 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2044 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2047 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2050 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2051 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2055 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2057 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2059 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2060 make_cleanup (free
, new);
2061 memset (new, 0, sizeof (struct nextfield
));
2062 new -> next
= fip
-> list
;
2064 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2066 STABS_CONTINUE (pp
);
2070 /* Nothing to do. */
2073 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2076 /* Bad visibility format. */
2080 new -> visibility
= *(*pp
)++;
2081 switch (new -> visibility
)
2083 case VISIBILITY_PRIVATE
:
2084 case VISIBILITY_PROTECTED
:
2085 case VISIBILITY_PUBLIC
:
2088 /* Bad visibility format. */
2092 /* The remaining value is the bit offset of the portion of the object
2093 corresponding to this baseclass. Always zero in the absence of
2094 multiple inheritance. */
2096 new -> field
.bitpos
= read_number (pp
, ',');
2098 /* The last piece of baseclass information is the type of the base
2099 class. Read it, and remember it's type name as this field's name. */
2101 new -> field
.type
= read_type (pp
, objfile
);
2102 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2104 /* skip trailing ';' and bump count of number of fields seen */
2110 /* The tail end of stabs for C++ classes that contain a virtual function
2111 pointer contains a tilde, a %, and a type number.
2112 The type number refers to the base class (possibly this class itself) which
2113 contains the vtable pointer for the current class.
2115 This function is called when we have parsed all the method declarations,
2116 so we can look for the vptr base class info. */
2119 read_tilde_fields (fip
, pp
, type
, objfile
)
2120 struct field_info
*fip
;
2123 struct objfile
*objfile
;
2127 STABS_CONTINUE (pp
);
2129 /* If we are positioned at a ';', then skip it. */
2139 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2141 /* Obsolete flags that used to indicate the presence
2142 of constructors and/or destructors. */
2146 /* Read either a '%' or the final ';'. */
2147 if (*(*pp
)++ == '%')
2149 /* The next number is the type number of the base class
2150 (possibly our own class) which supplies the vtable for
2151 this class. Parse it out, and search that class to find
2152 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2153 and TYPE_VPTR_FIELDNO. */
2158 t
= read_type (pp
, objfile
);
2160 while (*p
!= '\0' && *p
!= ';')
2166 /* Premature end of symbol. */
2170 TYPE_VPTR_BASETYPE (type
) = t
;
2171 if (type
== t
) /* Our own class provides vtbl ptr */
2173 for (i
= TYPE_NFIELDS (t
) - 1;
2174 i
>= TYPE_N_BASECLASSES (t
);
2177 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2178 sizeof (vptr_name
) - 1))
2180 TYPE_VPTR_FIELDNO (type
) = i
;
2184 /* Virtual function table field not found. */
2185 complain (vtbl_notfound_complaint
, TYPE_NAME (type
));
2190 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2201 attach_fn_fields_to_type (fip
, type
)
2202 struct field_info
*fip
;
2203 register struct type
*type
;
2207 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2209 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2211 /* @@ Memory leak on objfile -> type_obstack? */
2214 TYPE_NFN_FIELDS_TOTAL (type
) +=
2215 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2218 for (n
= TYPE_NFN_FIELDS (type
);
2219 fip
-> fnlist
!= NULL
;
2220 fip
-> fnlist
= fip
-> fnlist
-> next
)
2222 --n
; /* Circumvent Sun3 compiler bug */
2223 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2228 /* Create the vector of fields, and record how big it is.
2229 We need this info to record proper virtual function table information
2230 for this class's virtual functions. */
2233 attach_fields_to_type (fip
, type
, objfile
)
2234 struct field_info
*fip
;
2235 register struct type
*type
;
2236 struct objfile
*objfile
;
2238 register int nfields
= 0;
2239 register int non_public_fields
= 0;
2240 register struct nextfield
*scan
;
2242 /* Count up the number of fields that we have, as well as taking note of
2243 whether or not there are any non-public fields, which requires us to
2244 allocate and build the private_field_bits and protected_field_bits
2247 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2250 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2252 non_public_fields
++;
2256 /* Now we know how many fields there are, and whether or not there are any
2257 non-public fields. Record the field count, allocate space for the
2258 array of fields, and create blank visibility bitfields if necessary. */
2260 TYPE_NFIELDS (type
) = nfields
;
2261 TYPE_FIELDS (type
) = (struct field
*)
2262 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2263 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2265 if (non_public_fields
)
2267 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2269 TYPE_FIELD_PRIVATE_BITS (type
) =
2270 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2271 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2273 TYPE_FIELD_PROTECTED_BITS (type
) =
2274 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2275 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2278 /* Copy the saved-up fields into the field vector. Start from the head
2279 of the list, adding to the tail of the field array, so that they end
2280 up in the same order in the array in which they were added to the list. */
2282 while (nfields
-- > 0)
2284 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2285 switch (fip
-> list
-> visibility
)
2287 case VISIBILITY_PRIVATE
:
2288 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2291 case VISIBILITY_PROTECTED
:
2292 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2295 case VISIBILITY_PUBLIC
:
2299 /* Should warn about this unknown visibility? */
2302 fip
-> list
= fip
-> list
-> next
;
2307 /* Read the description of a structure (or union type) and return an object
2308 describing the type.
2310 PP points to a character pointer that points to the next unconsumed token
2311 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2312 *PP will point to "4a:1,0,32;;".
2314 TYPE points to an incomplete type that needs to be filled in.
2316 OBJFILE points to the current objfile from which the stabs information is
2317 being read. (Note that it is redundant in that TYPE also contains a pointer
2318 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2321 static struct type
*
2322 read_struct_type (pp
, type
, objfile
)
2325 struct objfile
*objfile
;
2327 struct cleanup
*back_to
;
2328 struct field_info fi
;
2333 back_to
= make_cleanup (null_cleanup
, 0);
2335 INIT_CPLUS_SPECIFIC (type
);
2336 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2338 /* First comes the total size in bytes. */
2340 TYPE_LENGTH (type
) = read_number (pp
, 0);
2342 /* Now read the baseclasses, if any, read the regular C struct or C++
2343 class member fields, attach the fields to the type, read the C++
2344 member functions, attach them to the type, and then read any tilde
2345 field (baseclass specifier for the class holding the main vtable). */
2347 if (!read_baseclasses (&fi
, pp
, type
, objfile
))
2349 do_cleanups (back_to
);
2350 return (error_type (pp
));
2352 if (!read_struct_fields (&fi
, pp
, type
, objfile
))
2354 do_cleanups (back_to
);
2355 return (error_type (pp
));
2357 if (!attach_fields_to_type (&fi
, type
, objfile
))
2359 do_cleanups (back_to
);
2360 return (error_type (pp
));
2362 if (!read_member_functions (&fi
, pp
, type
, objfile
))
2364 do_cleanups (back_to
);
2365 return (error_type (pp
));
2367 if (!attach_fn_fields_to_type (&fi
, type
))
2369 do_cleanups (back_to
);
2370 return (error_type (pp
));
2372 if (!read_tilde_fields (&fi
, pp
, type
, objfile
))
2374 do_cleanups (back_to
);
2375 return (error_type (pp
));
2378 do_cleanups (back_to
);
2382 /* Read a definition of an array type,
2383 and create and return a suitable type object.
2384 Also creates a range type which represents the bounds of that
2387 static struct type
*
2388 read_array_type (pp
, type
, objfile
)
2390 register struct type
*type
;
2391 struct objfile
*objfile
;
2393 struct type
*index_type
, *element_type
, *range_type
;
2397 /* Format of an array type:
2398 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2401 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2402 for these, produce a type like float[][]. */
2404 index_type
= read_type (pp
, objfile
);
2406 /* Improper format of array type decl. */
2407 return error_type (pp
);
2410 if (!(**pp
>= '0' && **pp
<= '9'))
2415 lower
= read_number (pp
, ';');
2417 if (!(**pp
>= '0' && **pp
<= '9'))
2422 upper
= read_number (pp
, ';');
2424 element_type
= read_type (pp
, objfile
);
2433 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2434 type
= create_array_type (type
, element_type
, range_type
);
2436 /* If we have an array whose element type is not yet known, but whose
2437 bounds *are* known, record it to be adjusted at the end of the file. */
2439 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2441 add_undefined_type (type
);
2448 /* Read a definition of an enumeration type,
2449 and create and return a suitable type object.
2450 Also defines the symbols that represent the values of the type. */
2452 static struct type
*
2453 read_enum_type (pp
, type
, objfile
)
2455 register struct type
*type
;
2456 struct objfile
*objfile
;
2461 register struct symbol
*sym
;
2463 struct pending
**symlist
;
2464 struct pending
*osyms
, *syms
;
2468 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2469 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2470 to do? For now, force all enum values to file scope. */
2471 if (within_function
)
2472 symlist
= &local_symbols
;
2475 symlist
= &file_symbols
;
2477 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2479 /* Read the value-names and their values.
2480 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2481 A semicolon or comma instead of a NAME means the end. */
2482 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2484 STABS_CONTINUE (pp
);
2486 while (*p
!= ':') p
++;
2487 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2489 n
= read_number (pp
, ',');
2491 sym
= (struct symbol
*)
2492 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2493 memset (sym
, 0, sizeof (struct symbol
));
2494 SYMBOL_NAME (sym
) = name
;
2495 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
2496 SYMBOL_CLASS (sym
) = LOC_CONST
;
2497 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2498 SYMBOL_VALUE (sym
) = n
;
2499 add_symbol_to_list (sym
, symlist
);
2504 (*pp
)++; /* Skip the semicolon. */
2506 /* Now fill in the fields of the type-structure. */
2508 TYPE_LENGTH (type
) = sizeof (int);
2509 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2510 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2511 TYPE_NFIELDS (type
) = nsyms
;
2512 TYPE_FIELDS (type
) = (struct field
*)
2513 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2514 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2516 /* Find the symbols for the values and put them into the type.
2517 The symbols can be found in the symlist that we put them on
2518 to cause them to be defined. osyms contains the old value
2519 of that symlist; everything up to there was defined by us. */
2520 /* Note that we preserve the order of the enum constants, so
2521 that in something like "enum {FOO, LAST_THING=FOO}" we print
2522 FOO, not LAST_THING. */
2524 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2529 for (; j
< syms
->nsyms
; j
++,n
++)
2531 struct symbol
*xsym
= syms
->symbol
[j
];
2532 SYMBOL_TYPE (xsym
) = type
;
2533 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2534 TYPE_FIELD_VALUE (type
, n
) = 0;
2535 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2536 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2543 /* This screws up perfectly good C programs with enums. FIXME. */
2544 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2545 if(TYPE_NFIELDS(type
) == 2 &&
2546 ((STREQ(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2547 STREQ(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2548 (STREQ(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2549 STREQ(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2550 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2556 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2557 typedefs in every file (for int, long, etc):
2559 type = b <signed> <width>; <offset>; <nbits>
2560 signed = u or s. Possible c in addition to u or s (for char?).
2561 offset = offset from high order bit to start bit of type.
2562 width is # bytes in object of this type, nbits is # bits in type.
2564 The width/offset stuff appears to be for small objects stored in
2565 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2568 static struct type
*
2569 read_sun_builtin_type (pp
, typenums
, objfile
)
2572 struct objfile
*objfile
;
2586 return error_type (pp
);
2590 /* For some odd reason, all forms of char put a c here. This is strange
2591 because no other type has this honor. We can safely ignore this because
2592 we actually determine 'char'acterness by the number of bits specified in
2598 /* The first number appears to be the number of bytes occupied
2599 by this type, except that unsigned short is 4 instead of 2.
2600 Since this information is redundant with the third number,
2601 we will ignore it. */
2602 read_number (pp
, ';');
2604 /* The second number is always 0, so ignore it too. */
2605 read_number (pp
, ';');
2607 /* The third number is the number of bits for this type. */
2608 nbits
= read_number (pp
, 0);
2610 /* FIXME. Here we should just be able to make a type of the right
2611 number of bits and signedness. FIXME. */
2613 if (nbits
== TARGET_LONG_LONG_BIT
)
2614 return (lookup_fundamental_type (objfile
,
2615 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
2617 if (nbits
== TARGET_INT_BIT
)
2619 /* FIXME -- the only way to distinguish `int' from `long'
2620 is to look at its name! */
2623 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2624 return lookup_fundamental_type (objfile
, FT_LONG
);
2626 return lookup_fundamental_type (objfile
, FT_INTEGER
);
2630 if (long_kludge_name
2631 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2632 long_kludge_name
[9] == 'l' /* long */)
2633 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2634 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
2636 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
2640 if (nbits
== TARGET_SHORT_BIT
)
2641 return (lookup_fundamental_type (objfile
,
2642 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
2644 if (nbits
== TARGET_CHAR_BIT
)
2645 return (lookup_fundamental_type (objfile
,
2646 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
2649 return lookup_fundamental_type (objfile
, FT_VOID
);
2651 return error_type (pp
);
2654 static struct type
*
2655 read_sun_floating_type (pp
, typenums
, objfile
)
2658 struct objfile
*objfile
;
2662 /* The first number has more details about the type, for example
2663 FN_COMPLEX. See the sun stab.h. */
2664 read_number (pp
, ';');
2666 /* The second number is the number of bytes occupied by this type */
2667 nbytes
= read_number (pp
, ';');
2670 return error_type (pp
);
2672 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
2673 return lookup_fundamental_type (objfile
, FT_FLOAT
);
2675 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2676 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
2678 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2679 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
2681 return error_type (pp
);
2684 /* Read a number from the string pointed to by *PP.
2685 The value of *PP is advanced over the number.
2686 If END is nonzero, the character that ends the
2687 number must match END, or an error happens;
2688 and that character is skipped if it does match.
2689 If END is zero, *PP is left pointing to that character.
2691 If the number fits in a long, set *VALUE and set *BITS to 0.
2692 If not, set *BITS to be the number of bits in the number.
2694 If encounter garbage, set *BITS to -1. */
2697 read_huge_number (pp
, end
, valu
, bits
)
2718 /* Leading zero means octal. GCC uses this to output values larger
2719 than an int (because that would be hard in decimal). */
2726 upper_limit
= LONG_MAX
/ radix
;
2727 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2729 if (n
<= upper_limit
)
2732 n
+= c
- '0'; /* FIXME this overflows anyway */
2737 /* This depends on large values being output in octal, which is
2744 /* Ignore leading zeroes. */
2748 else if (c
== '2' || c
== '3')
2774 /* Large decimal constants are an error (because it is hard to
2775 count how many bits are in them). */
2781 /* -0x7f is the same as 0x80. So deal with it by adding one to
2782 the number of bits. */
2797 static struct type
*
2798 read_range_type (pp
, typenums
, objfile
)
2801 struct objfile
*objfile
;
2807 struct type
*result_type
;
2808 struct type
*index_type
;
2810 /* First comes a type we are a subrange of.
2811 In C it is usually 0, 1 or the type being defined. */
2812 read_type_number (pp
, rangenums
);
2813 self_subrange
= (rangenums
[0] == typenums
[0] &&
2814 rangenums
[1] == typenums
[1]);
2816 /* A semicolon should now follow; skip it. */
2820 /* The remaining two operands are usually lower and upper bounds
2821 of the range. But in some special cases they mean something else. */
2822 read_huge_number (pp
, ';', &n2
, &n2bits
);
2823 read_huge_number (pp
, ';', &n3
, &n3bits
);
2825 if (n2bits
== -1 || n3bits
== -1)
2826 return error_type (pp
);
2828 /* If limits are huge, must be large integral type. */
2829 if (n2bits
!= 0 || n3bits
!= 0)
2831 char got_signed
= 0;
2832 char got_unsigned
= 0;
2833 /* Number of bits in the type. */
2836 /* Range from 0 to <large number> is an unsigned large integral type. */
2837 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2842 /* Range from <large number> to <large number>-1 is a large signed
2844 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2850 /* Check for "long long". */
2851 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2852 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2853 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2854 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2856 if (got_signed
|| got_unsigned
)
2858 result_type
= alloc_type (objfile
);
2859 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2860 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2862 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2866 return error_type (pp
);
2869 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2870 if (self_subrange
&& n2
== 0 && n3
== 0)
2871 return (lookup_fundamental_type (objfile
, FT_VOID
));
2873 /* If n3 is zero and n2 is not, we want a floating type,
2874 and n2 is the width in bytes.
2876 Fortran programs appear to use this for complex types also,
2877 and they give no way to distinguish between double and single-complex!
2878 We don't have complex types, so we would lose on all fortran files!
2879 So return type `double' for all of those. It won't work right
2880 for the complex values, but at least it makes the file loadable.
2882 FIXME, we may be able to distinguish these by their names. FIXME. */
2884 if (n3
== 0 && n2
> 0)
2886 if (n2
== sizeof (float))
2887 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
2888 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
2891 /* If the upper bound is -1, it must really be an unsigned int. */
2893 else if (n2
== 0 && n3
== -1)
2895 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2896 long' is to look at its name! */
2898 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2899 long_kludge_name
[9] == 'l' /* long */)
2900 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2901 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2903 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2906 /* Special case: char is defined (Who knows why) as a subrange of
2907 itself with range 0-127. */
2908 else if (self_subrange
&& n2
== 0 && n3
== 127)
2909 return (lookup_fundamental_type (objfile
, FT_CHAR
));
2911 /* Assumptions made here: Subrange of self is equivalent to subrange
2912 of int. FIXME: Host and target type-sizes assumed the same. */
2913 /* FIXME: This is the *only* place in GDB that depends on comparing
2914 some type to a builtin type with ==. Fix it! */
2916 && (self_subrange
||
2917 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
2919 /* an unsigned type */
2921 if (n3
== - sizeof (long long))
2922 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2924 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2925 long' is to look at its name! */
2926 if (n3
== (unsigned long)~0L &&
2927 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2928 long_kludge_name
[9] == 'l' /* long */)
2929 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2930 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2931 if (n3
== (unsigned int)~0L)
2932 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2933 if (n3
== (unsigned short)~0L)
2934 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
2935 if (n3
== (unsigned char)~0L)
2936 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
2939 else if (n3
== 0 && n2
== -sizeof (long long))
2940 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2942 else if (n2
== -n3
-1)
2945 /* FIXME -- the only way to distinguish `int' from `long' is to look
2947 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2948 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2949 return (lookup_fundamental_type (objfile
, FT_LONG
));
2950 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2951 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
2952 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
2953 return (lookup_fundamental_type (objfile
, FT_SHORT
));
2954 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
2955 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
2958 /* We have a real range type on our hands. Allocate space and
2959 return a real pointer. */
2961 /* At this point I don't have the faintest idea how to deal with
2962 a self_subrange type; I'm going to assume that this is used
2963 as an idiom, and that all of them are special cases. So . . . */
2965 return error_type (pp
);
2967 index_type
= *dbx_lookup_type (rangenums
);
2968 if (index_type
== NULL
)
2970 complain (&range_type_base_complaint
, rangenums
[1]);
2971 index_type
= lookup_fundamental_type (objfile
, FT_INTEGER
);
2974 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
2975 return (result_type
);
2978 /* Read a number from the string pointed to by *PP.
2979 The value of *PP is advanced over the number.
2980 If END is nonzero, the character that ends the
2981 number must match END, or an error happens;
2982 and that character is skipped if it does match.
2983 If END is zero, *PP is left pointing to that character. */
2986 read_number (pp
, end
)
2990 register char *p
= *pp
;
2991 register long n
= 0;
2995 /* Handle an optional leading minus sign. */
3003 /* Read the digits, as far as they go. */
3005 while ((c
= *p
++) >= '0' && c
<= '9')
3013 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3022 /* Read in an argument list. This is a list of types, separated by commas
3023 and terminated with END. Return the list of types read in, or (struct type
3024 **)-1 if there is an error. */
3026 static struct type
**
3027 read_args (pp
, end
, objfile
)
3030 struct objfile
*objfile
;
3032 /* FIXME! Remove this arbitrary limit! */
3033 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3039 /* Invalid argument list: no ','. */
3040 return (struct type
**)-1;
3042 STABS_CONTINUE (pp
);
3043 types
[n
++] = read_type (pp
, objfile
);
3045 (*pp
)++; /* get past `end' (the ':' character) */
3049 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3051 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3053 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3054 memset (rval
+ n
, 0, sizeof (struct type
*));
3058 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3060 memcpy (rval
, types
, n
* sizeof (struct type
*));
3064 /* Add a common block's start address to the offset of each symbol
3065 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3066 the common block name). */
3069 fix_common_block (sym
, valu
)
3073 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3074 for ( ; next
; next
= next
->next
)
3077 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3078 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3084 /* What about types defined as forward references inside of a small lexical
3086 /* Add a type to the list of undefined types to be checked through
3087 once this file has been read in. */
3090 add_undefined_type (type
)
3093 if (undef_types_length
== undef_types_allocated
)
3095 undef_types_allocated
*= 2;
3096 undef_types
= (struct type
**)
3097 xrealloc ((char *) undef_types
,
3098 undef_types_allocated
* sizeof (struct type
*));
3100 undef_types
[undef_types_length
++] = type
;
3103 /* Go through each undefined type, see if it's still undefined, and fix it
3104 up if possible. We have two kinds of undefined types:
3106 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3107 Fix: update array length using the element bounds
3108 and the target type's length.
3109 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3110 yet defined at the time a pointer to it was made.
3111 Fix: Do a full lookup on the struct/union tag. */
3113 cleanup_undefined_types ()
3117 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3119 switch (TYPE_CODE (*type
))
3122 case TYPE_CODE_STRUCT
:
3123 case TYPE_CODE_UNION
:
3124 case TYPE_CODE_ENUM
:
3126 /* Check if it has been defined since. */
3127 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3129 struct pending
*ppt
;
3131 /* Name of the type, without "struct" or "union" */
3132 char *typename
= TYPE_NAME (*type
);
3134 if (!strncmp (typename
, "struct ", 7))
3136 if (!strncmp (typename
, "union ", 6))
3138 if (!strncmp (typename
, "enum ", 5))
3141 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3143 for (i
= 0; i
< ppt
->nsyms
; i
++)
3145 struct symbol
*sym
= ppt
->symbol
[i
];
3147 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3148 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3149 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3151 && STREQ (SYMBOL_NAME (sym
), typename
))
3153 memcpy (*type
, SYMBOL_TYPE (sym
),
3154 sizeof (struct type
));
3162 case TYPE_CODE_ARRAY
:
3164 struct type
*range_type
;
3167 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3169 if (TYPE_NFIELDS (*type
) != 1)
3171 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3172 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3175 /* Now recompute the length of the array type, based on its
3176 number of elements and the target type's length. */
3177 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3178 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3179 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3180 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3186 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type
));
3190 undef_types_length
= 0;
3193 /* Scan through all of the global symbols defined in the object file,
3194 assigning values to the debugging symbols that need to be assigned
3195 to. Get these symbols from the minimal symbol table. */
3198 scan_file_globals (objfile
)
3199 struct objfile
*objfile
;
3202 struct minimal_symbol
*msymbol
;
3203 struct symbol
*sym
, *prev
;
3205 if (objfile
->msymbols
== 0) /* Beware the null file. */
3208 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3214 /* Get the hash index and check all the symbols
3215 under that hash index. */
3217 hash
= hashname (SYMBOL_NAME (msymbol
));
3219 for (sym
= global_sym_chain
[hash
]; sym
;)
3221 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3222 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3224 /* Splice this symbol out of the hash chain and
3225 assign the value we have to it. */
3228 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3232 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3235 /* Check to see whether we need to fix up a common block. */
3236 /* Note: this code might be executed several times for
3237 the same symbol if there are multiple references. */
3239 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3241 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3245 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3250 sym
= SYMBOL_VALUE_CHAIN (prev
);
3254 sym
= global_sym_chain
[hash
];
3260 sym
= SYMBOL_VALUE_CHAIN (sym
);
3266 /* Initialize anything that needs initializing when starting to read
3267 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3275 /* Initialize anything that needs initializing when a completely new
3276 symbol file is specified (not just adding some symbols from another
3277 file, e.g. a shared library). */
3280 stabsread_new_init ()
3282 /* Empty the hash table of global syms looking for values. */
3283 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3286 /* Initialize anything that needs initializing at the same time as
3287 start_symtab() is called. */
3291 global_stabs
= NULL
; /* AIX COFF */
3292 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3293 n_this_object_header_files
= 1;
3294 type_vector_length
= 0;
3295 type_vector
= (struct type
**) 0;
3298 /* Call after end_symtab() */
3304 free ((char *) type_vector
);
3307 type_vector_length
= 0;
3308 previous_stab_code
= 0;
3312 finish_global_stabs (objfile
)
3313 struct objfile
*objfile
;
3317 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3318 free ((PTR
) global_stabs
);
3319 global_stabs
= NULL
;
3323 /* Initializer for this module */
3326 _initialize_stabsread ()
3328 undef_types_allocated
= 20;
3329 undef_types_length
= 0;
3330 undef_types
= (struct type
**)
3331 xmalloc (undef_types_allocated
* sizeof (struct type
*));