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 read_member_functions
PARAMS ((struct field_info
*, char **, struct type
*,
95 read_struct_fields
PARAMS ((struct field_info
*, char **, struct type
*,
99 read_baseclasses
PARAMS ((struct field_info
*, char **, struct type
*,
103 read_tilde_fields
PARAMS ((struct field_info
*, char **, struct type
*,
107 attach_fn_fields_to_type
PARAMS ((struct field_info
*, struct type
*));
110 attach_fields_to_type
PARAMS ((struct field_info
*, struct type
*,
114 read_struct_type
PARAMS ((char **, struct type
*, struct objfile
*));
117 read_array_type
PARAMS ((char **, struct type
*, struct objfile
*));
119 static struct type
**
120 read_args
PARAMS ((char **, int, struct objfile
*));
123 read_cpp_abbrev
PARAMS ((struct field_info
*, char **, struct type
*,
126 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
127 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
129 /* Define this as 1 if a pcc declaration of a char or short argument
130 gives the correct address. Otherwise assume pcc gives the
131 address of the corresponding int, which is not the same on a
132 big-endian machine. */
134 #ifndef BELIEVE_PCC_PROMOTION
135 #define BELIEVE_PCC_PROMOTION 0
138 /* During some calls to read_type (and thus to read_range_type), this
139 contains the name of the type being defined. Range types are only
140 used in C as basic types. We use the name to distinguish the otherwise
141 identical basic types "int" and "long" and their unsigned versions.
142 FIXME, this should disappear with better type management. */
144 static char *long_kludge_name
;
147 struct complaint dbx_class_complaint
=
149 "encountered DBX-style class variable debugging information.\n\
150 You seem to have compiled your program with \
151 \"g++ -g0\" instead of \"g++ -g\".\n\
152 Therefore GDB will not know about your class variables", 0, 0
156 struct complaint invalid_cpp_abbrev_complaint
=
157 {"invalid C++ abbreviation `%s'", 0, 0};
159 struct complaint invalid_cpp_type_complaint
=
160 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
162 struct complaint member_fn_complaint
=
163 {"member function type missing, got '%c'", 0, 0};
165 struct complaint const_vol_complaint
=
166 {"const/volatile indicator missing, got '%c'", 0, 0};
168 struct complaint error_type_complaint
=
169 {"debug info mismatch between compiler and debugger", 0, 0};
171 struct complaint invalid_member_complaint
=
172 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
174 struct complaint range_type_base_complaint
=
175 {"base type %d of range type is not defined", 0, 0};
177 struct complaint reg_value_complaint
=
178 {"register number too large in symbol %s", 0, 0};
180 struct complaint vtbl_notfound_complaint
=
181 {"virtual function table pointer not found when defining class `%s'", 0, 0};
183 struct complaint unrecognized_cplus_name_complaint
=
184 {"Unknown C++ symbol name `%s'", 0, 0};
186 struct complaint stabs_general_complaint
=
189 /* Make a list of forward references which haven't been defined. */
191 static struct type
**undef_types
;
192 static int undef_types_allocated
;
193 static int undef_types_length
;
195 /* Check for and handle cretinous stabs symbol name continuation! */
196 #define STABS_CONTINUE(pp) \
198 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
206 register char *p
= name
;
207 register int total
= p
[0];
222 /* Ensure result is positive. */
225 total
+= (1000 << 6);
227 return (total
% HASHSIZE
);
231 /* Look up a dbx type-number pair. Return the address of the slot
232 where the type for that number-pair is stored.
233 The number-pair is in TYPENUMS.
235 This can be used for finding the type associated with that pair
236 or for associating a new type with the pair. */
239 dbx_lookup_type (typenums
)
242 register int filenum
= typenums
[0];
243 register int index
= typenums
[1];
245 register int real_filenum
;
246 register struct header_file
*f
;
249 if (filenum
== -1) /* -1,-1 is for temporary types. */
252 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
253 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
254 filenum
, index
, symnum
);
258 /* Type is defined outside of header files.
259 Find it in this object file's type vector. */
260 if (index
>= type_vector_length
)
262 old_len
= type_vector_length
;
265 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
266 type_vector
= (struct type
**)
267 malloc (type_vector_length
* sizeof (struct type
*));
269 while (index
>= type_vector_length
)
271 type_vector_length
*= 2;
273 type_vector
= (struct type
**)
274 xrealloc ((char *) type_vector
,
275 (type_vector_length
* sizeof (struct type
*)));
276 memset (&type_vector
[old_len
], 0,
277 (type_vector_length
- old_len
) * sizeof (struct type
*));
279 return (&type_vector
[index
]);
283 real_filenum
= this_object_header_files
[filenum
];
285 if (real_filenum
>= n_header_files
)
290 f
= &header_files
[real_filenum
];
292 f_orig_length
= f
->length
;
293 if (index
>= f_orig_length
)
295 while (index
>= f
->length
)
299 f
->vector
= (struct type
**)
300 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
301 memset (&f
->vector
[f_orig_length
], 0,
302 (f
->length
- f_orig_length
) * sizeof (struct type
*));
304 return (&f
->vector
[index
]);
308 /* Make sure there is a type allocated for type numbers TYPENUMS
309 and return the type object.
310 This can create an empty (zeroed) type object.
311 TYPENUMS may be (-1, -1) to return a new type object that is not
312 put into the type vector, and so may not be referred to by number. */
315 dbx_alloc_type (typenums
, objfile
)
317 struct objfile
*objfile
;
319 register struct type
**type_addr
;
321 if (typenums
[0] == -1)
323 return (alloc_type (objfile
));
326 type_addr
= dbx_lookup_type (typenums
);
328 /* If we are referring to a type not known at all yet,
329 allocate an empty type for it.
330 We will fill it in later if we find out how. */
333 *type_addr
= alloc_type (objfile
);
339 /* for all the stabs in a given stab vector, build appropriate types
340 and fix their symbols in given symbol vector. */
343 patch_block_stabs (symbols
, stabs
, objfile
)
344 struct pending
*symbols
;
345 struct pending_stabs
*stabs
;
346 struct objfile
*objfile
;
356 /* for all the stab entries, find their corresponding symbols and
357 patch their types! */
359 for (ii
= 0; ii
< stabs
->count
; ++ii
)
361 name
= stabs
->stab
[ii
];
362 pp
= (char*) strchr (name
, ':');
363 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
366 #ifndef IBM6000_TARGET
367 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
373 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
376 lookup_function_type (read_type (&pp
, objfile
));
380 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
388 /* Read a number by which a type is referred to in dbx data,
389 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
390 Just a single number N is equivalent to (0,N).
391 Return the two numbers by storing them in the vector TYPENUMS.
392 TYPENUMS will then be used as an argument to dbx_lookup_type. */
395 read_type_number (pp
, typenums
)
397 register int *typenums
;
402 typenums
[0] = read_number (pp
, ',');
403 typenums
[1] = read_number (pp
, ')');
408 typenums
[1] = read_number (pp
, 0);
413 /* To handle GNU C++ typename abbreviation, we need to be able to
414 fill in a type's name as soon as space for that type is allocated.
415 `type_synonym_name' is the name of the type being allocated.
416 It is cleared as soon as it is used (lest all allocated types
419 static char *type_synonym_name
;
423 define_symbol (valu
, string
, desc
, type
, objfile
)
428 struct objfile
*objfile
;
430 register struct symbol
*sym
;
431 char *p
= (char *) strchr (string
, ':');
435 struct type
*temptype
;
437 /* We would like to eliminate nameless symbols, but keep their types.
438 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
439 to type 2, but, should not create a symbol to address that type. Since
440 the symbol will be nameless, there is no way any user can refer to it. */
444 /* Ignore syms with empty names. */
448 /* Ignore old-style symbols from cc -go */
452 /* If a nameless stab entry, all we need is the type, not the symbol.
453 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
454 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
456 sym
= (struct symbol
*)
457 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
458 memset (sym
, 0, sizeof (struct symbol
));
460 if (processing_gcc_compilation
)
462 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
463 number of bytes occupied by a type or object, which we ignore. */
464 SYMBOL_LINE(sym
) = desc
;
468 SYMBOL_LINE(sym
) = 0; /* unknown */
471 if (string
[0] == CPLUS_MARKER
)
473 /* Special GNU C++ names. */
477 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
478 &objfile
-> symbol_obstack
);
481 case 'v': /* $vtbl_ptr_type */
482 /* Was: SYMBOL_NAME (sym) = "vptr"; */
486 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
487 &objfile
-> symbol_obstack
);
491 /* This was an anonymous type that was never fixed up. */
495 complain (unrecognized_cplus_name_complaint
, string
);
496 goto normal
; /* Do *something* with it */
502 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
503 SYMBOL_NAME (sym
) = (char *)
504 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
505 /* Open-coded bcopy--saves function call time. */
506 /* FIXME: Does it really? Try replacing with simple strcpy and
507 try it on an executable with a large symbol table. */
509 register char *p1
= string
;
510 register char *p2
= SYMBOL_NAME (sym
);
518 /* If this symbol is from a C++ compilation, then attempt to cache the
519 demangled form for future reference. This is a typical time versus
520 space tradeoff, that was decided in favor of time because it sped up
521 C++ symbol lookups by a factor of about 20. */
523 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
527 /* Determine the type of name being defined. */
528 /* The Acorn RISC machine's compiler can put out locals that don't
529 start with "234=" or "(3,4)=", so assume anything other than the
530 deftypes we know how to handle is a local. */
531 if (!strchr ("cfFGpPrStTvVXCR", *p
))
536 /* c is a special case, not followed by a type-number.
537 SYMBOL:c=iVALUE for an integer constant symbol.
538 SYMBOL:c=rVALUE for a floating constant symbol.
539 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
540 e.g. "b:c=e6,0" for "const b = blob1"
541 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
545 error ("Invalid symbol data at symtab pos %d.", symnum
);
553 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
556 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (double));
557 memcpy (dbl_valu
, &d
, sizeof (double));
558 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
559 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
560 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
565 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
567 SYMBOL_VALUE (sym
) = atoi (p
);
568 SYMBOL_CLASS (sym
) = LOC_CONST
;
572 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
573 e.g. "b:c=e6,0" for "const b = blob1"
574 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
578 read_type_number (&p
, typenums
);
580 error ("Invalid symbol data: no comma in enum const symbol");
582 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
583 SYMBOL_VALUE (sym
) = atoi (p
);
584 SYMBOL_CLASS (sym
) = LOC_CONST
;
588 error ("Invalid symbol data at symtab pos %d.", symnum
);
590 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
591 add_symbol_to_list (sym
, &file_symbols
);
595 /* Now usually comes a number that says which data type,
596 and possibly more stuff to define the type
597 (all of which is handled by read_type) */
599 if (deftype
== 'p' && *p
== 'F')
600 /* pF is a two-letter code that means a function parameter in Fortran.
601 The type-number specifies the type of the return value.
602 Translate it into a pointer-to-function type. */
606 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
610 /* The symbol class letter is followed by a type (typically the
611 type of the symbol, or its return-type, or etc). Read it. */
618 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
619 strlen (SYMBOL_NAME (sym
)),
620 &objfile
-> symbol_obstack
);
623 /* Here we save the name of the symbol for read_range_type, which
624 ends up reading in the basic types. In stabs, unfortunately there
625 is no distinction between "int" and "long" types except their
626 names. Until we work out a saner type policy (eliminating most
627 builtin types and using the names specified in the files), we
628 save away the name so that far away from here in read_range_type,
629 we can examine it to decide between "int" and "long". FIXME. */
630 long_kludge_name
= SYMBOL_NAME (sym
);
632 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
638 /* The name of a caught exception. */
639 SYMBOL_CLASS (sym
) = LOC_LABEL
;
640 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
641 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
642 add_symbol_to_list (sym
, &local_symbols
);
646 /* A static function definition. */
647 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
648 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
649 add_symbol_to_list (sym
, &file_symbols
);
650 /* fall into process_function_types. */
652 process_function_types
:
653 /* Function result types are described as the result type in stabs.
654 We need to convert this to the function-returning-type-X type
655 in GDB. E.g. "int" is converted to "function returning int". */
656 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
659 /* This code doesn't work -- it needs to realloc and can't. */
660 /* Attempt to set up to record a function prototype... */
661 struct type
*new = alloc_type (objfile
);
663 /* Generate a template for the type of this function. The
664 types of the arguments will be added as we read the symbol
666 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
667 SYMBOL_TYPE(sym
) = new;
668 TYPE_OBJFILE (new) = objfile
;
669 in_function_type
= new;
671 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
674 /* fall into process_prototype_types */
676 process_prototype_types
:
677 /* Sun acc puts declared types of arguments here. We don't care
678 about their actual types (FIXME -- we should remember the whole
679 function prototype), but the list may define some new types
680 that we have to remember, so we must scan it now. */
683 read_type (&p
, objfile
);
688 /* A global function definition. */
689 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
690 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
691 add_symbol_to_list (sym
, &global_symbols
);
692 goto process_function_types
;
695 /* For a class G (global) symbol, it appears that the
696 value is not correct. It is necessary to search for the
697 corresponding linker definition to find the value.
698 These definitions appear at the end of the namelist. */
699 i
= hashname (SYMBOL_NAME (sym
));
700 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
701 global_sym_chain
[i
] = sym
;
702 SYMBOL_CLASS (sym
) = LOC_STATIC
;
703 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
704 add_symbol_to_list (sym
, &global_symbols
);
707 /* This case is faked by a conditional above,
708 when there is no code letter in the dbx data.
709 Dbx data never actually contains 'l'. */
711 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
712 SYMBOL_VALUE (sym
) = valu
;
713 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
714 add_symbol_to_list (sym
, &local_symbols
);
718 /* Normally this is a parameter, a LOC_ARG. On the i960, it
719 can also be a LOC_LOCAL_ARG depending on symbol type. */
720 #ifndef DBX_PARM_SYMBOL_CLASS
721 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
723 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
724 SYMBOL_VALUE (sym
) = valu
;
725 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
727 /* This doesn't work yet. */
728 add_param_to_type (&in_function_type
, sym
);
730 add_symbol_to_list (sym
, &local_symbols
);
732 /* If it's gcc-compiled, if it says `short', believe it. */
733 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
736 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
737 /* This macro is defined on machines (e.g. sparc) where
738 we should believe the type of a PCC 'short' argument,
739 but shouldn't believe the address (the address is
740 the address of the corresponding int). Note that
741 this is only different from the BELIEVE_PCC_PROMOTION
742 case on big-endian machines.
744 My guess is that this correction, as opposed to changing
745 the parameter to an 'int' (as done below, for PCC
746 on most machines), is the right thing to do
747 on all machines, but I don't want to risk breaking
748 something that already works. On most PCC machines,
749 the sparc problem doesn't come up because the calling
750 function has to zero the top bytes (not knowing whether
751 the called function wants an int or a short), so there
752 is no practical difference between an int and a short
753 (except perhaps what happens when the GDB user types
754 "print short_arg = 0x10000;").
756 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
757 actually produces the correct address (we don't need to fix it
758 up). I made this code adapt so that it will offset the symbol
759 if it was pointing at an int-aligned location and not
760 otherwise. This way you can use the same gdb for 4.0.x and
763 If the parameter is shorter than an int, and is integral
764 (e.g. char, short, or unsigned equivalent), and is claimed to
765 be passed on an integer boundary, don't believe it! Offset the
766 parameter's address to the tail-end of that integer. */
768 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
769 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
770 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
771 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
773 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
774 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
778 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
780 /* If PCC says a parameter is a short or a char,
781 it is really an int. */
782 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
783 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
784 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
786 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
787 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
792 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
795 /* acc seems to use P to delare the prototypes of functions that
796 are referenced by this file. gdb is not prepared to deal
797 with this extra information. FIXME, it ought to. */
799 goto process_prototype_types
;
801 /* Parameter which is in a register. */
802 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
803 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
804 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
806 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
807 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
809 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
810 add_symbol_to_list (sym
, &local_symbols
);
815 /* Register variable (either global or local). */
816 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
817 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
818 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
820 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
821 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
823 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
825 add_symbol_to_list (sym
, &local_symbols
);
827 add_symbol_to_list (sym
, &file_symbols
);
831 /* Static symbol at top level of file */
832 SYMBOL_CLASS (sym
) = LOC_STATIC
;
833 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
834 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
835 add_symbol_to_list (sym
, &file_symbols
);
839 /* For a nameless type, we don't want a create a symbol, thus we
840 did not use `sym'. Return without further processing. */
841 if (nameless
) return NULL
;
843 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
844 SYMBOL_VALUE (sym
) = valu
;
845 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
846 /* C++ vagaries: we may have a type which is derived from
847 a base type which did not have its name defined when the
848 derived class was output. We fill in the derived class's
849 base part member's name here in that case. */
850 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
851 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
852 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
853 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
856 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
857 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
858 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
859 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
862 add_symbol_to_list (sym
, &file_symbols
);
866 /* For a nameless type, we don't want a create a symbol, thus we
867 did not use `sym'. Return without further processing. */
868 if (nameless
) return NULL
;
870 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
871 SYMBOL_VALUE (sym
) = valu
;
872 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
873 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
874 TYPE_NAME (SYMBOL_TYPE (sym
))
875 = obconcat (&objfile
-> type_obstack
, "",
876 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
878 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
879 ? "struct " : "union ")),
881 add_symbol_to_list (sym
, &file_symbols
);
885 /* Clone the sym and then modify it. */
886 register struct symbol
*typedef_sym
= (struct symbol
*)
887 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
889 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
890 SYMBOL_VALUE (typedef_sym
) = valu
;
891 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
892 add_symbol_to_list (typedef_sym
, &file_symbols
);
897 /* Static symbol of local scope */
898 SYMBOL_CLASS (sym
) = LOC_STATIC
;
899 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
900 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
901 add_symbol_to_list (sym
, &local_symbols
);
905 /* Reference parameter */
906 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
907 SYMBOL_VALUE (sym
) = valu
;
908 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
909 add_symbol_to_list (sym
, &local_symbols
);
913 /* This is used by Sun FORTRAN for "function result value".
914 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
915 that Pascal uses it too, but when I tried it Pascal used
916 "x:3" (local symbol) instead. */
917 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
918 SYMBOL_VALUE (sym
) = valu
;
919 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
920 add_symbol_to_list (sym
, &local_symbols
);
924 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
930 /* Skip rest of this symbol and return an error type.
932 General notes on error recovery: error_type always skips to the
933 end of the symbol (modulo cretinous dbx symbol name continuation).
937 return error_type (pp);
939 is wrong because if *pp starts out pointing at '\0' (typically as the
940 result of an earlier error), it will be incremented to point to the
941 start of the next symbol, which might produce strange results, at least
942 if you run off the end of the string table. Instead use
945 return error_type (pp);
951 foo = error_type (pp);
955 And in case it isn't obvious, the point of all this hair is so the compiler
956 can define new types and new syntaxes, and old versions of the
957 debugger will be able to read the new symbol tables. */
963 complain (&error_type_complaint
);
966 /* Skip to end of symbol. */
972 /* Check for and handle cretinous dbx symbol name continuation! */
973 if ((*pp
)[-1] == '\\')
975 *pp
= next_symbol_text ();
982 return (builtin_type_error
);
986 /* Read a dbx type reference or definition;
987 return the type that is meant.
988 This can be just a number, in which case it references
989 a type already defined and placed in type_vector.
990 Or the number can be followed by an =, in which case
991 it means to define a new type according to the text that
995 read_type (pp
, objfile
)
997 struct objfile
*objfile
;
999 register struct type
*type
= 0;
1003 char type_descriptor
;
1005 /* Read type number if present. The type number may be omitted.
1006 for instance in a two-dimensional array declared with type
1007 "ar1;1;10;ar1;1;10;4". */
1008 if ((**pp
>= '0' && **pp
<= '9')
1011 read_type_number (pp
, typenums
);
1013 /* Type is not being defined here. Either it already exists,
1014 or this is a forward reference to it. dbx_alloc_type handles
1017 return dbx_alloc_type (typenums
, objfile
);
1019 /* Type is being defined here. */
1020 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1024 /* if such a type already exists, this is an unnecessary duplication
1025 of the stab string, which is common in (RS/6000) xlc generated
1026 objects. In that case, simply return NULL and let the caller take
1029 tt
= *dbx_lookup_type (typenums
);
1030 if (tt
&& tt
->length
&& tt
->code
)
1039 /* 'typenums=' not present, type is anonymous. Read and return
1040 the definition, but don't put it in the type vector. */
1041 typenums
[0] = typenums
[1] = -1;
1045 type_descriptor
= (*pp
)[-1];
1046 switch (type_descriptor
)
1050 enum type_code code
;
1052 /* Used to index through file_symbols. */
1053 struct pending
*ppt
;
1056 /* Name including "struct", etc. */
1059 /* Name without "struct", etc. */
1060 char *type_name_only
;
1066 /* Set the type code according to the following letter. */
1070 code
= TYPE_CODE_STRUCT
;
1074 code
= TYPE_CODE_UNION
;
1078 code
= TYPE_CODE_ENUM
;
1082 return error_type (pp
);
1085 to
= type_name
= (char *)
1086 obstack_alloc (&objfile
-> type_obstack
,
1088 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1090 /* Copy the prefix. */
1092 while ((*to
++ = *from
++) != '\0')
1096 type_name_only
= to
;
1098 /* Copy the name. */
1100 while ((*to
++ = *from
++) != ':')
1104 /* Set the pointer ahead of the name which we just read. */
1108 /* The following hack is clearly wrong, because it doesn't
1109 check whether we are in a baseclass. I tried to reproduce
1110 the case that it is trying to fix, but I couldn't get
1111 g++ to put out a cross reference to a basetype. Perhaps
1112 it doesn't do it anymore. */
1113 /* Note: for C++, the cross reference may be to a base type which
1114 has not yet been seen. In this case, we skip to the comma,
1115 which will mark the end of the base class name. (The ':'
1116 at the end of the base class name will be skipped as well.)
1117 But sometimes (ie. when the cross ref is the last thing on
1118 the line) there will be no ','. */
1119 from
= (char *) strchr (*pp
, ',');
1125 /* Now check to see whether the type has already been declared. */
1126 /* This is necessary at least in the case where the
1127 program says something like
1129 The compiler puts out a cross-reference; we better find
1130 set the length of the structure correctly so we can
1131 set the length of the array. */
1132 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1133 for (i
= 0; i
< ppt
->nsyms
; i
++)
1135 struct symbol
*sym
= ppt
->symbol
[i
];
1137 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1138 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1139 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1140 && STREQ (SYMBOL_NAME (sym
), type_name_only
))
1142 obstack_free (&objfile
-> type_obstack
, type_name
);
1143 type
= SYMBOL_TYPE (sym
);
1148 /* Didn't find the type to which this refers, so we must
1149 be dealing with a forward reference. Allocate a type
1150 structure for it, and keep track of it so we can
1151 fill in the rest of the fields when we get the full
1153 type
= dbx_alloc_type (typenums
, objfile
);
1154 TYPE_CODE (type
) = code
;
1155 TYPE_NAME (type
) = type_name
;
1156 INIT_CPLUS_SPECIFIC(type
);
1157 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1159 add_undefined_type (type
);
1163 case '-': /* RS/6000 built-in type */
1165 type
= builtin_type (pp
); /* (in xcoffread.c) */
1180 read_type_number (pp
, xtypenums
);
1181 type
= *dbx_lookup_type (xtypenums
);
1186 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1187 if (typenums
[0] != -1)
1188 *dbx_lookup_type (typenums
) = type
;
1191 /* In the following types, we must be sure to overwrite any existing
1192 type that the typenums refer to, rather than allocating a new one
1193 and making the typenums point to the new one. This is because there
1194 may already be pointers to the existing type (if it had been
1195 forward-referenced), and we must change it to a pointer, function,
1196 reference, or whatever, *in-place*. */
1199 type1
= read_type (pp
, objfile
);
1200 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1203 case '&': /* Reference to another type */
1204 type1
= read_type (pp
, objfile
);
1205 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1208 case 'f': /* Function returning another type */
1209 type1
= read_type (pp
, objfile
);
1210 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1213 case 'k': /* Const qualifier on some type (Sun) */
1214 type
= read_type (pp
, objfile
);
1215 /* FIXME! For now, we ignore const and volatile qualifiers. */
1218 case 'B': /* Volatile qual on some type (Sun) */
1219 type
= read_type (pp
, objfile
);
1220 /* FIXME! For now, we ignore const and volatile qualifiers. */
1223 /* FIXME -- we should be doing smash_to_XXX types here. */
1224 case '@': /* Member (class & variable) type */
1226 struct type
*domain
= read_type (pp
, objfile
);
1227 struct type
*memtype
;
1230 /* Invalid member type data format. */
1231 return error_type (pp
);
1234 memtype
= read_type (pp
, objfile
);
1235 type
= dbx_alloc_type (typenums
, objfile
);
1236 smash_to_member_type (type
, domain
, memtype
);
1240 case '#': /* Method (class & fn) type */
1241 if ((*pp
)[0] == '#')
1243 /* We'll get the parameter types from the name. */
1244 struct type
*return_type
;
1247 return_type
= read_type (pp
, objfile
);
1248 if (*(*pp
)++ != ';')
1249 complain (&invalid_member_complaint
, symnum
);
1250 type
= allocate_stub_method (return_type
);
1251 if (typenums
[0] != -1)
1252 *dbx_lookup_type (typenums
) = type
;
1256 struct type
*domain
= read_type (pp
, objfile
);
1257 struct type
*return_type
;
1260 if (*(*pp
)++ != ',')
1261 error ("invalid member type data format, at symtab pos %d.",
1264 return_type
= read_type (pp
, objfile
);
1265 args
= read_args (pp
, ';', objfile
);
1266 type
= dbx_alloc_type (typenums
, objfile
);
1267 smash_to_method_type (type
, domain
, return_type
, args
);
1271 case 'r': /* Range type */
1272 type
= read_range_type (pp
, typenums
, objfile
);
1273 if (typenums
[0] != -1)
1274 *dbx_lookup_type (typenums
) = type
;
1277 case 'b': /* Sun ACC builtin int type */
1278 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1279 if (typenums
[0] != -1)
1280 *dbx_lookup_type (typenums
) = type
;
1283 case 'R': /* Sun ACC builtin float type */
1284 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1285 if (typenums
[0] != -1)
1286 *dbx_lookup_type (typenums
) = type
;
1289 case 'e': /* Enumeration type */
1290 type
= dbx_alloc_type (typenums
, objfile
);
1291 type
= read_enum_type (pp
, type
, objfile
);
1292 *dbx_lookup_type (typenums
) = type
;
1295 case 's': /* Struct type */
1296 case 'u': /* Union type */
1297 type
= dbx_alloc_type (typenums
, objfile
);
1298 if (!TYPE_NAME (type
))
1300 TYPE_NAME (type
) = type_synonym_name
;
1302 type_synonym_name
= NULL
;
1303 switch (type_descriptor
)
1306 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1309 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1312 type
= read_struct_type (pp
, type
, objfile
);
1315 case 'a': /* Array type */
1317 return error_type (pp
);
1320 type
= dbx_alloc_type (typenums
, objfile
);
1321 type
= read_array_type (pp
, type
, objfile
);
1325 --*pp
; /* Go back to the symbol in error */
1326 /* Particularly important if it was \0! */
1327 return error_type (pp
);
1336 /* This page contains subroutines of read_type. */
1338 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1339 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1340 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1342 /* Read member function stabs info for C++ classes. The form of each member
1345 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1347 An example with two member functions is:
1349 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1351 For the case of overloaded operators, the format is op$::*.funcs, where
1352 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1353 name (such as `+=') and `.' marks the end of the operator name. */
1356 read_member_functions (fip
, pp
, type
, objfile
)
1357 struct field_info
*fip
;
1360 struct objfile
*objfile
;
1364 /* Total number of member functions defined in this class. If the class
1365 defines two `f' functions, and one `g' function, then this will have
1367 int total_length
= 0;
1371 struct next_fnfield
*next
;
1372 struct fn_field fn_field
;
1374 struct type
*look_ahead_type
;
1375 struct next_fnfieldlist
*new_fnlist
;
1376 struct next_fnfield
*new_sublist
;
1380 /* Process each list until we find something that is not a member function
1381 or find the end of the functions. */
1385 /* We should be positioned at the start of the function name.
1386 Scan forward to find the first ':' and if it is not the
1387 first of a "::" delimiter, then this is not a member function. */
1399 look_ahead_type
= NULL
;
1402 new_fnlist
= (struct next_fnfieldlist
*)
1403 xmalloc (sizeof (struct next_fnfieldlist
));
1404 make_cleanup (free
, new_fnlist
);
1405 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1407 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1409 /* This is a completely wierd case. In order to stuff in the
1410 names that might contain colons (the usual name delimiter),
1411 Mike Tiemann defined a different name format which is
1412 signalled if the identifier is "op$". In that case, the
1413 format is "op$::XXXX." where XXXX is the name. This is
1414 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1415 /* This lets the user type "break operator+".
1416 We could just put in "+" as the name, but that wouldn't
1418 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1419 char *o
= opname
+ 3;
1421 /* Skip past '::'. */
1424 STABS_CONTINUE (pp
);
1430 main_fn_name
= savestring (opname
, o
- opname
);
1436 main_fn_name
= savestring (*pp
, p
- *pp
);
1437 /* Skip past '::'. */
1440 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1445 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1446 make_cleanup (free
, new_sublist
);
1447 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1449 /* Check for and handle cretinous dbx symbol name continuation! */
1450 if (look_ahead_type
== NULL
)
1453 STABS_CONTINUE (pp
);
1455 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1458 /* Invalid symtab info for member function. */
1464 /* g++ version 1 kludge */
1465 new_sublist
-> fn_field
.type
= look_ahead_type
;
1466 look_ahead_type
= NULL
;
1476 /* If this is just a stub, then we don't have the real name here. */
1478 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1480 new_sublist
-> fn_field
.is_stub
= 1;
1482 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1485 /* Set this member function's visibility fields. */
1488 case VISIBILITY_PRIVATE
:
1489 new_sublist
-> fn_field
.is_private
= 1;
1491 case VISIBILITY_PROTECTED
:
1492 new_sublist
-> fn_field
.is_protected
= 1;
1496 STABS_CONTINUE (pp
);
1499 case 'A': /* Normal functions. */
1500 new_sublist
-> fn_field
.is_const
= 0;
1501 new_sublist
-> fn_field
.is_volatile
= 0;
1504 case 'B': /* `const' member functions. */
1505 new_sublist
-> fn_field
.is_const
= 1;
1506 new_sublist
-> fn_field
.is_volatile
= 0;
1509 case 'C': /* `volatile' member function. */
1510 new_sublist
-> fn_field
.is_const
= 0;
1511 new_sublist
-> fn_field
.is_volatile
= 1;
1514 case 'D': /* `const volatile' member function. */
1515 new_sublist
-> fn_field
.is_const
= 1;
1516 new_sublist
-> fn_field
.is_volatile
= 1;
1519 case '*': /* File compiled with g++ version 1 -- no info */
1524 complain (&const_vol_complaint
, **pp
);
1531 /* virtual member function, followed by index.
1532 The sign bit is set to distinguish pointers-to-methods
1533 from virtual function indicies. Since the array is
1534 in words, the quantity must be shifted left by 1
1535 on 16 bit machine, and by 2 on 32 bit machine, forcing
1536 the sign bit out, and usable as a valid index into
1537 the array. Remove the sign bit here. */
1538 new_sublist
-> fn_field
.voffset
=
1539 (0x7fffffff & read_number (pp
, ';')) + 2;
1541 STABS_CONTINUE (pp
);
1542 if (**pp
== ';' || **pp
== '\0')
1544 /* Must be g++ version 1. */
1545 new_sublist
-> fn_field
.fcontext
= 0;
1549 /* Figure out from whence this virtual function came.
1550 It may belong to virtual function table of
1551 one of its baseclasses. */
1552 look_ahead_type
= read_type (pp
, objfile
);
1555 /* g++ version 1 overloaded methods. */
1559 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1568 look_ahead_type
= NULL
;
1574 /* static member function. */
1575 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
1576 if (strncmp (new_sublist
-> fn_field
.physname
,
1577 main_fn_name
, strlen (main_fn_name
)))
1579 new_sublist
-> fn_field
.is_stub
= 1;
1585 complain (&member_fn_complaint
, (*pp
)[-1]);
1586 /* Fall through into normal member function. */
1589 /* normal member function. */
1590 new_sublist
-> fn_field
.voffset
= 0;
1591 new_sublist
-> fn_field
.fcontext
= 0;
1595 new_sublist
-> next
= sublist
;
1596 sublist
= new_sublist
;
1598 STABS_CONTINUE (pp
);
1600 while (**pp
!= ';' && **pp
!= '\0');
1604 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
1605 obstack_alloc (&objfile
-> type_obstack
,
1606 sizeof (struct fn_field
) * length
);
1607 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
1608 sizeof (struct fn_field
) * length
);
1609 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
1611 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
1614 new_fnlist
-> fn_fieldlist
.length
= length
;
1615 new_fnlist
-> next
= fip
-> fnlist
;
1616 fip
-> fnlist
= new_fnlist
;
1618 total_length
+= length
;
1619 STABS_CONTINUE (pp
);
1624 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1625 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
1626 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
1627 memset (TYPE_FN_FIELDLISTS (type
), 0,
1628 sizeof (struct fn_fieldlist
) * nfn_fields
);
1629 TYPE_NFN_FIELDS (type
) = nfn_fields
;
1630 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
1636 /* Special GNU C++ name.
1637 FIXME: Still need to properly handle parse error conditions. */
1640 read_cpp_abbrev (fip
, pp
, type
, objfile
)
1641 struct field_info
*fip
;
1644 struct objfile
*objfile
;
1650 struct type
*context
;
1660 /* At this point, *pp points to something like "22:23=*22...",
1661 where the type number before the ':' is the "context" and
1662 everything after is a regular type definition. Lookup the
1663 type, find it's name, and construct the field name. */
1665 context
= read_type (pp
, objfile
);
1669 case 'f': /* $vf -- a virtual function table pointer */
1670 fip
->list
->field
.name
=
1671 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
1674 case 'b': /* $vb -- a virtual bsomethingorother */
1675 name
= type_name_no_tag (context
);
1678 complain (&invalid_cpp_type_complaint
, symnum
);
1681 fip
->list
->field
.name
=
1682 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
1686 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1687 fip
->list
->field
.name
=
1688 obconcat (&objfile
->type_obstack
,
1689 "INVALID_CPLUSPLUS_ABBREV", "", "");
1693 /* At this point, *pp points to the ':'. Skip it and read the
1699 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1701 fip
->list
->field
.type
= read_type (pp
, objfile
);
1702 (*pp
)++; /* Skip the comma. */
1703 fip
->list
->field
.bitpos
= read_number (pp
, ';');
1704 /* This field is unpacked. */
1705 fip
->list
->field
.bitsize
= 0;
1706 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
1710 /* GNU C++ anonymous type. */
1711 complain (&stabs_general_complaint
, "g++ anonymous type $_ not handled");
1715 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1720 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
1721 struct field_info
*fip
;
1725 struct objfile
*objfile
;
1727 fip
-> list
-> field
.name
=
1728 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
1731 /* This means we have a visibility for a field coming. */
1735 fip
-> list
-> visibility
= *(*pp
)++;
1736 switch (fip
-> list
-> visibility
)
1738 case VISIBILITY_PRIVATE
:
1739 case VISIBILITY_PROTECTED
:
1742 case VISIBILITY_PUBLIC
:
1747 /* Unknown visibility specifier. */
1748 complain (&stabs_general_complaint
,
1749 "unknown visibility specifier");
1756 /* normal dbx-style format, no explicit visibility */
1757 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
1760 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
1765 /* Possible future hook for nested types. */
1768 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
1774 /* Static class member. */
1775 fip
-> list
-> field
.bitpos
= (long) -1;
1781 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
1785 else if (**pp
!= ',')
1787 /* Bad structure-type format. */
1788 complain (&stabs_general_complaint
, "bad structure-type format");
1792 (*pp
)++; /* Skip the comma. */
1793 fip
-> list
-> field
.bitpos
= read_number (pp
, ',');
1794 fip
-> list
-> field
.bitsize
= read_number (pp
, ';');
1797 /* FIXME-tiemann: Can't the compiler put out something which
1798 lets us distinguish these? (or maybe just not put out anything
1799 for the field). What is the story here? What does the compiler
1800 really do? Also, patch gdb.texinfo for this case; I document
1801 it as a possible problem there. Search for "DBX-style". */
1803 /* This is wrong because this is identical to the symbols
1804 produced for GCC 0-size arrays. For example:
1809 The code which dumped core in such circumstances should be
1810 fixed not to dump core. */
1812 /* g++ -g0 can put out bitpos & bitsize zero for a static
1813 field. This does not give us any way of getting its
1814 class, so we can't know its name. But we can just
1815 ignore the field so we don't dump core and other nasty
1817 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
1819 complain (&dbx_class_complaint
);
1820 /* Ignore this field. */
1821 fip
-> list
= fip
-> list
-> next
;
1826 /* Detect an unpacked field and mark it as such.
1827 dbx gives a bit size for all fields.
1828 Note that forward refs cannot be packed,
1829 and treat enums as if they had the width of ints. */
1831 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
1832 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
1834 fip
-> list
-> field
.bitsize
= 0;
1836 if ((fip
-> list
-> field
.bitsize
1837 == 8 * TYPE_LENGTH (fip
-> list
-> field
.type
)
1838 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
1839 && (fip
-> list
-> field
.bitsize
1840 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
1844 fip
-> list
-> field
.bitpos
% 8 == 0)
1846 fip
-> list
-> field
.bitsize
= 0;
1852 /* Read struct or class data fields. They have the form:
1854 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
1856 At the end, we see a semicolon instead of a field.
1858 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1861 The optional VISIBILITY is one of:
1863 '/0' (VISIBILITY_PRIVATE)
1864 '/1' (VISIBILITY_PROTECTED)
1865 '/2' (VISIBILITY_PUBLIC)
1867 or nothing, for C style fields with public visibility. */
1870 read_struct_fields (fip
, pp
, type
, objfile
)
1871 struct field_info
*fip
;
1874 struct objfile
*objfile
;
1877 struct nextfield
*new;
1879 /* We better set p right now, in case there are no fields at all... */
1883 /* Read each data member type until we find the terminating ';' at the end of
1884 the data member list, or break for some other reason such as finding the
1885 start of the member function list. */
1889 STABS_CONTINUE (pp
);
1890 /* Get space to record the next field's data. */
1891 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1892 make_cleanup (free
, new);
1893 memset (new, 0, sizeof (struct nextfield
));
1894 new -> next
= fip
-> list
;
1897 /* Get the field name. */
1899 if (*p
== CPLUS_MARKER
)
1901 read_cpp_abbrev (fip
, pp
, type
, objfile
);
1905 /* Look for the ':' that separates the field name from the field
1906 values. Data members are delimited by a single ':', while member
1907 functions are delimited by a pair of ':'s. When we hit the member
1908 functions (if any), terminate scan loop and return. */
1915 /* Check to see if we have hit the member functions yet. */
1920 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
1924 /* chill the list of fields: the last entry (at the head) is a
1925 partially constructed entry which we now scrub. */
1926 fip
-> list
= fip
-> list
-> next
;
1931 /* The stabs for C++ derived classes contain baseclass information which
1932 is marked by a '!' character after the total size. This function is
1933 called when we encounter the baseclass marker, and slurps up all the
1934 baseclass information.
1936 Immediately following the '!' marker is the number of base classes that
1937 the class is derived from, followed by information for each base class.
1938 For each base class, there are two visibility specifiers, a bit offset
1939 to the base class information within the derived class, a reference to
1940 the type for the base class, and a terminating semicolon.
1942 A typical example, with two base classes, would be "!2,020,19;0264,21;".
1944 Baseclass information marker __________________|| | | | | | |
1945 Number of baseclasses __________________________| | | | | | |
1946 Visibility specifiers (2) ________________________| | | | | |
1947 Offset in bits from start of class _________________| | | | |
1948 Type number for base class ___________________________| | | |
1949 Visibility specifiers (2) _______________________________| | |
1950 Offset in bits from start of class ________________________| |
1951 Type number of base class ____________________________________|
1955 read_baseclasses (fip
, pp
, type
, objfile
)
1956 struct field_info
*fip
;
1959 struct objfile
*objfile
;
1962 struct nextfield
*new;
1970 /* Skip the '!' baseclass information marker. */
1974 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1975 TYPE_N_BASECLASSES (type
) = read_number (pp
, ',');
1978 /* Some stupid compilers have trouble with the following, so break
1979 it up into simpler expressions. */
1980 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
1981 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
1984 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
1987 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
1988 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
1992 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
1994 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
1996 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1997 make_cleanup (free
, new);
1998 memset (new, 0, sizeof (struct nextfield
));
1999 new -> next
= fip
-> list
;
2001 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2003 STABS_CONTINUE (pp
);
2007 /* Nothing to do. */
2010 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2013 /* Bad visibility format. */
2017 new -> visibility
= *(*pp
)++;
2018 switch (new -> visibility
)
2020 case VISIBILITY_PRIVATE
:
2021 case VISIBILITY_PROTECTED
:
2022 case VISIBILITY_PUBLIC
:
2025 /* Bad visibility format. */
2029 /* The remaining value is the bit offset of the portion of the object
2030 corresponding to this baseclass. Always zero in the absence of
2031 multiple inheritance. */
2033 new -> field
.bitpos
= read_number (pp
, ',');
2035 /* The last piece of baseclass information is the type of the base
2036 class. Read it, and remember it's type name as this field's name. */
2038 new -> field
.type
= read_type (pp
, objfile
);
2039 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2041 /* skip trailing ';' and bump count of number of fields seen */
2047 /* The tail end of stabs for C++ classes that contain a virtual function
2048 pointer contains a tilde, a %, and a type number.
2049 The type number refers to the base class (possibly this class itself) which
2050 contains the vtable pointer for the current class.
2052 This function is called when we have parsed all the method declarations,
2053 so we can look for the vptr base class info. */
2056 read_tilde_fields (fip
, pp
, type
, objfile
)
2057 struct field_info
*fip
;
2060 struct objfile
*objfile
;
2064 STABS_CONTINUE (pp
);
2066 /* If we are positioned at a ';', then skip it. */
2076 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2078 /* Obsolete flags that used to indicate the presence
2079 of constructors and/or destructors. */
2083 /* Read either a '%' or the final ';'. */
2084 if (*(*pp
)++ == '%')
2086 /* The next number is the type number of the base class
2087 (possibly our own class) which supplies the vtable for
2088 this class. Parse it out, and search that class to find
2089 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2090 and TYPE_VPTR_FIELDNO. */
2095 t
= read_type (pp
, objfile
);
2097 while (*p
!= '\0' && *p
!= ';')
2103 /* Premature end of symbol. */
2107 TYPE_VPTR_BASETYPE (type
) = t
;
2108 if (type
== t
) /* Our own class provides vtbl ptr */
2110 for (i
= TYPE_NFIELDS (t
) - 1;
2111 i
>= TYPE_N_BASECLASSES (t
);
2114 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2115 sizeof (vptr_name
) - 1))
2117 TYPE_VPTR_FIELDNO (type
) = i
;
2121 /* Virtual function table field not found. */
2122 complain (vtbl_notfound_complaint
, TYPE_NAME (type
));
2127 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2138 attach_fn_fields_to_type (fip
, type
)
2139 struct field_info
*fip
;
2140 register struct type
*type
;
2144 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2146 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2148 /* @@ Memory leak on objfile -> type_obstack? */
2151 TYPE_NFN_FIELDS_TOTAL (type
) +=
2152 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2155 for (n
= TYPE_NFN_FIELDS (type
);
2156 fip
-> fnlist
!= NULL
;
2157 fip
-> fnlist
= fip
-> fnlist
-> next
)
2159 --n
; /* Circumvent Sun3 compiler bug */
2160 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2165 /* Create the vector of fields, and record how big it is.
2166 We need this info to record proper virtual function table information
2167 for this class's virtual functions. */
2170 attach_fields_to_type (fip
, type
, objfile
)
2171 struct field_info
*fip
;
2172 register struct type
*type
;
2173 struct objfile
*objfile
;
2175 register int nfields
= 0;
2176 register int non_public_fields
= 0;
2177 register struct nextfield
*scan
;
2179 /* Count up the number of fields that we have, as well as taking note of
2180 whether or not there are any non-public fields, which requires us to
2181 allocate and build the private_field_bits and protected_field_bits
2184 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2187 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2189 non_public_fields
++;
2193 /* Now we know how many fields there are, and whether or not there are any
2194 non-public fields. Record the field count, allocate space for the
2195 array of fields, and create blank visibility bitfields if necessary. */
2197 TYPE_NFIELDS (type
) = nfields
;
2198 TYPE_FIELDS (type
) = (struct field
*)
2199 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2200 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2202 if (non_public_fields
)
2204 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2206 TYPE_FIELD_PRIVATE_BITS (type
) =
2207 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2208 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2210 TYPE_FIELD_PROTECTED_BITS (type
) =
2211 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2212 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2215 /* Copy the saved-up fields into the field vector. Start from the head
2216 of the list, adding to the tail of the field array, so that they end
2217 up in the same order in the array in which they were added to the list. */
2219 while (nfields
-- > 0)
2221 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2222 switch (fip
-> list
-> visibility
)
2224 case VISIBILITY_PRIVATE
:
2225 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2228 case VISIBILITY_PROTECTED
:
2229 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2232 case VISIBILITY_PUBLIC
:
2236 /* Should warn about this unknown visibility? */
2239 fip
-> list
= fip
-> list
-> next
;
2244 /* Read the description of a structure (or union type) and return an object
2245 describing the type.
2247 PP points to a character pointer that points to the next unconsumed token
2248 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2249 *PP will point to "4a:1,0,32;;".
2251 TYPE points to an incomplete type that needs to be filled in.
2253 OBJFILE points to the current objfile from which the stabs information is
2254 being read. (Note that it is redundant in that TYPE also contains a pointer
2255 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2258 static struct type
*
2259 read_struct_type (pp
, type
, objfile
)
2262 struct objfile
*objfile
;
2264 struct cleanup
*back_to
;
2265 struct field_info fi
;
2270 back_to
= make_cleanup (null_cleanup
, 0);
2272 INIT_CPLUS_SPECIFIC (type
);
2273 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2275 /* First comes the total size in bytes. */
2277 TYPE_LENGTH (type
) = read_number (pp
, 0);
2279 /* Now read the baseclasses, if any, read the regular C struct or C++
2280 class member fields, attach the fields to the type, read the C++
2281 member functions, attach them to the type, and then read any tilde
2284 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2285 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2286 || !attach_fields_to_type (&fi
, type
, objfile
)
2287 || !read_member_functions (&fi
, pp
, type
, objfile
)
2288 || !attach_fn_fields_to_type (&fi
, type
)
2289 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2291 do_cleanups (back_to
);
2292 return (error_type (pp
));
2295 do_cleanups (back_to
);
2299 /* Read a definition of an array type,
2300 and create and return a suitable type object.
2301 Also creates a range type which represents the bounds of that
2304 static struct type
*
2305 read_array_type (pp
, type
, objfile
)
2307 register struct type
*type
;
2308 struct objfile
*objfile
;
2310 struct type
*index_type
, *element_type
, *range_type
;
2314 /* Format of an array type:
2315 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2318 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2319 for these, produce a type like float[][]. */
2321 index_type
= read_type (pp
, objfile
);
2323 /* Improper format of array type decl. */
2324 return error_type (pp
);
2327 if (!(**pp
>= '0' && **pp
<= '9'))
2332 lower
= read_number (pp
, ';');
2334 if (!(**pp
>= '0' && **pp
<= '9'))
2339 upper
= read_number (pp
, ';');
2341 element_type
= read_type (pp
, objfile
);
2350 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2351 type
= create_array_type (type
, element_type
, range_type
);
2353 /* If we have an array whose element type is not yet known, but whose
2354 bounds *are* known, record it to be adjusted at the end of the file. */
2356 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2358 add_undefined_type (type
);
2365 /* Read a definition of an enumeration type,
2366 and create and return a suitable type object.
2367 Also defines the symbols that represent the values of the type. */
2369 static struct type
*
2370 read_enum_type (pp
, type
, objfile
)
2372 register struct type
*type
;
2373 struct objfile
*objfile
;
2378 register struct symbol
*sym
;
2380 struct pending
**symlist
;
2381 struct pending
*osyms
, *syms
;
2385 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2386 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2387 to do? For now, force all enum values to file scope. */
2388 if (within_function
)
2389 symlist
= &local_symbols
;
2392 symlist
= &file_symbols
;
2394 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2396 /* Read the value-names and their values.
2397 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2398 A semicolon or comma instead of a NAME means the end. */
2399 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2401 STABS_CONTINUE (pp
);
2403 while (*p
!= ':') p
++;
2404 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2406 n
= read_number (pp
, ',');
2408 sym
= (struct symbol
*)
2409 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2410 memset (sym
, 0, sizeof (struct symbol
));
2411 SYMBOL_NAME (sym
) = name
;
2412 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
2413 SYMBOL_CLASS (sym
) = LOC_CONST
;
2414 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2415 SYMBOL_VALUE (sym
) = n
;
2416 add_symbol_to_list (sym
, symlist
);
2421 (*pp
)++; /* Skip the semicolon. */
2423 /* Now fill in the fields of the type-structure. */
2425 TYPE_LENGTH (type
) = sizeof (int);
2426 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2427 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2428 TYPE_NFIELDS (type
) = nsyms
;
2429 TYPE_FIELDS (type
) = (struct field
*)
2430 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2431 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2433 /* Find the symbols for the values and put them into the type.
2434 The symbols can be found in the symlist that we put them on
2435 to cause them to be defined. osyms contains the old value
2436 of that symlist; everything up to there was defined by us. */
2437 /* Note that we preserve the order of the enum constants, so
2438 that in something like "enum {FOO, LAST_THING=FOO}" we print
2439 FOO, not LAST_THING. */
2441 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2446 for (; j
< syms
->nsyms
; j
++,n
++)
2448 struct symbol
*xsym
= syms
->symbol
[j
];
2449 SYMBOL_TYPE (xsym
) = type
;
2450 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2451 TYPE_FIELD_VALUE (type
, n
) = 0;
2452 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2453 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2460 /* This screws up perfectly good C programs with enums. FIXME. */
2461 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2462 if(TYPE_NFIELDS(type
) == 2 &&
2463 ((STREQ(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2464 STREQ(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2465 (STREQ(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2466 STREQ(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2467 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2473 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2474 typedefs in every file (for int, long, etc):
2476 type = b <signed> <width>; <offset>; <nbits>
2477 signed = u or s. Possible c in addition to u or s (for char?).
2478 offset = offset from high order bit to start bit of type.
2479 width is # bytes in object of this type, nbits is # bits in type.
2481 The width/offset stuff appears to be for small objects stored in
2482 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2485 static struct type
*
2486 read_sun_builtin_type (pp
, typenums
, objfile
)
2489 struct objfile
*objfile
;
2503 return error_type (pp
);
2507 /* For some odd reason, all forms of char put a c here. This is strange
2508 because no other type has this honor. We can safely ignore this because
2509 we actually determine 'char'acterness by the number of bits specified in
2515 /* The first number appears to be the number of bytes occupied
2516 by this type, except that unsigned short is 4 instead of 2.
2517 Since this information is redundant with the third number,
2518 we will ignore it. */
2519 read_number (pp
, ';');
2521 /* The second number is always 0, so ignore it too. */
2522 read_number (pp
, ';');
2524 /* The third number is the number of bits for this type. */
2525 nbits
= read_number (pp
, 0);
2527 /* FIXME. Here we should just be able to make a type of the right
2528 number of bits and signedness. FIXME. */
2530 if (nbits
== TARGET_LONG_LONG_BIT
)
2531 return (lookup_fundamental_type (objfile
,
2532 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
2534 if (nbits
== TARGET_INT_BIT
)
2536 /* FIXME -- the only way to distinguish `int' from `long'
2537 is to look at its name! */
2540 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2541 return lookup_fundamental_type (objfile
, FT_LONG
);
2543 return lookup_fundamental_type (objfile
, FT_INTEGER
);
2547 if (long_kludge_name
2548 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2549 long_kludge_name
[9] == 'l' /* long */)
2550 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2551 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
2553 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
2557 if (nbits
== TARGET_SHORT_BIT
)
2558 return (lookup_fundamental_type (objfile
,
2559 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
2561 if (nbits
== TARGET_CHAR_BIT
)
2562 return (lookup_fundamental_type (objfile
,
2563 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
2566 return lookup_fundamental_type (objfile
, FT_VOID
);
2568 return error_type (pp
);
2571 static struct type
*
2572 read_sun_floating_type (pp
, typenums
, objfile
)
2575 struct objfile
*objfile
;
2579 /* The first number has more details about the type, for example
2580 FN_COMPLEX. See the sun stab.h. */
2581 read_number (pp
, ';');
2583 /* The second number is the number of bytes occupied by this type */
2584 nbytes
= read_number (pp
, ';');
2587 return error_type (pp
);
2589 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
2590 return lookup_fundamental_type (objfile
, FT_FLOAT
);
2592 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2593 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
2595 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2596 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
2598 return error_type (pp
);
2601 /* Read a number from the string pointed to by *PP.
2602 The value of *PP is advanced over the number.
2603 If END is nonzero, the character that ends the
2604 number must match END, or an error happens;
2605 and that character is skipped if it does match.
2606 If END is zero, *PP is left pointing to that character.
2608 If the number fits in a long, set *VALUE and set *BITS to 0.
2609 If not, set *BITS to be the number of bits in the number.
2611 If encounter garbage, set *BITS to -1. */
2614 read_huge_number (pp
, end
, valu
, bits
)
2635 /* Leading zero means octal. GCC uses this to output values larger
2636 than an int (because that would be hard in decimal). */
2643 upper_limit
= LONG_MAX
/ radix
;
2644 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2646 if (n
<= upper_limit
)
2649 n
+= c
- '0'; /* FIXME this overflows anyway */
2654 /* This depends on large values being output in octal, which is
2661 /* Ignore leading zeroes. */
2665 else if (c
== '2' || c
== '3')
2691 /* Large decimal constants are an error (because it is hard to
2692 count how many bits are in them). */
2698 /* -0x7f is the same as 0x80. So deal with it by adding one to
2699 the number of bits. */
2714 static struct type
*
2715 read_range_type (pp
, typenums
, objfile
)
2718 struct objfile
*objfile
;
2724 struct type
*result_type
;
2725 struct type
*index_type
;
2727 /* First comes a type we are a subrange of.
2728 In C it is usually 0, 1 or the type being defined. */
2729 read_type_number (pp
, rangenums
);
2730 self_subrange
= (rangenums
[0] == typenums
[0] &&
2731 rangenums
[1] == typenums
[1]);
2733 /* A semicolon should now follow; skip it. */
2737 /* The remaining two operands are usually lower and upper bounds
2738 of the range. But in some special cases they mean something else. */
2739 read_huge_number (pp
, ';', &n2
, &n2bits
);
2740 read_huge_number (pp
, ';', &n3
, &n3bits
);
2742 if (n2bits
== -1 || n3bits
== -1)
2743 return error_type (pp
);
2745 /* If limits are huge, must be large integral type. */
2746 if (n2bits
!= 0 || n3bits
!= 0)
2748 char got_signed
= 0;
2749 char got_unsigned
= 0;
2750 /* Number of bits in the type. */
2753 /* Range from 0 to <large number> is an unsigned large integral type. */
2754 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2759 /* Range from <large number> to <large number>-1 is a large signed
2761 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2767 /* Check for "long long". */
2768 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2769 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2770 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2771 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2773 if (got_signed
|| got_unsigned
)
2775 result_type
= alloc_type (objfile
);
2776 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2777 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2779 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2783 return error_type (pp
);
2786 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2787 if (self_subrange
&& n2
== 0 && n3
== 0)
2788 return (lookup_fundamental_type (objfile
, FT_VOID
));
2790 /* If n3 is zero and n2 is not, we want a floating type,
2791 and n2 is the width in bytes.
2793 Fortran programs appear to use this for complex types also,
2794 and they give no way to distinguish between double and single-complex!
2795 We don't have complex types, so we would lose on all fortran files!
2796 So return type `double' for all of those. It won't work right
2797 for the complex values, but at least it makes the file loadable.
2799 FIXME, we may be able to distinguish these by their names. FIXME. */
2801 if (n3
== 0 && n2
> 0)
2803 if (n2
== sizeof (float))
2804 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
2805 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
2808 /* If the upper bound is -1, it must really be an unsigned int. */
2810 else if (n2
== 0 && n3
== -1)
2812 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2813 long' is to look at its name! */
2815 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2816 long_kludge_name
[9] == 'l' /* long */)
2817 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2818 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2820 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2823 /* Special case: char is defined (Who knows why) as a subrange of
2824 itself with range 0-127. */
2825 else if (self_subrange
&& n2
== 0 && n3
== 127)
2826 return (lookup_fundamental_type (objfile
, FT_CHAR
));
2828 /* Assumptions made here: Subrange of self is equivalent to subrange
2829 of int. FIXME: Host and target type-sizes assumed the same. */
2830 /* FIXME: This is the *only* place in GDB that depends on comparing
2831 some type to a builtin type with ==. Fix it! */
2833 && (self_subrange
||
2834 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
2836 /* an unsigned type */
2838 if (n3
== - sizeof (long long))
2839 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2841 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2842 long' is to look at its name! */
2843 if (n3
== (unsigned long)~0L &&
2844 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2845 long_kludge_name
[9] == 'l' /* long */)
2846 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2847 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2848 if (n3
== (unsigned int)~0L)
2849 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2850 if (n3
== (unsigned short)~0L)
2851 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
2852 if (n3
== (unsigned char)~0L)
2853 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
2856 else if (n3
== 0 && n2
== -sizeof (long long))
2857 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2859 else if (n2
== -n3
-1)
2862 /* FIXME -- the only way to distinguish `int' from `long' is to look
2864 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2865 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2866 return (lookup_fundamental_type (objfile
, FT_LONG
));
2867 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2868 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
2869 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
2870 return (lookup_fundamental_type (objfile
, FT_SHORT
));
2871 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
2872 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
2875 /* We have a real range type on our hands. Allocate space and
2876 return a real pointer. */
2878 /* At this point I don't have the faintest idea how to deal with
2879 a self_subrange type; I'm going to assume that this is used
2880 as an idiom, and that all of them are special cases. So . . . */
2882 return error_type (pp
);
2884 index_type
= *dbx_lookup_type (rangenums
);
2885 if (index_type
== NULL
)
2887 complain (&range_type_base_complaint
, rangenums
[1]);
2888 index_type
= lookup_fundamental_type (objfile
, FT_INTEGER
);
2891 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
2892 return (result_type
);
2895 /* Read a number from the string pointed to by *PP.
2896 The value of *PP is advanced over the number.
2897 If END is nonzero, the character that ends the
2898 number must match END, or an error happens;
2899 and that character is skipped if it does match.
2900 If END is zero, *PP is left pointing to that character. */
2903 read_number (pp
, end
)
2907 register char *p
= *pp
;
2908 register long n
= 0;
2912 /* Handle an optional leading minus sign. */
2920 /* Read the digits, as far as they go. */
2922 while ((c
= *p
++) >= '0' && c
<= '9')
2930 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
2939 /* Read in an argument list. This is a list of types, separated by commas
2940 and terminated with END. Return the list of types read in, or (struct type
2941 **)-1 if there is an error. */
2943 static struct type
**
2944 read_args (pp
, end
, objfile
)
2947 struct objfile
*objfile
;
2949 /* FIXME! Remove this arbitrary limit! */
2950 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
2956 /* Invalid argument list: no ','. */
2957 return (struct type
**)-1;
2959 STABS_CONTINUE (pp
);
2960 types
[n
++] = read_type (pp
, objfile
);
2962 (*pp
)++; /* get past `end' (the ':' character) */
2966 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
2968 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
2970 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
2971 memset (rval
+ n
, 0, sizeof (struct type
*));
2975 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
2977 memcpy (rval
, types
, n
* sizeof (struct type
*));
2981 /* Add a common block's start address to the offset of each symbol
2982 declared to be in it (by being between a BCOMM/ECOMM pair that uses
2983 the common block name). */
2986 fix_common_block (sym
, valu
)
2990 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
2991 for ( ; next
; next
= next
->next
)
2994 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
2995 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3001 /* What about types defined as forward references inside of a small lexical
3003 /* Add a type to the list of undefined types to be checked through
3004 once this file has been read in. */
3007 add_undefined_type (type
)
3010 if (undef_types_length
== undef_types_allocated
)
3012 undef_types_allocated
*= 2;
3013 undef_types
= (struct type
**)
3014 xrealloc ((char *) undef_types
,
3015 undef_types_allocated
* sizeof (struct type
*));
3017 undef_types
[undef_types_length
++] = type
;
3020 /* Go through each undefined type, see if it's still undefined, and fix it
3021 up if possible. We have two kinds of undefined types:
3023 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3024 Fix: update array length using the element bounds
3025 and the target type's length.
3026 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3027 yet defined at the time a pointer to it was made.
3028 Fix: Do a full lookup on the struct/union tag. */
3030 cleanup_undefined_types ()
3034 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3036 switch (TYPE_CODE (*type
))
3039 case TYPE_CODE_STRUCT
:
3040 case TYPE_CODE_UNION
:
3041 case TYPE_CODE_ENUM
:
3043 /* Check if it has been defined since. */
3044 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3046 struct pending
*ppt
;
3048 /* Name of the type, without "struct" or "union" */
3049 char *typename
= TYPE_NAME (*type
);
3051 if (!strncmp (typename
, "struct ", 7))
3053 if (!strncmp (typename
, "union ", 6))
3055 if (!strncmp (typename
, "enum ", 5))
3058 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3060 for (i
= 0; i
< ppt
->nsyms
; i
++)
3062 struct symbol
*sym
= ppt
->symbol
[i
];
3064 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3065 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3066 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3068 && STREQ (SYMBOL_NAME (sym
), typename
))
3070 memcpy (*type
, SYMBOL_TYPE (sym
),
3071 sizeof (struct type
));
3079 case TYPE_CODE_ARRAY
:
3081 struct type
*range_type
;
3084 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3086 if (TYPE_NFIELDS (*type
) != 1)
3088 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3089 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3092 /* Now recompute the length of the array type, based on its
3093 number of elements and the target type's length. */
3094 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3095 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3096 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3097 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3103 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type
));
3107 undef_types_length
= 0;
3110 /* Scan through all of the global symbols defined in the object file,
3111 assigning values to the debugging symbols that need to be assigned
3112 to. Get these symbols from the minimal symbol table. */
3115 scan_file_globals (objfile
)
3116 struct objfile
*objfile
;
3119 struct minimal_symbol
*msymbol
;
3120 struct symbol
*sym
, *prev
;
3122 if (objfile
->msymbols
== 0) /* Beware the null file. */
3125 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3131 /* Get the hash index and check all the symbols
3132 under that hash index. */
3134 hash
= hashname (SYMBOL_NAME (msymbol
));
3136 for (sym
= global_sym_chain
[hash
]; sym
;)
3138 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3139 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3141 /* Splice this symbol out of the hash chain and
3142 assign the value we have to it. */
3145 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3149 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3152 /* Check to see whether we need to fix up a common block. */
3153 /* Note: this code might be executed several times for
3154 the same symbol if there are multiple references. */
3156 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3158 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3162 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3167 sym
= SYMBOL_VALUE_CHAIN (prev
);
3171 sym
= global_sym_chain
[hash
];
3177 sym
= SYMBOL_VALUE_CHAIN (sym
);
3183 /* Initialize anything that needs initializing when starting to read
3184 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3192 /* Initialize anything that needs initializing when a completely new
3193 symbol file is specified (not just adding some symbols from another
3194 file, e.g. a shared library). */
3197 stabsread_new_init ()
3199 /* Empty the hash table of global syms looking for values. */
3200 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3203 /* Initialize anything that needs initializing at the same time as
3204 start_symtab() is called. */
3208 global_stabs
= NULL
; /* AIX COFF */
3209 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3210 n_this_object_header_files
= 1;
3211 type_vector_length
= 0;
3212 type_vector
= (struct type
**) 0;
3215 /* Call after end_symtab() */
3221 free ((char *) type_vector
);
3224 type_vector_length
= 0;
3225 previous_stab_code
= 0;
3229 finish_global_stabs (objfile
)
3230 struct objfile
*objfile
;
3234 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3235 free ((PTR
) global_stabs
);
3236 global_stabs
= NULL
;
3240 /* Initializer for this module */
3243 _initialize_stabsread ()
3245 undef_types_allocated
= 20;
3246 undef_types_length
= 0;
3247 undef_types
= (struct type
**)
3248 xmalloc (undef_types_allocated
* sizeof (struct type
*));