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 ((int));
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
);
266 /* Caller wants address of address of type. We think
267 that negative (rs6k builtin) types will never appear as
268 "lvalues", (nor should they), so we stuff the real type
269 pointer into a temp, and return its address. If referenced,
270 this will do the right thing. */
271 static struct type
*temp_type
;
273 temp_type
= rs6000_builtin_type(index
);
277 /* Type is defined outside of header files.
278 Find it in this object file's type vector. */
279 if (index
>= type_vector_length
)
281 old_len
= type_vector_length
;
284 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
285 type_vector
= (struct type
**)
286 malloc (type_vector_length
* sizeof (struct type
*));
288 while (index
>= type_vector_length
)
290 type_vector_length
*= 2;
292 type_vector
= (struct type
**)
293 xrealloc ((char *) type_vector
,
294 (type_vector_length
* sizeof (struct type
*)));
295 memset (&type_vector
[old_len
], 0,
296 (type_vector_length
- old_len
) * sizeof (struct type
*));
298 return (&type_vector
[index
]);
302 real_filenum
= this_object_header_files
[filenum
];
304 if (real_filenum
>= n_header_files
)
309 f
= &header_files
[real_filenum
];
311 f_orig_length
= f
->length
;
312 if (index
>= f_orig_length
)
314 while (index
>= f
->length
)
318 f
->vector
= (struct type
**)
319 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
320 memset (&f
->vector
[f_orig_length
], 0,
321 (f
->length
- f_orig_length
) * sizeof (struct type
*));
323 return (&f
->vector
[index
]);
327 /* Make sure there is a type allocated for type numbers TYPENUMS
328 and return the type object.
329 This can create an empty (zeroed) type object.
330 TYPENUMS may be (-1, -1) to return a new type object that is not
331 put into the type vector, and so may not be referred to by number. */
334 dbx_alloc_type (typenums
, objfile
)
336 struct objfile
*objfile
;
338 register struct type
**type_addr
;
340 if (typenums
[0] == -1)
342 return (alloc_type (objfile
));
345 type_addr
= dbx_lookup_type (typenums
);
347 /* If we are referring to a type not known at all yet,
348 allocate an empty type for it.
349 We will fill it in later if we find out how. */
352 *type_addr
= alloc_type (objfile
);
358 /* for all the stabs in a given stab vector, build appropriate types
359 and fix their symbols in given symbol vector. */
362 patch_block_stabs (symbols
, stabs
, objfile
)
363 struct pending
*symbols
;
364 struct pending_stabs
*stabs
;
365 struct objfile
*objfile
;
375 /* for all the stab entries, find their corresponding symbols and
376 patch their types! */
378 for (ii
= 0; ii
< stabs
->count
; ++ii
)
380 name
= stabs
->stab
[ii
];
381 pp
= (char*) strchr (name
, ':');
382 sym
= find_symbol_in_list (symbols
, name
, pp
-name
);
385 /* On xcoff, if a global is defined and never referenced,
386 ld will remove it from the executable. There is then
387 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
388 sym
= (struct symbol
*)
389 obstack_alloc (&objfile
->symbol_obstack
,
390 sizeof (struct symbol
));
392 memset (sym
, 0, sizeof (struct symbol
));
393 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
394 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
396 obstack_copy0 (&objfile
->symbol_obstack
, name
, pp
- name
);
398 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
400 /* I don't think the linker does this with functions,
401 so as far as I know this is never executed.
402 But it doesn't hurt to check. */
404 lookup_function_type (read_type (&pp
, objfile
));
408 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
410 add_symbol_to_list (sym
, &global_symbols
);
415 if (*(pp
-1) == 'F' || *(pp
-1) == 'f')
418 lookup_function_type (read_type (&pp
, objfile
));
422 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
430 /* Read a number by which a type is referred to in dbx data,
431 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
432 Just a single number N is equivalent to (0,N).
433 Return the two numbers by storing them in the vector TYPENUMS.
434 TYPENUMS will then be used as an argument to dbx_lookup_type. */
437 read_type_number (pp
, typenums
)
439 register int *typenums
;
444 typenums
[0] = read_number (pp
, ',');
445 typenums
[1] = read_number (pp
, ')');
450 typenums
[1] = read_number (pp
, 0);
455 /* To handle GNU C++ typename abbreviation, we need to be able to
456 fill in a type's name as soon as space for that type is allocated.
457 `type_synonym_name' is the name of the type being allocated.
458 It is cleared as soon as it is used (lest all allocated types
461 static char *type_synonym_name
;
465 define_symbol (valu
, string
, desc
, type
, objfile
)
470 struct objfile
*objfile
;
472 register struct symbol
*sym
;
473 char *p
= (char *) strchr (string
, ':');
477 struct type
*temptype
;
479 /* We would like to eliminate nameless symbols, but keep their types.
480 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
481 to type 2, but, should not create a symbol to address that type. Since
482 the symbol will be nameless, there is no way any user can refer to it. */
486 /* Ignore syms with empty names. */
490 /* Ignore old-style symbols from cc -go */
494 /* If a nameless stab entry, all we need is the type, not the symbol.
495 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
496 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
498 sym
= (struct symbol
*)
499 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
500 memset (sym
, 0, sizeof (struct symbol
));
502 if (processing_gcc_compilation
)
504 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
505 number of bytes occupied by a type or object, which we ignore. */
506 SYMBOL_LINE(sym
) = desc
;
510 SYMBOL_LINE(sym
) = 0; /* unknown */
513 if (string
[0] == CPLUS_MARKER
)
515 /* Special GNU C++ names. */
519 SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
520 &objfile
-> symbol_obstack
);
523 case 'v': /* $vtbl_ptr_type */
524 /* Was: SYMBOL_NAME (sym) = "vptr"; */
528 SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
529 &objfile
-> symbol_obstack
);
533 /* This was an anonymous type that was never fixed up. */
537 complain (unrecognized_cplus_name_complaint
, string
);
538 goto normal
; /* Do *something* with it */
544 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
545 SYMBOL_NAME (sym
) = (char *)
546 obstack_alloc (&objfile
-> symbol_obstack
, ((p
- string
) + 1));
547 /* Open-coded bcopy--saves function call time. */
548 /* FIXME: Does it really? Try replacing with simple strcpy and
549 try it on an executable with a large symbol table. */
551 register char *p1
= string
;
552 register char *p2
= SYMBOL_NAME (sym
);
560 /* If this symbol is from a C++ compilation, then attempt to cache the
561 demangled form for future reference. This is a typical time versus
562 space tradeoff, that was decided in favor of time because it sped up
563 C++ symbol lookups by a factor of about 20. */
565 SYMBOL_INIT_DEMANGLED_NAME (sym
, &objfile
->symbol_obstack
);
569 /* Determine the type of name being defined. */
570 /* The Acorn RISC machine's compiler can put out locals that don't
571 start with "234=" or "(3,4)=", so assume anything other than the
572 deftypes we know how to handle is a local. */
573 if (!strchr ("cfFGpPrStTvVXCR", *p
))
578 /* c is a special case, not followed by a type-number.
579 SYMBOL:c=iVALUE for an integer constant symbol.
580 SYMBOL:c=rVALUE for a floating constant symbol.
581 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
582 e.g. "b:c=e6,0" for "const b = blob1"
583 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
587 error ("Invalid symbol data at symtab pos %d.", symnum
);
595 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
598 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (double));
599 memcpy (dbl_valu
, &d
, sizeof (double));
600 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
601 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
602 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
607 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
609 SYMBOL_VALUE (sym
) = atoi (p
);
610 SYMBOL_CLASS (sym
) = LOC_CONST
;
614 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
615 e.g. "b:c=e6,0" for "const b = blob1"
616 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
620 read_type_number (&p
, typenums
);
622 error ("Invalid symbol data: no comma in enum const symbol");
624 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
625 SYMBOL_VALUE (sym
) = atoi (p
);
626 SYMBOL_CLASS (sym
) = LOC_CONST
;
630 error ("Invalid symbol data at symtab pos %d.", symnum
);
632 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
633 add_symbol_to_list (sym
, &file_symbols
);
637 /* Now usually comes a number that says which data type,
638 and possibly more stuff to define the type
639 (all of which is handled by read_type) */
641 if (deftype
== 'p' && *p
== 'F')
642 /* pF is a two-letter code that means a function parameter in Fortran.
643 The type-number specifies the type of the return value.
644 Translate it into a pointer-to-function type. */
648 = lookup_pointer_type (lookup_function_type (read_type (&p
, objfile
)));
652 /* The symbol class letter is followed by a type (typically the
653 type of the symbol, or its return-type, or etc). Read it. */
660 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
661 strlen (SYMBOL_NAME (sym
)),
662 &objfile
-> symbol_obstack
);
665 /* Here we save the name of the symbol for read_range_type, which
666 ends up reading in the basic types. In stabs, unfortunately there
667 is no distinction between "int" and "long" types except their
668 names. Until we work out a saner type policy (eliminating most
669 builtin types and using the names specified in the files), we
670 save away the name so that far away from here in read_range_type,
671 we can examine it to decide between "int" and "long". FIXME. */
672 long_kludge_name
= SYMBOL_NAME (sym
);
674 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
680 /* The name of a caught exception. */
681 SYMBOL_CLASS (sym
) = LOC_LABEL
;
682 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
683 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
684 add_symbol_to_list (sym
, &local_symbols
);
688 /* A static function definition. */
689 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
690 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
691 add_symbol_to_list (sym
, &file_symbols
);
692 /* fall into process_function_types. */
694 process_function_types
:
695 /* Function result types are described as the result type in stabs.
696 We need to convert this to the function-returning-type-X type
697 in GDB. E.g. "int" is converted to "function returning int". */
698 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
701 /* This code doesn't work -- it needs to realloc and can't. */
702 /* Attempt to set up to record a function prototype... */
703 struct type
*new = alloc_type (objfile
);
705 /* Generate a template for the type of this function. The
706 types of the arguments will be added as we read the symbol
708 *new = *lookup_function_type (SYMBOL_TYPE(sym
));
709 SYMBOL_TYPE(sym
) = new;
710 TYPE_OBJFILE (new) = objfile
;
711 in_function_type
= new;
713 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
716 /* fall into process_prototype_types */
718 process_prototype_types
:
719 /* Sun acc puts declared types of arguments here. We don't care
720 about their actual types (FIXME -- we should remember the whole
721 function prototype), but the list may define some new types
722 that we have to remember, so we must scan it now. */
725 read_type (&p
, objfile
);
730 /* A global function definition. */
731 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
732 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
733 add_symbol_to_list (sym
, &global_symbols
);
734 goto process_function_types
;
737 /* For a class G (global) symbol, it appears that the
738 value is not correct. It is necessary to search for the
739 corresponding linker definition to find the value.
740 These definitions appear at the end of the namelist. */
741 i
= hashname (SYMBOL_NAME (sym
));
742 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
743 global_sym_chain
[i
] = sym
;
744 SYMBOL_CLASS (sym
) = LOC_STATIC
;
745 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
746 add_symbol_to_list (sym
, &global_symbols
);
749 /* This case is faked by a conditional above,
750 when there is no code letter in the dbx data.
751 Dbx data never actually contains 'l'. */
753 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
754 SYMBOL_VALUE (sym
) = valu
;
755 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
756 add_symbol_to_list (sym
, &local_symbols
);
760 /* Normally this is a parameter, a LOC_ARG. On the i960, it
761 can also be a LOC_LOCAL_ARG depending on symbol type. */
762 #ifndef DBX_PARM_SYMBOL_CLASS
763 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
765 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
766 SYMBOL_VALUE (sym
) = valu
;
767 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
769 /* This doesn't work yet. */
770 add_param_to_type (&in_function_type
, sym
);
772 add_symbol_to_list (sym
, &local_symbols
);
774 /* If it's gcc-compiled, if it says `short', believe it. */
775 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
778 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
779 /* This macro is defined on machines (e.g. sparc) where
780 we should believe the type of a PCC 'short' argument,
781 but shouldn't believe the address (the address is
782 the address of the corresponding int). Note that
783 this is only different from the BELIEVE_PCC_PROMOTION
784 case on big-endian machines.
786 My guess is that this correction, as opposed to changing
787 the parameter to an 'int' (as done below, for PCC
788 on most machines), is the right thing to do
789 on all machines, but I don't want to risk breaking
790 something that already works. On most PCC machines,
791 the sparc problem doesn't come up because the calling
792 function has to zero the top bytes (not knowing whether
793 the called function wants an int or a short), so there
794 is no practical difference between an int and a short
795 (except perhaps what happens when the GDB user types
796 "print short_arg = 0x10000;").
798 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
799 actually produces the correct address (we don't need to fix it
800 up). I made this code adapt so that it will offset the symbol
801 if it was pointing at an int-aligned location and not
802 otherwise. This way you can use the same gdb for 4.0.x and
805 If the parameter is shorter than an int, and is integral
806 (e.g. char, short, or unsigned equivalent), and is claimed to
807 be passed on an integer boundary, don't believe it! Offset the
808 parameter's address to the tail-end of that integer. */
810 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
811 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
812 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
813 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (temptype
))
815 SYMBOL_VALUE (sym
) += TYPE_LENGTH (temptype
)
816 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
820 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
822 /* If PCC says a parameter is a short or a char,
823 it is really an int. */
824 temptype
= lookup_fundamental_type (objfile
, FT_INTEGER
);
825 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (temptype
)
826 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
828 SYMBOL_TYPE (sym
) = TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
829 ? lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
)
834 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
838 /* acc seems to use P to delare the prototypes of functions that
839 are referenced by this file. gdb is not prepared to deal
840 with this extra information. FIXME, it ought to. */
842 goto process_prototype_types
;
844 /* Parameter which is in a register. */
845 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
846 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
847 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
849 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
850 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
852 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
853 add_symbol_to_list (sym
, &local_symbols
);
857 /* Register variable (either global or local). */
858 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
859 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
860 if (SYMBOL_VALUE (sym
) >= NUM_REGS
)
862 complain (®_value_complaint
, SYMBOL_SOURCE_NAME (sym
));
863 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
865 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
867 add_symbol_to_list (sym
, &local_symbols
);
869 add_symbol_to_list (sym
, &file_symbols
);
873 /* Static symbol at top level of file */
874 SYMBOL_CLASS (sym
) = LOC_STATIC
;
875 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
876 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
877 add_symbol_to_list (sym
, &file_symbols
);
881 /* For a nameless type, we don't want a create a symbol, thus we
882 did not use `sym'. Return without further processing. */
883 if (nameless
) return NULL
;
885 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
886 SYMBOL_VALUE (sym
) = valu
;
887 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
888 /* C++ vagaries: we may have a type which is derived from
889 a base type which did not have its name defined when the
890 derived class was output. We fill in the derived class's
891 base part member's name here in that case. */
892 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
893 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
894 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
895 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
898 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
899 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
900 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
901 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
904 add_symbol_to_list (sym
, &file_symbols
);
908 /* For a nameless type, we don't want a create a symbol, thus we
909 did not use `sym'. Return without further processing. */
910 if (nameless
) return NULL
;
912 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
913 SYMBOL_VALUE (sym
) = valu
;
914 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
915 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
916 TYPE_NAME (SYMBOL_TYPE (sym
))
917 = obconcat (&objfile
-> type_obstack
, "",
918 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
920 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
921 ? "struct " : "union ")),
923 add_symbol_to_list (sym
, &file_symbols
);
927 /* Clone the sym and then modify it. */
928 register struct symbol
*typedef_sym
= (struct symbol
*)
929 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
931 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
932 SYMBOL_VALUE (typedef_sym
) = valu
;
933 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
934 add_symbol_to_list (typedef_sym
, &file_symbols
);
939 /* Static symbol of local scope */
940 SYMBOL_CLASS (sym
) = LOC_STATIC
;
941 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
942 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
943 add_symbol_to_list (sym
, &local_symbols
);
947 /* Reference parameter */
948 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
949 SYMBOL_VALUE (sym
) = valu
;
950 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
951 add_symbol_to_list (sym
, &local_symbols
);
955 /* This is used by Sun FORTRAN for "function result value".
956 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
957 that Pascal uses it too, but when I tried it Pascal used
958 "x:3" (local symbol) instead. */
959 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
960 SYMBOL_VALUE (sym
) = valu
;
961 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
962 add_symbol_to_list (sym
, &local_symbols
);
966 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
972 /* Skip rest of this symbol and return an error type.
974 General notes on error recovery: error_type always skips to the
975 end of the symbol (modulo cretinous dbx symbol name continuation).
979 return error_type (pp);
981 is wrong because if *pp starts out pointing at '\0' (typically as the
982 result of an earlier error), it will be incremented to point to the
983 start of the next symbol, which might produce strange results, at least
984 if you run off the end of the string table. Instead use
987 return error_type (pp);
993 foo = error_type (pp);
997 And in case it isn't obvious, the point of all this hair is so the compiler
998 can define new types and new syntaxes, and old versions of the
999 debugger will be able to read the new symbol tables. */
1005 complain (&error_type_complaint
);
1008 /* Skip to end of symbol. */
1009 while (**pp
!= '\0')
1014 /* Check for and handle cretinous dbx symbol name continuation! */
1015 if ((*pp
)[-1] == '\\')
1017 *pp
= next_symbol_text ();
1024 return (builtin_type_error
);
1028 /* Read a dbx type reference or definition;
1029 return the type that is meant.
1030 This can be just a number, in which case it references
1031 a type already defined and placed in type_vector.
1032 Or the number can be followed by an =, in which case
1033 it means to define a new type according to the text that
1037 read_type (pp
, objfile
)
1039 struct objfile
*objfile
;
1041 register struct type
*type
= 0;
1045 char type_descriptor
;
1047 /* Read type number if present. The type number may be omitted.
1048 for instance in a two-dimensional array declared with type
1049 "ar1;1;10;ar1;1;10;4". */
1050 if ((**pp
>= '0' && **pp
<= '9')
1053 read_type_number (pp
, typenums
);
1055 /* Type is not being defined here. Either it already exists,
1056 or this is a forward reference to it. dbx_alloc_type handles
1059 return dbx_alloc_type (typenums
, objfile
);
1061 /* Type is being defined here. */
1062 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1066 /* if such a type already exists, this is an unnecessary duplication
1067 of the stab string, which is common in (RS/6000) xlc generated
1068 objects. In that case, simply return NULL and let the caller take
1071 tt
= *dbx_lookup_type (typenums
);
1072 if (tt
&& tt
->length
&& tt
->code
)
1081 /* 'typenums=' not present, type is anonymous. Read and return
1082 the definition, but don't put it in the type vector. */
1083 typenums
[0] = typenums
[1] = -1;
1087 type_descriptor
= (*pp
)[-1];
1088 switch (type_descriptor
)
1092 enum type_code code
;
1094 /* Used to index through file_symbols. */
1095 struct pending
*ppt
;
1098 /* Name including "struct", etc. */
1101 /* Name without "struct", etc. */
1102 char *type_name_only
;
1108 /* Set the type code according to the following letter. */
1112 code
= TYPE_CODE_STRUCT
;
1116 code
= TYPE_CODE_UNION
;
1120 code
= TYPE_CODE_ENUM
;
1124 return error_type (pp
);
1127 to
= type_name
= (char *)
1128 obstack_alloc (&objfile
-> type_obstack
,
1130 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1132 /* Copy the prefix. */
1134 while ((*to
++ = *from
++) != '\0')
1138 type_name_only
= to
;
1140 /* Copy the name. */
1142 while ((*to
++ = *from
++) != ':')
1146 /* Set the pointer ahead of the name which we just read. */
1150 /* The following hack is clearly wrong, because it doesn't
1151 check whether we are in a baseclass. I tried to reproduce
1152 the case that it is trying to fix, but I couldn't get
1153 g++ to put out a cross reference to a basetype. Perhaps
1154 it doesn't do it anymore. */
1155 /* Note: for C++, the cross reference may be to a base type which
1156 has not yet been seen. In this case, we skip to the comma,
1157 which will mark the end of the base class name. (The ':'
1158 at the end of the base class name will be skipped as well.)
1159 But sometimes (ie. when the cross ref is the last thing on
1160 the line) there will be no ','. */
1161 from
= (char *) strchr (*pp
, ',');
1167 /* Now check to see whether the type has already been declared. */
1168 /* This is necessary at least in the case where the
1169 program says something like
1171 The compiler puts out a cross-reference; we better find
1172 set the length of the structure correctly so we can
1173 set the length of the array. */
1174 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1175 for (i
= 0; i
< ppt
->nsyms
; i
++)
1177 struct symbol
*sym
= ppt
->symbol
[i
];
1179 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1180 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1181 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1182 && STREQ (SYMBOL_NAME (sym
), type_name_only
))
1184 obstack_free (&objfile
-> type_obstack
, type_name
);
1185 type
= SYMBOL_TYPE (sym
);
1190 /* Didn't find the type to which this refers, so we must
1191 be dealing with a forward reference. Allocate a type
1192 structure for it, and keep track of it so we can
1193 fill in the rest of the fields when we get the full
1195 type
= dbx_alloc_type (typenums
, objfile
);
1196 TYPE_CODE (type
) = code
;
1197 TYPE_NAME (type
) = type_name
;
1198 INIT_CPLUS_SPECIFIC(type
);
1199 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1201 add_undefined_type (type
);
1205 case '-': /* RS/6000 built-in type */
1218 read_type_number (pp
, xtypenums
);
1219 type
= *dbx_lookup_type (xtypenums
);
1221 type
= lookup_fundamental_type (objfile
, FT_VOID
);
1222 if (typenums
[0] != -1)
1223 *dbx_lookup_type (typenums
) = type
;
1226 /* In the following types, we must be sure to overwrite any existing
1227 type that the typenums refer to, rather than allocating a new one
1228 and making the typenums point to the new one. This is because there
1229 may already be pointers to the existing type (if it had been
1230 forward-referenced), and we must change it to a pointer, function,
1231 reference, or whatever, *in-place*. */
1234 type1
= read_type (pp
, objfile
);
1235 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1238 case '&': /* Reference to another type */
1239 type1
= read_type (pp
, objfile
);
1240 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1243 case 'f': /* Function returning another type */
1244 type1
= read_type (pp
, objfile
);
1245 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1248 case 'k': /* Const qualifier on some type (Sun) */
1249 type
= read_type (pp
, objfile
);
1250 /* FIXME! For now, we ignore const and volatile qualifiers. */
1253 case 'B': /* Volatile qual on some type (Sun) */
1254 type
= read_type (pp
, objfile
);
1255 /* FIXME! For now, we ignore const and volatile qualifiers. */
1258 /* FIXME -- we should be doing smash_to_XXX types here. */
1259 case '@': /* Member (class & variable) type */
1261 struct type
*domain
= read_type (pp
, objfile
);
1262 struct type
*memtype
;
1265 /* Invalid member type data format. */
1266 return error_type (pp
);
1269 memtype
= read_type (pp
, objfile
);
1270 type
= dbx_alloc_type (typenums
, objfile
);
1271 smash_to_member_type (type
, domain
, memtype
);
1275 case '#': /* Method (class & fn) type */
1276 if ((*pp
)[0] == '#')
1278 /* We'll get the parameter types from the name. */
1279 struct type
*return_type
;
1282 return_type
= read_type (pp
, objfile
);
1283 if (*(*pp
)++ != ';')
1284 complain (&invalid_member_complaint
, symnum
);
1285 type
= allocate_stub_method (return_type
);
1286 if (typenums
[0] != -1)
1287 *dbx_lookup_type (typenums
) = type
;
1291 struct type
*domain
= read_type (pp
, objfile
);
1292 struct type
*return_type
;
1295 if (*(*pp
)++ != ',')
1296 error ("invalid member type data format, at symtab pos %d.",
1299 return_type
= read_type (pp
, objfile
);
1300 args
= read_args (pp
, ';', objfile
);
1301 type
= dbx_alloc_type (typenums
, objfile
);
1302 smash_to_method_type (type
, domain
, return_type
, args
);
1306 case 'r': /* Range type */
1307 type
= read_range_type (pp
, typenums
, objfile
);
1308 if (typenums
[0] != -1)
1309 *dbx_lookup_type (typenums
) = type
;
1312 case 'b': /* Sun ACC builtin int type */
1313 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1314 if (typenums
[0] != -1)
1315 *dbx_lookup_type (typenums
) = type
;
1318 case 'R': /* Sun ACC builtin float type */
1319 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1320 if (typenums
[0] != -1)
1321 *dbx_lookup_type (typenums
) = type
;
1324 case 'e': /* Enumeration type */
1325 type
= dbx_alloc_type (typenums
, objfile
);
1326 type
= read_enum_type (pp
, type
, objfile
);
1327 *dbx_lookup_type (typenums
) = type
;
1330 case 's': /* Struct type */
1331 case 'u': /* Union type */
1332 type
= dbx_alloc_type (typenums
, objfile
);
1333 if (!TYPE_NAME (type
))
1335 TYPE_NAME (type
) = type_synonym_name
;
1337 type_synonym_name
= NULL
;
1338 switch (type_descriptor
)
1341 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1344 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1347 type
= read_struct_type (pp
, type
, objfile
);
1350 case 'a': /* Array type */
1352 return error_type (pp
);
1355 type
= dbx_alloc_type (typenums
, objfile
);
1356 type
= read_array_type (pp
, type
, objfile
);
1360 --*pp
; /* Go back to the symbol in error */
1361 /* Particularly important if it was \0! */
1362 return error_type (pp
);
1371 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1372 Return the proper type node for a given builtin type number. */
1374 static struct type
*
1375 rs6000_builtin_type (typenum
)
1378 /* default types are defined in dbxstclass.h. */
1381 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1383 return lookup_fundamental_type (current_objfile
, FT_CHAR
);
1385 return lookup_fundamental_type (current_objfile
, FT_SHORT
);
1387 return lookup_fundamental_type (current_objfile
, FT_LONG
);
1389 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_CHAR
);
1391 return lookup_fundamental_type (current_objfile
, FT_SIGNED_CHAR
);
1393 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_SHORT
);
1395 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1397 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_INTEGER
);
1399 return lookup_fundamental_type (current_objfile
, FT_UNSIGNED_LONG
);
1401 return lookup_fundamental_type (current_objfile
, FT_VOID
);
1403 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1405 return lookup_fundamental_type (current_objfile
, FT_DBL_PREC_FLOAT
);
1407 return lookup_fundamental_type (current_objfile
, FT_EXT_PREC_FLOAT
);
1409 /* requires a builtin `integer' */
1410 return lookup_fundamental_type (current_objfile
, FT_INTEGER
);
1412 return lookup_fundamental_type (current_objfile
, FT_BOOLEAN
);
1414 /* requires builtin `short real' */
1415 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1417 /* requires builtin `real' */
1418 return lookup_fundamental_type (current_objfile
, FT_FLOAT
);
1420 complain (rs6000_builtin_complaint
, typenum
);
1425 /* This page contains subroutines of read_type. */
1427 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1428 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1429 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1431 /* Read member function stabs info for C++ classes. The form of each member
1434 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1436 An example with two member functions is:
1438 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1440 For the case of overloaded operators, the format is op$::*.funcs, where
1441 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1442 name (such as `+=') and `.' marks the end of the operator name. */
1445 read_member_functions (fip
, pp
, type
, objfile
)
1446 struct field_info
*fip
;
1449 struct objfile
*objfile
;
1453 /* Total number of member functions defined in this class. If the class
1454 defines two `f' functions, and one `g' function, then this will have
1456 int total_length
= 0;
1460 struct next_fnfield
*next
;
1461 struct fn_field fn_field
;
1463 struct type
*look_ahead_type
;
1464 struct next_fnfieldlist
*new_fnlist
;
1465 struct next_fnfield
*new_sublist
;
1469 /* Process each list until we find something that is not a member function
1470 or find the end of the functions. */
1474 /* We should be positioned at the start of the function name.
1475 Scan forward to find the first ':' and if it is not the
1476 first of a "::" delimiter, then this is not a member function. */
1488 look_ahead_type
= NULL
;
1491 new_fnlist
= (struct next_fnfieldlist
*)
1492 xmalloc (sizeof (struct next_fnfieldlist
));
1493 make_cleanup (free
, new_fnlist
);
1494 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
1496 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1498 /* This is a completely wierd case. In order to stuff in the
1499 names that might contain colons (the usual name delimiter),
1500 Mike Tiemann defined a different name format which is
1501 signalled if the identifier is "op$". In that case, the
1502 format is "op$::XXXX." where XXXX is the name. This is
1503 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1504 /* This lets the user type "break operator+".
1505 We could just put in "+" as the name, but that wouldn't
1507 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1508 char *o
= opname
+ 3;
1510 /* Skip past '::'. */
1513 STABS_CONTINUE (pp
);
1519 main_fn_name
= savestring (opname
, o
- opname
);
1525 main_fn_name
= savestring (*pp
, p
- *pp
);
1526 /* Skip past '::'. */
1529 new_fnlist
-> fn_fieldlist
.name
= main_fn_name
;
1534 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
1535 make_cleanup (free
, new_sublist
);
1536 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
1538 /* Check for and handle cretinous dbx symbol name continuation! */
1539 if (look_ahead_type
== NULL
)
1542 STABS_CONTINUE (pp
);
1544 new_sublist
-> fn_field
.type
= read_type (pp
, objfile
);
1547 /* Invalid symtab info for member function. */
1553 /* g++ version 1 kludge */
1554 new_sublist
-> fn_field
.type
= look_ahead_type
;
1555 look_ahead_type
= NULL
;
1565 /* If this is just a stub, then we don't have the real name here. */
1567 if (TYPE_FLAGS (new_sublist
-> fn_field
.type
) & TYPE_FLAG_STUB
)
1569 if (!TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
))
1570 TYPE_DOMAIN_TYPE (new_sublist
-> fn_field
.type
) = type
;
1571 new_sublist
-> fn_field
.is_stub
= 1;
1573 new_sublist
-> fn_field
.physname
= savestring (*pp
, p
- *pp
);
1576 /* Set this member function's visibility fields. */
1579 case VISIBILITY_PRIVATE
:
1580 new_sublist
-> fn_field
.is_private
= 1;
1582 case VISIBILITY_PROTECTED
:
1583 new_sublist
-> fn_field
.is_protected
= 1;
1587 STABS_CONTINUE (pp
);
1590 case 'A': /* Normal functions. */
1591 new_sublist
-> fn_field
.is_const
= 0;
1592 new_sublist
-> fn_field
.is_volatile
= 0;
1595 case 'B': /* `const' member functions. */
1596 new_sublist
-> fn_field
.is_const
= 1;
1597 new_sublist
-> fn_field
.is_volatile
= 0;
1600 case 'C': /* `volatile' member function. */
1601 new_sublist
-> fn_field
.is_const
= 0;
1602 new_sublist
-> fn_field
.is_volatile
= 1;
1605 case 'D': /* `const volatile' member function. */
1606 new_sublist
-> fn_field
.is_const
= 1;
1607 new_sublist
-> fn_field
.is_volatile
= 1;
1610 case '*': /* File compiled with g++ version 1 -- no info */
1615 complain (&const_vol_complaint
, **pp
);
1622 /* virtual member function, followed by index.
1623 The sign bit is set to distinguish pointers-to-methods
1624 from virtual function indicies. Since the array is
1625 in words, the quantity must be shifted left by 1
1626 on 16 bit machine, and by 2 on 32 bit machine, forcing
1627 the sign bit out, and usable as a valid index into
1628 the array. Remove the sign bit here. */
1629 new_sublist
-> fn_field
.voffset
=
1630 (0x7fffffff & read_number (pp
, ';')) + 2;
1632 STABS_CONTINUE (pp
);
1633 if (**pp
== ';' || **pp
== '\0')
1635 /* Must be g++ version 1. */
1636 new_sublist
-> fn_field
.fcontext
= 0;
1640 /* Figure out from whence this virtual function came.
1641 It may belong to virtual function table of
1642 one of its baseclasses. */
1643 look_ahead_type
= read_type (pp
, objfile
);
1646 /* g++ version 1 overloaded methods. */
1650 new_sublist
-> fn_field
.fcontext
= look_ahead_type
;
1659 look_ahead_type
= NULL
;
1665 /* static member function. */
1666 new_sublist
-> fn_field
.voffset
= VOFFSET_STATIC
;
1667 if (strncmp (new_sublist
-> fn_field
.physname
,
1668 main_fn_name
, strlen (main_fn_name
)))
1670 new_sublist
-> fn_field
.is_stub
= 1;
1676 complain (&member_fn_complaint
, (*pp
)[-1]);
1677 /* Fall through into normal member function. */
1680 /* normal member function. */
1681 new_sublist
-> fn_field
.voffset
= 0;
1682 new_sublist
-> fn_field
.fcontext
= 0;
1686 new_sublist
-> next
= sublist
;
1687 sublist
= new_sublist
;
1689 STABS_CONTINUE (pp
);
1691 while (**pp
!= ';' && **pp
!= '\0');
1695 new_fnlist
-> fn_fieldlist
.fn_fields
= (struct fn_field
*)
1696 obstack_alloc (&objfile
-> type_obstack
,
1697 sizeof (struct fn_field
) * length
);
1698 memset (new_fnlist
-> fn_fieldlist
.fn_fields
, 0,
1699 sizeof (struct fn_field
) * length
);
1700 for (i
= length
; (i
--, sublist
); sublist
= sublist
-> next
)
1702 new_fnlist
-> fn_fieldlist
.fn_fields
[i
] = sublist
-> fn_field
;
1705 new_fnlist
-> fn_fieldlist
.length
= length
;
1706 new_fnlist
-> next
= fip
-> fnlist
;
1707 fip
-> fnlist
= new_fnlist
;
1709 total_length
+= length
;
1710 STABS_CONTINUE (pp
);
1715 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
1716 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
1717 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
1718 memset (TYPE_FN_FIELDLISTS (type
), 0,
1719 sizeof (struct fn_fieldlist
) * nfn_fields
);
1720 TYPE_NFN_FIELDS (type
) = nfn_fields
;
1721 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
1727 /* Special GNU C++ name.
1728 FIXME: Still need to properly handle parse error conditions. */
1731 read_cpp_abbrev (fip
, pp
, type
, objfile
)
1732 struct field_info
*fip
;
1735 struct objfile
*objfile
;
1741 struct type
*context
;
1751 /* At this point, *pp points to something like "22:23=*22...",
1752 where the type number before the ':' is the "context" and
1753 everything after is a regular type definition. Lookup the
1754 type, find it's name, and construct the field name. */
1756 context
= read_type (pp
, objfile
);
1760 case 'f': /* $vf -- a virtual function table pointer */
1761 fip
->list
->field
.name
=
1762 obconcat (&objfile
->type_obstack
, vptr_name
, "", "");
1765 case 'b': /* $vb -- a virtual bsomethingorother */
1766 name
= type_name_no_tag (context
);
1769 complain (&invalid_cpp_type_complaint
, symnum
);
1772 fip
->list
->field
.name
=
1773 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
1777 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1778 fip
->list
->field
.name
=
1779 obconcat (&objfile
->type_obstack
,
1780 "INVALID_CPLUSPLUS_ABBREV", "", "");
1784 /* At this point, *pp points to the ':'. Skip it and read the
1790 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1792 fip
->list
->field
.type
= read_type (pp
, objfile
);
1793 (*pp
)++; /* Skip the comma. */
1794 fip
->list
->field
.bitpos
= read_number (pp
, ';');
1795 /* This field is unpacked. */
1796 fip
->list
->field
.bitsize
= 0;
1797 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
1801 /* GNU C++ anonymous type. */
1802 complain (&stabs_general_complaint
, "g++ anonymous type $_ not handled");
1806 complain (&invalid_cpp_abbrev_complaint
, *pp
);
1811 read_one_struct_field (fip
, pp
, p
, type
, objfile
)
1812 struct field_info
*fip
;
1816 struct objfile
*objfile
;
1818 fip
-> list
-> field
.name
=
1819 obsavestring (*pp
, p
- *pp
, &objfile
-> type_obstack
);
1822 /* This means we have a visibility for a field coming. */
1826 fip
-> list
-> visibility
= *(*pp
)++;
1827 switch (fip
-> list
-> visibility
)
1829 case VISIBILITY_PRIVATE
:
1830 case VISIBILITY_PROTECTED
:
1833 case VISIBILITY_PUBLIC
:
1838 /* Unknown visibility specifier. */
1839 complain (&stabs_general_complaint
,
1840 "unknown visibility specifier");
1847 /* normal dbx-style format, no explicit visibility */
1848 fip
-> list
-> visibility
= VISIBILITY_PUBLIC
;
1851 fip
-> list
-> field
.type
= read_type (pp
, objfile
);
1856 /* Possible future hook for nested types. */
1859 fip
-> list
-> field
.bitpos
= (long)-2; /* nested type */
1865 /* Static class member. */
1866 fip
-> list
-> field
.bitpos
= (long) -1;
1872 fip
-> list
-> field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
1876 else if (**pp
!= ',')
1878 /* Bad structure-type format. */
1879 complain (&stabs_general_complaint
, "bad structure-type format");
1883 (*pp
)++; /* Skip the comma. */
1884 fip
-> list
-> field
.bitpos
= read_number (pp
, ',');
1885 fip
-> list
-> field
.bitsize
= read_number (pp
, ';');
1888 /* FIXME-tiemann: Can't the compiler put out something which
1889 lets us distinguish these? (or maybe just not put out anything
1890 for the field). What is the story here? What does the compiler
1891 really do? Also, patch gdb.texinfo for this case; I document
1892 it as a possible problem there. Search for "DBX-style". */
1894 /* This is wrong because this is identical to the symbols
1895 produced for GCC 0-size arrays. For example:
1900 The code which dumped core in such circumstances should be
1901 fixed not to dump core. */
1903 /* g++ -g0 can put out bitpos & bitsize zero for a static
1904 field. This does not give us any way of getting its
1905 class, so we can't know its name. But we can just
1906 ignore the field so we don't dump core and other nasty
1908 if (fip
-> list
-> field
.bitpos
== 0 && fip
-> list
-> field
.bitsize
== 0)
1910 complain (&dbx_class_complaint
);
1911 /* Ignore this field. */
1912 fip
-> list
= fip
-> list
-> next
;
1917 /* Detect an unpacked field and mark it as such.
1918 dbx gives a bit size for all fields.
1919 Note that forward refs cannot be packed,
1920 and treat enums as if they had the width of ints. */
1922 if (TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_INT
1923 && TYPE_CODE (fip
-> list
-> field
.type
) != TYPE_CODE_ENUM
)
1925 fip
-> list
-> field
.bitsize
= 0;
1927 if ((fip
-> list
-> field
.bitsize
1928 == 8 * TYPE_LENGTH (fip
-> list
-> field
.type
)
1929 || (TYPE_CODE (fip
-> list
-> field
.type
) == TYPE_CODE_ENUM
1930 && (fip
-> list
-> field
.bitsize
1931 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile
, FT_INTEGER
)))
1935 fip
-> list
-> field
.bitpos
% 8 == 0)
1937 fip
-> list
-> field
.bitsize
= 0;
1943 /* Read struct or class data fields. They have the form:
1945 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
1947 At the end, we see a semicolon instead of a field.
1949 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1952 The optional VISIBILITY is one of:
1954 '/0' (VISIBILITY_PRIVATE)
1955 '/1' (VISIBILITY_PROTECTED)
1956 '/2' (VISIBILITY_PUBLIC)
1958 or nothing, for C style fields with public visibility. */
1961 read_struct_fields (fip
, pp
, type
, objfile
)
1962 struct field_info
*fip
;
1965 struct objfile
*objfile
;
1968 struct nextfield
*new;
1970 /* We better set p right now, in case there are no fields at all... */
1974 /* Read each data member type until we find the terminating ';' at the end of
1975 the data member list, or break for some other reason such as finding the
1976 start of the member function list. */
1980 STABS_CONTINUE (pp
);
1981 /* Get space to record the next field's data. */
1982 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
1983 make_cleanup (free
, new);
1984 memset (new, 0, sizeof (struct nextfield
));
1985 new -> next
= fip
-> list
;
1988 /* Get the field name. */
1990 if (*p
== CPLUS_MARKER
)
1992 read_cpp_abbrev (fip
, pp
, type
, objfile
);
1996 /* Look for the ':' that separates the field name from the field
1997 values. Data members are delimited by a single ':', while member
1998 functions are delimited by a pair of ':'s. When we hit the member
1999 functions (if any), terminate scan loop and return. */
2006 /* Check to see if we have hit the member functions yet. */
2011 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
2015 /* chill the list of fields: the last entry (at the head) is a
2016 partially constructed entry which we now scrub. */
2017 fip
-> list
= fip
-> list
-> next
;
2022 /* The stabs for C++ derived classes contain baseclass information which
2023 is marked by a '!' character after the total size. This function is
2024 called when we encounter the baseclass marker, and slurps up all the
2025 baseclass information.
2027 Immediately following the '!' marker is the number of base classes that
2028 the class is derived from, followed by information for each base class.
2029 For each base class, there are two visibility specifiers, a bit offset
2030 to the base class information within the derived class, a reference to
2031 the type for the base class, and a terminating semicolon.
2033 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2035 Baseclass information marker __________________|| | | | | | |
2036 Number of baseclasses __________________________| | | | | | |
2037 Visibility specifiers (2) ________________________| | | | | |
2038 Offset in bits from start of class _________________| | | | |
2039 Type number for base class ___________________________| | | |
2040 Visibility specifiers (2) _______________________________| | |
2041 Offset in bits from start of class ________________________| |
2042 Type number of base class ____________________________________|
2046 read_baseclasses (fip
, pp
, type
, objfile
)
2047 struct field_info
*fip
;
2050 struct objfile
*objfile
;
2053 struct nextfield
*new;
2061 /* Skip the '!' baseclass information marker. */
2065 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2066 TYPE_N_BASECLASSES (type
) = read_number (pp
, ',');
2069 /* Some stupid compilers have trouble with the following, so break
2070 it up into simpler expressions. */
2071 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
2072 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
2075 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
2078 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
2079 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
2083 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
2085 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
2087 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
2088 make_cleanup (free
, new);
2089 memset (new, 0, sizeof (struct nextfield
));
2090 new -> next
= fip
-> list
;
2092 new -> field
.bitsize
= 0; /* this should be an unpacked field! */
2094 STABS_CONTINUE (pp
);
2098 /* Nothing to do. */
2101 SET_TYPE_FIELD_VIRTUAL (type
, i
);
2104 /* Bad visibility format. */
2108 new -> visibility
= *(*pp
)++;
2109 switch (new -> visibility
)
2111 case VISIBILITY_PRIVATE
:
2112 case VISIBILITY_PROTECTED
:
2113 case VISIBILITY_PUBLIC
:
2116 /* Bad visibility format. */
2120 /* The remaining value is the bit offset of the portion of the object
2121 corresponding to this baseclass. Always zero in the absence of
2122 multiple inheritance. */
2124 new -> field
.bitpos
= read_number (pp
, ',');
2126 /* The last piece of baseclass information is the type of the base
2127 class. Read it, and remember it's type name as this field's name. */
2129 new -> field
.type
= read_type (pp
, objfile
);
2130 new -> field
.name
= type_name_no_tag (new -> field
.type
);
2132 /* skip trailing ';' and bump count of number of fields seen */
2138 /* The tail end of stabs for C++ classes that contain a virtual function
2139 pointer contains a tilde, a %, and a type number.
2140 The type number refers to the base class (possibly this class itself) which
2141 contains the vtable pointer for the current class.
2143 This function is called when we have parsed all the method declarations,
2144 so we can look for the vptr base class info. */
2147 read_tilde_fields (fip
, pp
, type
, objfile
)
2148 struct field_info
*fip
;
2151 struct objfile
*objfile
;
2155 STABS_CONTINUE (pp
);
2157 /* If we are positioned at a ';', then skip it. */
2167 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
2169 /* Obsolete flags that used to indicate the presence
2170 of constructors and/or destructors. */
2174 /* Read either a '%' or the final ';'. */
2175 if (*(*pp
)++ == '%')
2177 /* The next number is the type number of the base class
2178 (possibly our own class) which supplies the vtable for
2179 this class. Parse it out, and search that class to find
2180 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2181 and TYPE_VPTR_FIELDNO. */
2186 t
= read_type (pp
, objfile
);
2188 while (*p
!= '\0' && *p
!= ';')
2194 /* Premature end of symbol. */
2198 TYPE_VPTR_BASETYPE (type
) = t
;
2199 if (type
== t
) /* Our own class provides vtbl ptr */
2201 for (i
= TYPE_NFIELDS (t
) - 1;
2202 i
>= TYPE_N_BASECLASSES (t
);
2205 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2206 sizeof (vptr_name
) - 1))
2208 TYPE_VPTR_FIELDNO (type
) = i
;
2212 /* Virtual function table field not found. */
2213 complain (vtbl_notfound_complaint
, TYPE_NAME (type
));
2218 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2229 attach_fn_fields_to_type (fip
, type
)
2230 struct field_info
*fip
;
2231 register struct type
*type
;
2235 for (n
= 0; n
< TYPE_N_BASECLASSES (type
); n
++)
2237 if (TYPE_CODE (TYPE_BASECLASS (type
, n
)) == TYPE_CODE_UNDEF
)
2239 /* @@ Memory leak on objfile -> type_obstack? */
2242 TYPE_NFN_FIELDS_TOTAL (type
) +=
2243 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, n
));
2246 for (n
= TYPE_NFN_FIELDS (type
);
2247 fip
-> fnlist
!= NULL
;
2248 fip
-> fnlist
= fip
-> fnlist
-> next
)
2250 --n
; /* Circumvent Sun3 compiler bug */
2251 TYPE_FN_FIELDLISTS (type
)[n
] = fip
-> fnlist
-> fn_fieldlist
;
2256 /* Create the vector of fields, and record how big it is.
2257 We need this info to record proper virtual function table information
2258 for this class's virtual functions. */
2261 attach_fields_to_type (fip
, type
, objfile
)
2262 struct field_info
*fip
;
2263 register struct type
*type
;
2264 struct objfile
*objfile
;
2266 register int nfields
= 0;
2267 register int non_public_fields
= 0;
2268 register struct nextfield
*scan
;
2270 /* Count up the number of fields that we have, as well as taking note of
2271 whether or not there are any non-public fields, which requires us to
2272 allocate and build the private_field_bits and protected_field_bits
2275 for (scan
= fip
-> list
; scan
!= NULL
; scan
= scan
-> next
)
2278 if (scan
-> visibility
!= VISIBILITY_PUBLIC
)
2280 non_public_fields
++;
2284 /* Now we know how many fields there are, and whether or not there are any
2285 non-public fields. Record the field count, allocate space for the
2286 array of fields, and create blank visibility bitfields if necessary. */
2288 TYPE_NFIELDS (type
) = nfields
;
2289 TYPE_FIELDS (type
) = (struct field
*)
2290 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
2291 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
2293 if (non_public_fields
)
2295 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2297 TYPE_FIELD_PRIVATE_BITS (type
) =
2298 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2299 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
2301 TYPE_FIELD_PROTECTED_BITS (type
) =
2302 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
2303 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
2306 /* Copy the saved-up fields into the field vector. Start from the head
2307 of the list, adding to the tail of the field array, so that they end
2308 up in the same order in the array in which they were added to the list. */
2310 while (nfields
-- > 0)
2312 TYPE_FIELD (type
, nfields
) = fip
-> list
-> field
;
2313 switch (fip
-> list
-> visibility
)
2315 case VISIBILITY_PRIVATE
:
2316 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
2319 case VISIBILITY_PROTECTED
:
2320 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
2323 case VISIBILITY_PUBLIC
:
2327 /* Should warn about this unknown visibility? */
2330 fip
-> list
= fip
-> list
-> next
;
2335 /* Read the description of a structure (or union type) and return an object
2336 describing the type.
2338 PP points to a character pointer that points to the next unconsumed token
2339 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2340 *PP will point to "4a:1,0,32;;".
2342 TYPE points to an incomplete type that needs to be filled in.
2344 OBJFILE points to the current objfile from which the stabs information is
2345 being read. (Note that it is redundant in that TYPE also contains a pointer
2346 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2349 static struct type
*
2350 read_struct_type (pp
, type
, objfile
)
2353 struct objfile
*objfile
;
2355 struct cleanup
*back_to
;
2356 struct field_info fi
;
2361 back_to
= make_cleanup (null_cleanup
, 0);
2363 INIT_CPLUS_SPECIFIC (type
);
2364 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2366 /* First comes the total size in bytes. */
2368 TYPE_LENGTH (type
) = read_number (pp
, 0);
2370 /* Now read the baseclasses, if any, read the regular C struct or C++
2371 class member fields, attach the fields to the type, read the C++
2372 member functions, attach them to the type, and then read any tilde
2373 field (baseclass specifier for the class holding the main vtable). */
2375 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
2376 || !read_struct_fields (&fi
, pp
, type
, objfile
)
2377 || !attach_fields_to_type (&fi
, type
, objfile
)
2378 || !read_member_functions (&fi
, pp
, type
, objfile
)
2379 || !attach_fn_fields_to_type (&fi
, type
)
2380 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
2382 do_cleanups (back_to
);
2383 return (error_type (pp
));
2386 do_cleanups (back_to
);
2390 /* Read a definition of an array type,
2391 and create and return a suitable type object.
2392 Also creates a range type which represents the bounds of that
2395 static struct type
*
2396 read_array_type (pp
, type
, objfile
)
2398 register struct type
*type
;
2399 struct objfile
*objfile
;
2401 struct type
*index_type
, *element_type
, *range_type
;
2405 /* Format of an array type:
2406 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2409 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2410 for these, produce a type like float[][]. */
2412 index_type
= read_type (pp
, objfile
);
2414 /* Improper format of array type decl. */
2415 return error_type (pp
);
2418 if (!(**pp
>= '0' && **pp
<= '9'))
2423 lower
= read_number (pp
, ';');
2425 if (!(**pp
>= '0' && **pp
<= '9'))
2430 upper
= read_number (pp
, ';');
2432 element_type
= read_type (pp
, objfile
);
2441 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
2442 type
= create_array_type (type
, element_type
, range_type
);
2444 /* If we have an array whose element type is not yet known, but whose
2445 bounds *are* known, record it to be adjusted at the end of the file. */
2447 if (TYPE_LENGTH (element_type
) == 0 && !adjustable
)
2449 add_undefined_type (type
);
2456 /* Read a definition of an enumeration type,
2457 and create and return a suitable type object.
2458 Also defines the symbols that represent the values of the type. */
2460 static struct type
*
2461 read_enum_type (pp
, type
, objfile
)
2463 register struct type
*type
;
2464 struct objfile
*objfile
;
2469 register struct symbol
*sym
;
2471 struct pending
**symlist
;
2472 struct pending
*osyms
, *syms
;
2476 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2477 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2478 to do? For now, force all enum values to file scope. */
2479 if (within_function
)
2480 symlist
= &local_symbols
;
2483 symlist
= &file_symbols
;
2485 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2487 /* Read the value-names and their values.
2488 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2489 A semicolon or comma instead of a NAME means the end. */
2490 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2492 STABS_CONTINUE (pp
);
2494 while (*p
!= ':') p
++;
2495 name
= obsavestring (*pp
, p
- *pp
, &objfile
-> symbol_obstack
);
2497 n
= read_number (pp
, ',');
2499 sym
= (struct symbol
*)
2500 obstack_alloc (&objfile
-> symbol_obstack
, sizeof (struct symbol
));
2501 memset (sym
, 0, sizeof (struct symbol
));
2502 SYMBOL_NAME (sym
) = name
;
2503 SYMBOL_LANGUAGE (sym
) = current_subfile
-> language
;
2504 SYMBOL_CLASS (sym
) = LOC_CONST
;
2505 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2506 SYMBOL_VALUE (sym
) = n
;
2507 add_symbol_to_list (sym
, symlist
);
2512 (*pp
)++; /* Skip the semicolon. */
2514 /* Now fill in the fields of the type-structure. */
2516 TYPE_LENGTH (type
) = sizeof (int);
2517 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2518 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
2519 TYPE_NFIELDS (type
) = nsyms
;
2520 TYPE_FIELDS (type
) = (struct field
*)
2521 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
2522 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
2524 /* Find the symbols for the values and put them into the type.
2525 The symbols can be found in the symlist that we put them on
2526 to cause them to be defined. osyms contains the old value
2527 of that symlist; everything up to there was defined by us. */
2528 /* Note that we preserve the order of the enum constants, so
2529 that in something like "enum {FOO, LAST_THING=FOO}" we print
2530 FOO, not LAST_THING. */
2532 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2537 for (; j
< syms
->nsyms
; j
++,n
++)
2539 struct symbol
*xsym
= syms
->symbol
[j
];
2540 SYMBOL_TYPE (xsym
) = type
;
2541 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2542 TYPE_FIELD_VALUE (type
, n
) = 0;
2543 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2544 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2551 /* This screws up perfectly good C programs with enums. FIXME. */
2552 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2553 if(TYPE_NFIELDS(type
) == 2 &&
2554 ((STREQ(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2555 STREQ(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2556 (STREQ(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2557 STREQ(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2558 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2564 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2565 typedefs in every file (for int, long, etc):
2567 type = b <signed> <width>; <offset>; <nbits>
2568 signed = u or s. Possible c in addition to u or s (for char?).
2569 offset = offset from high order bit to start bit of type.
2570 width is # bytes in object of this type, nbits is # bits in type.
2572 The width/offset stuff appears to be for small objects stored in
2573 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2576 static struct type
*
2577 read_sun_builtin_type (pp
, typenums
, objfile
)
2580 struct objfile
*objfile
;
2594 return error_type (pp
);
2598 /* For some odd reason, all forms of char put a c here. This is strange
2599 because no other type has this honor. We can safely ignore this because
2600 we actually determine 'char'acterness by the number of bits specified in
2606 /* The first number appears to be the number of bytes occupied
2607 by this type, except that unsigned short is 4 instead of 2.
2608 Since this information is redundant with the third number,
2609 we will ignore it. */
2610 read_number (pp
, ';');
2612 /* The second number is always 0, so ignore it too. */
2613 read_number (pp
, ';');
2615 /* The third number is the number of bits for this type. */
2616 nbits
= read_number (pp
, 0);
2618 /* FIXME. Here we should just be able to make a type of the right
2619 number of bits and signedness. FIXME. */
2621 if (nbits
== TARGET_LONG_LONG_BIT
)
2622 return (lookup_fundamental_type (objfile
,
2623 signed_type
? FT_LONG_LONG
: FT_UNSIGNED_LONG_LONG
));
2625 if (nbits
== TARGET_INT_BIT
)
2627 /* FIXME -- the only way to distinguish `int' from `long'
2628 is to look at its name! */
2631 if (long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2632 return lookup_fundamental_type (objfile
, FT_LONG
);
2634 return lookup_fundamental_type (objfile
, FT_INTEGER
);
2638 if (long_kludge_name
2639 && ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2640 long_kludge_name
[9] == 'l' /* long */)
2641 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2642 return lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
);
2644 return lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
);
2648 if (nbits
== TARGET_SHORT_BIT
)
2649 return (lookup_fundamental_type (objfile
,
2650 signed_type
? FT_SHORT
: FT_UNSIGNED_SHORT
));
2652 if (nbits
== TARGET_CHAR_BIT
)
2653 return (lookup_fundamental_type (objfile
,
2654 signed_type
? FT_CHAR
: FT_UNSIGNED_CHAR
));
2657 return lookup_fundamental_type (objfile
, FT_VOID
);
2659 return error_type (pp
);
2662 static struct type
*
2663 read_sun_floating_type (pp
, typenums
, objfile
)
2666 struct objfile
*objfile
;
2670 /* The first number has more details about the type, for example
2671 FN_COMPLEX. See the sun stab.h. */
2672 read_number (pp
, ';');
2674 /* The second number is the number of bytes occupied by this type */
2675 nbytes
= read_number (pp
, ';');
2678 return error_type (pp
);
2680 if (nbytes
== TARGET_FLOAT_BIT
/ TARGET_CHAR_BIT
)
2681 return lookup_fundamental_type (objfile
, FT_FLOAT
);
2683 if (nbytes
== TARGET_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2684 return lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
);
2686 if (nbytes
== TARGET_LONG_DOUBLE_BIT
/ TARGET_CHAR_BIT
)
2687 return lookup_fundamental_type (objfile
, FT_EXT_PREC_FLOAT
);
2689 return error_type (pp
);
2692 /* Read a number from the string pointed to by *PP.
2693 The value of *PP is advanced over the number.
2694 If END is nonzero, the character that ends the
2695 number must match END, or an error happens;
2696 and that character is skipped if it does match.
2697 If END is zero, *PP is left pointing to that character.
2699 If the number fits in a long, set *VALUE and set *BITS to 0.
2700 If not, set *BITS to be the number of bits in the number.
2702 If encounter garbage, set *BITS to -1. */
2705 read_huge_number (pp
, end
, valu
, bits
)
2726 /* Leading zero means octal. GCC uses this to output values larger
2727 than an int (because that would be hard in decimal). */
2734 upper_limit
= LONG_MAX
/ radix
;
2735 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2737 if (n
<= upper_limit
)
2740 n
+= c
- '0'; /* FIXME this overflows anyway */
2745 /* This depends on large values being output in octal, which is
2752 /* Ignore leading zeroes. */
2756 else if (c
== '2' || c
== '3')
2782 /* Large decimal constants are an error (because it is hard to
2783 count how many bits are in them). */
2789 /* -0x7f is the same as 0x80. So deal with it by adding one to
2790 the number of bits. */
2805 static struct type
*
2806 read_range_type (pp
, typenums
, objfile
)
2809 struct objfile
*objfile
;
2815 struct type
*result_type
;
2816 struct type
*index_type
;
2818 /* First comes a type we are a subrange of.
2819 In C it is usually 0, 1 or the type being defined. */
2820 read_type_number (pp
, rangenums
);
2821 self_subrange
= (rangenums
[0] == typenums
[0] &&
2822 rangenums
[1] == typenums
[1]);
2824 /* A semicolon should now follow; skip it. */
2828 /* The remaining two operands are usually lower and upper bounds
2829 of the range. But in some special cases they mean something else. */
2830 read_huge_number (pp
, ';', &n2
, &n2bits
);
2831 read_huge_number (pp
, ';', &n3
, &n3bits
);
2833 if (n2bits
== -1 || n3bits
== -1)
2834 return error_type (pp
);
2836 /* If limits are huge, must be large integral type. */
2837 if (n2bits
!= 0 || n3bits
!= 0)
2839 char got_signed
= 0;
2840 char got_unsigned
= 0;
2841 /* Number of bits in the type. */
2844 /* Range from 0 to <large number> is an unsigned large integral type. */
2845 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2850 /* Range from <large number> to <large number>-1 is a large signed
2852 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2858 /* Check for "long long". */
2859 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2860 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2861 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2862 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2864 if (got_signed
|| got_unsigned
)
2866 result_type
= alloc_type (objfile
);
2867 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2868 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2870 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2874 return error_type (pp
);
2877 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2878 if (self_subrange
&& n2
== 0 && n3
== 0)
2879 return (lookup_fundamental_type (objfile
, FT_VOID
));
2881 /* If n3 is zero and n2 is not, we want a floating type,
2882 and n2 is the width in bytes.
2884 Fortran programs appear to use this for complex types also,
2885 and they give no way to distinguish between double and single-complex!
2886 We don't have complex types, so we would lose on all fortran files!
2887 So return type `double' for all of those. It won't work right
2888 for the complex values, but at least it makes the file loadable.
2890 FIXME, we may be able to distinguish these by their names. FIXME. */
2892 if (n3
== 0 && n2
> 0)
2894 if (n2
== sizeof (float))
2895 return (lookup_fundamental_type (objfile
, FT_FLOAT
));
2896 return (lookup_fundamental_type (objfile
, FT_DBL_PREC_FLOAT
));
2899 /* If the upper bound is -1, it must really be an unsigned int. */
2901 else if (n2
== 0 && n3
== -1)
2903 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2904 long' is to look at its name! */
2906 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2907 long_kludge_name
[9] == 'l' /* long */)
2908 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2909 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2911 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2914 /* Special case: char is defined (Who knows why) as a subrange of
2915 itself with range 0-127. */
2916 else if (self_subrange
&& n2
== 0 && n3
== 127)
2917 return (lookup_fundamental_type (objfile
, FT_CHAR
));
2919 /* Assumptions made here: Subrange of self is equivalent to subrange
2920 of int. FIXME: Host and target type-sizes assumed the same. */
2921 /* FIXME: This is the *only* place in GDB that depends on comparing
2922 some type to a builtin type with ==. Fix it! */
2924 && (self_subrange
||
2925 *dbx_lookup_type (rangenums
) == lookup_fundamental_type (objfile
, FT_INTEGER
)))
2927 /* an unsigned type */
2929 if (n3
== - sizeof (long long))
2930 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG_LONG
));
2932 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2933 long' is to look at its name! */
2934 if (n3
== (unsigned long)~0L &&
2935 long_kludge_name
&& ((long_kludge_name
[0] == 'u' /* unsigned */ &&
2936 long_kludge_name
[9] == 'l' /* long */)
2937 || (long_kludge_name
[0] == 'l' /* long unsigned */)))
2938 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_LONG
));
2939 if (n3
== (unsigned int)~0L)
2940 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_INTEGER
));
2941 if (n3
== (unsigned short)~0L)
2942 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_SHORT
));
2943 if (n3
== (unsigned char)~0L)
2944 return (lookup_fundamental_type (objfile
, FT_UNSIGNED_CHAR
));
2947 else if (n3
== 0 && n2
== -sizeof (long long))
2948 return (lookup_fundamental_type (objfile
, FT_LONG_LONG
));
2950 else if (n2
== -n3
-1)
2953 /* FIXME -- the only way to distinguish `int' from `long' is to look
2955 if ((n3
==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2956 long_kludge_name
&& long_kludge_name
[0] == 'l' /* long */)
2957 return (lookup_fundamental_type (objfile
, FT_LONG
));
2958 if (n3
== (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2959 return (lookup_fundamental_type (objfile
, FT_INTEGER
));
2960 if (n3
== ( 1 << (8 * sizeof (short) - 1)) - 1)
2961 return (lookup_fundamental_type (objfile
, FT_SHORT
));
2962 if (n3
== ( 1 << (8 * sizeof (char) - 1)) - 1)
2963 return (lookup_fundamental_type (objfile
, FT_SIGNED_CHAR
));
2966 /* We have a real range type on our hands. Allocate space and
2967 return a real pointer. */
2969 /* At this point I don't have the faintest idea how to deal with
2970 a self_subrange type; I'm going to assume that this is used
2971 as an idiom, and that all of them are special cases. So . . . */
2973 return error_type (pp
);
2975 index_type
= *dbx_lookup_type (rangenums
);
2976 if (index_type
== NULL
)
2978 complain (&range_type_base_complaint
, rangenums
[1]);
2979 index_type
= lookup_fundamental_type (objfile
, FT_INTEGER
);
2982 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
2983 return (result_type
);
2986 /* Read a number from the string pointed to by *PP.
2987 The value of *PP is advanced over the number.
2988 If END is nonzero, the character that ends the
2989 number must match END, or an error happens;
2990 and that character is skipped if it does match.
2991 If END is zero, *PP is left pointing to that character. */
2994 read_number (pp
, end
)
2998 register char *p
= *pp
;
2999 register long n
= 0;
3003 /* Handle an optional leading minus sign. */
3011 /* Read the digits, as far as they go. */
3013 while ((c
= *p
++) >= '0' && c
<= '9')
3021 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
3030 /* Read in an argument list. This is a list of types, separated by commas
3031 and terminated with END. Return the list of types read in, or (struct type
3032 **)-1 if there is an error. */
3034 static struct type
**
3035 read_args (pp
, end
, objfile
)
3038 struct objfile
*objfile
;
3040 /* FIXME! Remove this arbitrary limit! */
3041 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
3047 /* Invalid argument list: no ','. */
3048 return (struct type
**)-1;
3050 STABS_CONTINUE (pp
);
3051 types
[n
++] = read_type (pp
, objfile
);
3053 (*pp
)++; /* get past `end' (the ':' character) */
3057 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
3059 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
3061 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
3062 memset (rval
+ n
, 0, sizeof (struct type
*));
3066 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
3068 memcpy (rval
, types
, n
* sizeof (struct type
*));
3072 /* Add a common block's start address to the offset of each symbol
3073 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3074 the common block name). */
3077 fix_common_block (sym
, valu
)
3081 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
3082 for ( ; next
; next
= next
->next
)
3085 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
3086 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
3092 /* What about types defined as forward references inside of a small lexical
3094 /* Add a type to the list of undefined types to be checked through
3095 once this file has been read in. */
3098 add_undefined_type (type
)
3101 if (undef_types_length
== undef_types_allocated
)
3103 undef_types_allocated
*= 2;
3104 undef_types
= (struct type
**)
3105 xrealloc ((char *) undef_types
,
3106 undef_types_allocated
* sizeof (struct type
*));
3108 undef_types
[undef_types_length
++] = type
;
3111 /* Go through each undefined type, see if it's still undefined, and fix it
3112 up if possible. We have two kinds of undefined types:
3114 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3115 Fix: update array length using the element bounds
3116 and the target type's length.
3117 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3118 yet defined at the time a pointer to it was made.
3119 Fix: Do a full lookup on the struct/union tag. */
3121 cleanup_undefined_types ()
3125 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3127 switch (TYPE_CODE (*type
))
3130 case TYPE_CODE_STRUCT
:
3131 case TYPE_CODE_UNION
:
3132 case TYPE_CODE_ENUM
:
3134 /* Check if it has been defined since. */
3135 if (TYPE_FLAGS (*type
) & TYPE_FLAG_STUB
)
3137 struct pending
*ppt
;
3139 /* Name of the type, without "struct" or "union" */
3140 char *typename
= TYPE_NAME (*type
);
3142 if (!strncmp (typename
, "struct ", 7))
3144 if (!strncmp (typename
, "union ", 6))
3146 if (!strncmp (typename
, "enum ", 5))
3149 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3151 for (i
= 0; i
< ppt
->nsyms
; i
++)
3153 struct symbol
*sym
= ppt
->symbol
[i
];
3155 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3156 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3157 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3159 && STREQ (SYMBOL_NAME (sym
), typename
))
3161 memcpy (*type
, SYMBOL_TYPE (sym
),
3162 sizeof (struct type
));
3170 case TYPE_CODE_ARRAY
:
3172 struct type
*range_type
;
3175 if (TYPE_LENGTH (*type
) != 0) /* Better be unknown */
3177 if (TYPE_NFIELDS (*type
) != 1)
3179 range_type
= TYPE_FIELD_TYPE (*type
, 0);
3180 if (TYPE_CODE (range_type
) != TYPE_CODE_RANGE
)
3183 /* Now recompute the length of the array type, based on its
3184 number of elements and the target type's length. */
3185 lower
= TYPE_FIELD_BITPOS (range_type
, 0);
3186 upper
= TYPE_FIELD_BITPOS (range_type
, 1);
3187 TYPE_LENGTH (*type
) = (upper
- lower
+ 1)
3188 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type
));
3194 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type
));
3198 undef_types_length
= 0;
3201 /* Scan through all of the global symbols defined in the object file,
3202 assigning values to the debugging symbols that need to be assigned
3203 to. Get these symbols from the minimal symbol table. */
3206 scan_file_globals (objfile
)
3207 struct objfile
*objfile
;
3210 struct minimal_symbol
*msymbol
;
3211 struct symbol
*sym
, *prev
;
3213 if (objfile
->msymbols
== 0) /* Beware the null file. */
3216 for (msymbol
= objfile
-> msymbols
; SYMBOL_NAME (msymbol
) != NULL
; msymbol
++)
3222 /* Get the hash index and check all the symbols
3223 under that hash index. */
3225 hash
= hashname (SYMBOL_NAME (msymbol
));
3227 for (sym
= global_sym_chain
[hash
]; sym
;)
3229 if (SYMBOL_NAME (msymbol
)[0] == SYMBOL_NAME (sym
)[0] &&
3230 STREQ(SYMBOL_NAME (msymbol
) + 1, SYMBOL_NAME (sym
) + 1))
3232 /* Splice this symbol out of the hash chain and
3233 assign the value we have to it. */
3236 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
3240 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
3243 /* Check to see whether we need to fix up a common block. */
3244 /* Note: this code might be executed several times for
3245 the same symbol if there are multiple references. */
3247 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
3249 fix_common_block (sym
, SYMBOL_VALUE_ADDRESS (msymbol
));
3253 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msymbol
);
3258 sym
= SYMBOL_VALUE_CHAIN (prev
);
3262 sym
= global_sym_chain
[hash
];
3268 sym
= SYMBOL_VALUE_CHAIN (sym
);
3274 /* Initialize anything that needs initializing when starting to read
3275 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3283 /* Initialize anything that needs initializing when a completely new
3284 symbol file is specified (not just adding some symbols from another
3285 file, e.g. a shared library). */
3288 stabsread_new_init ()
3290 /* Empty the hash table of global syms looking for values. */
3291 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
3294 /* Initialize anything that needs initializing at the same time as
3295 start_symtab() is called. */
3299 global_stabs
= NULL
; /* AIX COFF */
3300 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3301 n_this_object_header_files
= 1;
3302 type_vector_length
= 0;
3303 type_vector
= (struct type
**) 0;
3306 /* Call after end_symtab() */
3312 free ((char *) type_vector
);
3315 type_vector_length
= 0;
3316 previous_stab_code
= 0;
3320 finish_global_stabs (objfile
)
3321 struct objfile
*objfile
;
3325 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
3326 free ((PTR
) global_stabs
);
3327 global_stabs
= NULL
;
3331 /* Initializer for this module */
3334 _initialize_stabsread ()
3336 undef_types_allocated
= 20;
3337 undef_types_length
= 0;
3338 undef_types
= (struct type
**)
3339 xmalloc (undef_types_allocated
* sizeof (struct type
*));