1 /* Support routines for decoding "stabs" debugging information format.
3 Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
4 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
5 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
7 This file is part of GDB.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
22 /* Support routines for reading and decoding debugging information in
23 the "stabs" format. This format is used with many systems that use
24 the a.out object file format, as well as some systems that use
25 COFF or ELF where the stabs data is placed in a special section.
26 Avoid placing any object file format specific code in this file. */
29 #include "gdb_string.h"
31 #include "gdb_obstack.h"
34 #include "expression.h"
37 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native. */
39 #include "aout/aout64.h"
40 #include "gdb-stabs.h"
42 #include "complaints.h"
44 #include "gdb-demangle.h"
48 #include "cp-support.h"
49 #include "gdb_assert.h"
53 /* Ask stabsread.h to define the vars it normally declares `extern'. */
56 #include "stabsread.h" /* Our own declarations */
59 extern void _initialize_stabsread (void);
61 /* The routines that read and process a complete stabs for a C struct or
62 C++ class pass lists of data member fields and lists of member function
63 fields in an instance of a field_info structure, as defined below.
64 This is part of some reorganization of low level C++ support and is
65 expected to eventually go away... (FIXME) */
71 struct nextfield
*next
;
73 /* This is the raw visibility from the stab. It is not checked
74 for being one of the visibilities we recognize, so code which
75 examines this field better be able to deal. */
81 struct next_fnfieldlist
83 struct next_fnfieldlist
*next
;
84 struct fn_fieldlist fn_fieldlist
;
90 read_one_struct_field (struct field_info
*, char **, char *,
91 struct type
*, struct objfile
*);
93 static struct type
*dbx_alloc_type (int[2], struct objfile
*);
95 static long read_huge_number (char **, int, int *, int);
97 static struct type
*error_type (char **, struct objfile
*);
100 patch_block_stabs (struct pending
*, struct pending_stabs
*,
103 static void fix_common_block (struct symbol
*, int);
105 static int read_type_number (char **, int *);
107 static struct type
*read_type (char **, struct objfile
*);
109 static struct type
*read_range_type (char **, int[2], int, struct objfile
*);
111 static struct type
*read_sun_builtin_type (char **, int[2], struct objfile
*);
113 static struct type
*read_sun_floating_type (char **, int[2],
116 static struct type
*read_enum_type (char **, struct type
*, struct objfile
*);
118 static struct type
*rs6000_builtin_type (int, struct objfile
*);
121 read_member_functions (struct field_info
*, char **, struct type
*,
125 read_struct_fields (struct field_info
*, char **, struct type
*,
129 read_baseclasses (struct field_info
*, char **, struct type
*,
133 read_tilde_fields (struct field_info
*, char **, struct type
*,
136 static int attach_fn_fields_to_type (struct field_info
*, struct type
*);
138 static int attach_fields_to_type (struct field_info
*, struct type
*,
141 static struct type
*read_struct_type (char **, struct type
*,
145 static struct type
*read_array_type (char **, struct type
*,
148 static struct field
*read_args (char **, int, struct objfile
*, int *, int *);
150 static void add_undefined_type (struct type
*, int[2]);
153 read_cpp_abbrev (struct field_info
*, char **, struct type
*,
156 static char *find_name_end (char *name
);
158 static int process_reference (char **string
);
160 void stabsread_clear_cache (void);
162 static const char vptr_name
[] = "_vptr$";
163 static const char vb_name
[] = "_vb$";
166 invalid_cpp_abbrev_complaint (const char *arg1
)
168 complaint (&symfile_complaints
, _("invalid C++ abbreviation `%s'"), arg1
);
172 reg_value_complaint (int regnum
, int num_regs
, const char *sym
)
174 complaint (&symfile_complaints
,
175 _("register number %d too large (max %d) in symbol %s"),
176 regnum
, num_regs
- 1, sym
);
180 stabs_general_complaint (const char *arg1
)
182 complaint (&symfile_complaints
, "%s", arg1
);
185 /* Make a list of forward references which haven't been defined. */
187 static struct type
**undef_types
;
188 static int undef_types_allocated
;
189 static int undef_types_length
;
190 static struct symbol
*current_symbol
= NULL
;
192 /* Make a list of nameless types that are undefined.
193 This happens when another type is referenced by its number
194 before this type is actually defined. For instance "t(0,1)=k(0,2)"
195 and type (0,2) is defined only later. */
202 static struct nat
*noname_undefs
;
203 static int noname_undefs_allocated
;
204 static int noname_undefs_length
;
206 /* Check for and handle cretinous stabs symbol name continuation! */
207 #define STABS_CONTINUE(pp,objfile) \
209 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
210 *(pp) = next_symbol_text (objfile); \
214 /* Look up a dbx type-number pair. Return the address of the slot
215 where the type for that number-pair is stored.
216 The number-pair is in TYPENUMS.
218 This can be used for finding the type associated with that pair
219 or for associating a new type with the pair. */
221 static struct type
**
222 dbx_lookup_type (int typenums
[2], struct objfile
*objfile
)
224 int filenum
= typenums
[0];
225 int index
= typenums
[1];
228 struct header_file
*f
;
231 if (filenum
== -1) /* -1,-1 is for temporary types. */
234 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
236 complaint (&symfile_complaints
,
237 _("Invalid symbol data: type number "
238 "(%d,%d) out of range at symtab pos %d."),
239 filenum
, index
, symnum
);
247 /* Caller wants address of address of type. We think
248 that negative (rs6k builtin) types will never appear as
249 "lvalues", (nor should they), so we stuff the real type
250 pointer into a temp, and return its address. If referenced,
251 this will do the right thing. */
252 static struct type
*temp_type
;
254 temp_type
= rs6000_builtin_type (index
, objfile
);
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 xmalloc (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 (objfile
))
287 static struct type
*temp_type
;
289 warning (_("GDB internal error: bad real_filenum"));
292 temp_type
= objfile_type (objfile
)->builtin_error
;
296 f
= HEADER_FILES (objfile
) + real_filenum
;
298 f_orig_length
= f
->length
;
299 if (index
>= f_orig_length
)
301 while (index
>= f
->length
)
305 f
->vector
= (struct type
**)
306 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
307 memset (&f
->vector
[f_orig_length
], 0,
308 (f
->length
- f_orig_length
) * sizeof (struct type
*));
310 return (&f
->vector
[index
]);
314 /* Make sure there is a type allocated for type numbers TYPENUMS
315 and return the type object.
316 This can create an empty (zeroed) type object.
317 TYPENUMS may be (-1, -1) to return a new type object that is not
318 put into the type vector, and so may not be referred to by number. */
321 dbx_alloc_type (int typenums
[2], struct objfile
*objfile
)
323 struct type
**type_addr
;
325 if (typenums
[0] == -1)
327 return (alloc_type (objfile
));
330 type_addr
= dbx_lookup_type (typenums
, objfile
);
332 /* If we are referring to a type not known at all yet,
333 allocate an empty type for it.
334 We will fill it in later if we find out how. */
337 *type_addr
= alloc_type (objfile
);
343 /* for all the stabs in a given stab vector, build appropriate types
344 and fix their symbols in given symbol vector. */
347 patch_block_stabs (struct pending
*symbols
, struct pending_stabs
*stabs
,
348 struct objfile
*objfile
)
357 /* for all the stab entries, find their corresponding symbols and
358 patch their types! */
360 for (ii
= 0; ii
< stabs
->count
; ++ii
)
362 name
= stabs
->stab
[ii
];
363 pp
= (char *) strchr (name
, ':');
364 gdb_assert (pp
); /* Must find a ':' or game's over. */
368 pp
= (char *) strchr (pp
, ':');
370 sym
= find_symbol_in_list (symbols
, name
, pp
- name
);
373 /* FIXME-maybe: it would be nice if we noticed whether
374 the variable was defined *anywhere*, not just whether
375 it is defined in this compilation unit. But neither
376 xlc or GCC seem to need such a definition, and until
377 we do psymtabs (so that the minimal symbols from all
378 compilation units are available now), I'm not sure
379 how to get the information. */
381 /* On xcoff, if a global is defined and never referenced,
382 ld will remove it from the executable. There is then
383 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
384 sym
= (struct symbol
*)
385 obstack_alloc (&objfile
->objfile_obstack
,
386 sizeof (struct symbol
));
388 memset (sym
, 0, sizeof (struct symbol
));
389 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
390 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
391 SYMBOL_SET_LINKAGE_NAME
392 (sym
, obsavestring (name
, pp
- name
,
393 &objfile
->objfile_obstack
));
395 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
397 /* I don't think the linker does this with functions,
398 so as far as I know this is never executed.
399 But it doesn't hurt to check. */
401 lookup_function_type (read_type (&pp
, objfile
));
405 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
407 add_symbol_to_list (sym
, &global_symbols
);
412 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
415 lookup_function_type (read_type (&pp
, objfile
));
419 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
427 /* Read a number by which a type is referred to in dbx data,
428 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
429 Just a single number N is equivalent to (0,N).
430 Return the two numbers by storing them in the vector TYPENUMS.
431 TYPENUMS will then be used as an argument to dbx_lookup_type.
433 Returns 0 for success, -1 for error. */
436 read_type_number (char **pp
, int *typenums
)
443 typenums
[0] = read_huge_number (pp
, ',', &nbits
, 0);
446 typenums
[1] = read_huge_number (pp
, ')', &nbits
, 0);
453 typenums
[1] = read_huge_number (pp
, 0, &nbits
, 0);
461 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
462 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
463 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
464 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
466 /* Structure for storing pointers to reference definitions for fast lookup
467 during "process_later". */
476 #define MAX_CHUNK_REFS 100
477 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
478 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
480 static struct ref_map
*ref_map
;
482 /* Ptr to free cell in chunk's linked list. */
483 static int ref_count
= 0;
485 /* Number of chunks malloced. */
486 static int ref_chunk
= 0;
488 /* This file maintains a cache of stabs aliases found in the symbol
489 table. If the symbol table changes, this cache must be cleared
490 or we are left holding onto data in invalid obstacks. */
492 stabsread_clear_cache (void)
498 /* Create array of pointers mapping refids to symbols and stab strings.
499 Add pointers to reference definition symbols and/or their values as we
500 find them, using their reference numbers as our index.
501 These will be used later when we resolve references. */
503 ref_add (int refnum
, struct symbol
*sym
, char *stabs
, CORE_ADDR value
)
507 if (refnum
>= ref_count
)
508 ref_count
= refnum
+ 1;
509 if (ref_count
> ref_chunk
* MAX_CHUNK_REFS
)
511 int new_slots
= ref_count
- ref_chunk
* MAX_CHUNK_REFS
;
512 int new_chunks
= new_slots
/ MAX_CHUNK_REFS
+ 1;
514 ref_map
= (struct ref_map
*)
515 xrealloc (ref_map
, REF_MAP_SIZE (ref_chunk
+ new_chunks
));
516 memset (ref_map
+ ref_chunk
* MAX_CHUNK_REFS
, 0,
517 new_chunks
* REF_CHUNK_SIZE
);
518 ref_chunk
+= new_chunks
;
520 ref_map
[refnum
].stabs
= stabs
;
521 ref_map
[refnum
].sym
= sym
;
522 ref_map
[refnum
].value
= value
;
525 /* Return defined sym for the reference REFNUM. */
527 ref_search (int refnum
)
529 if (refnum
< 0 || refnum
> ref_count
)
531 return ref_map
[refnum
].sym
;
534 /* Parse a reference id in STRING and return the resulting
535 reference number. Move STRING beyond the reference id. */
538 process_reference (char **string
)
546 /* Advance beyond the initial '#'. */
549 /* Read number as reference id. */
550 while (*p
&& isdigit (*p
))
552 refnum
= refnum
* 10 + *p
- '0';
559 /* If STRING defines a reference, store away a pointer to the reference
560 definition for later use. Return the reference number. */
563 symbol_reference_defined (char **string
)
568 refnum
= process_reference (&p
);
570 /* Defining symbols end in '='. */
573 /* Symbol is being defined here. */
579 /* Must be a reference. Either the symbol has already been defined,
580 or this is a forward reference to it. */
587 stab_reg_to_regnum (struct symbol
*sym
, struct gdbarch
*gdbarch
)
589 int regno
= gdbarch_stab_reg_to_regnum (gdbarch
, SYMBOL_VALUE (sym
));
591 if (regno
>= gdbarch_num_regs (gdbarch
)
592 + gdbarch_num_pseudo_regs (gdbarch
))
594 reg_value_complaint (regno
,
595 gdbarch_num_regs (gdbarch
)
596 + gdbarch_num_pseudo_regs (gdbarch
),
597 SYMBOL_PRINT_NAME (sym
));
599 regno
= gdbarch_sp_regnum (gdbarch
); /* Known safe, though useless. */
605 static const struct symbol_register_ops stab_register_funcs
= {
610 define_symbol (CORE_ADDR valu
, char *string
, int desc
, int type
,
611 struct objfile
*objfile
)
613 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
615 char *p
= (char *) find_name_end (string
);
619 char *new_name
= NULL
;
621 /* We would like to eliminate nameless symbols, but keep their types.
622 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
623 to type 2, but, should not create a symbol to address that type. Since
624 the symbol will be nameless, there is no way any user can refer to it. */
628 /* Ignore syms with empty names. */
632 /* Ignore old-style symbols from cc -go. */
642 complaint (&symfile_complaints
,
643 _("Bad stabs string '%s'"), string
);
648 /* If a nameless stab entry, all we need is the type, not the symbol.
649 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
650 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
652 current_symbol
= sym
= (struct symbol
*)
653 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct symbol
));
654 memset (sym
, 0, sizeof (struct symbol
));
656 switch (type
& N_TYPE
)
659 SYMBOL_SECTION (sym
) = SECT_OFF_TEXT (objfile
);
662 SYMBOL_SECTION (sym
) = SECT_OFF_DATA (objfile
);
665 SYMBOL_SECTION (sym
) = SECT_OFF_BSS (objfile
);
669 if (processing_gcc_compilation
)
671 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
672 number of bytes occupied by a type or object, which we ignore. */
673 SYMBOL_LINE (sym
) = desc
;
677 SYMBOL_LINE (sym
) = 0; /* unknown */
680 if (is_cplus_marker (string
[0]))
682 /* Special GNU C++ names. */
686 SYMBOL_SET_LINKAGE_NAME (sym
, "this");
689 case 'v': /* $vtbl_ptr_type */
693 SYMBOL_SET_LINKAGE_NAME (sym
, "eh_throw");
697 /* This was an anonymous type that was never fixed up. */
701 /* SunPRO (3.0 at least) static variable encoding. */
702 if (gdbarch_static_transform_name_p (gdbarch
))
704 /* ... fall through ... */
707 complaint (&symfile_complaints
, _("Unknown C++ symbol name `%s'"),
709 goto normal
; /* Do *something* with it. */
715 SYMBOL_SET_LANGUAGE (sym
, current_subfile
->language
);
716 if (SYMBOL_LANGUAGE (sym
) == language_cplus
)
718 char *name
= alloca (p
- string
+ 1);
720 memcpy (name
, string
, p
- string
);
721 name
[p
- string
] = '\0';
722 new_name
= cp_canonicalize_string (name
);
724 if (new_name
!= NULL
)
726 SYMBOL_SET_NAMES (sym
, new_name
, strlen (new_name
), 1, objfile
);
730 SYMBOL_SET_NAMES (sym
, string
, p
- string
, 1, objfile
);
732 if (SYMBOL_LANGUAGE (sym
) == language_cplus
)
733 cp_scan_for_anonymous_namespaces (sym
, objfile
);
738 /* Determine the type of name being defined. */
740 /* Getting GDB to correctly skip the symbol on an undefined symbol
741 descriptor and not ever dump core is a very dodgy proposition if
742 we do things this way. I say the acorn RISC machine can just
743 fix their compiler. */
744 /* The Acorn RISC machine's compiler can put out locals that don't
745 start with "234=" or "(3,4)=", so assume anything other than the
746 deftypes we know how to handle is a local. */
747 if (!strchr ("cfFGpPrStTvVXCR", *p
))
749 if (isdigit (*p
) || *p
== '(' || *p
== '-')
758 /* c is a special case, not followed by a type-number.
759 SYMBOL:c=iVALUE for an integer constant symbol.
760 SYMBOL:c=rVALUE for a floating constant symbol.
761 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
762 e.g. "b:c=e6,0" for "const b = blob1"
763 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
766 SYMBOL_CLASS (sym
) = LOC_CONST
;
767 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
768 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
769 add_symbol_to_list (sym
, &file_symbols
);
779 struct type
*dbl_type
;
781 /* FIXME-if-picky-about-floating-accuracy: Should be using
782 target arithmetic to get the value. real.c in GCC
783 probably has the necessary code. */
785 dbl_type
= objfile_type (objfile
)->builtin_double
;
787 obstack_alloc (&objfile
->objfile_obstack
,
788 TYPE_LENGTH (dbl_type
));
789 store_typed_floating (dbl_valu
, dbl_type
, d
);
791 SYMBOL_TYPE (sym
) = dbl_type
;
792 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
793 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
798 /* Defining integer constants this way is kind of silly,
799 since 'e' constants allows the compiler to give not
800 only the value, but the type as well. C has at least
801 int, long, unsigned int, and long long as constant
802 types; other languages probably should have at least
803 unsigned as well as signed constants. */
805 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_long
;
806 SYMBOL_VALUE (sym
) = atoi (p
);
807 SYMBOL_CLASS (sym
) = LOC_CONST
;
813 SYMBOL_TYPE (sym
) = objfile_type (objfile
)->builtin_char
;
814 SYMBOL_VALUE (sym
) = atoi (p
);
815 SYMBOL_CLASS (sym
) = LOC_CONST
;
821 struct type
*range_type
;
824 gdb_byte
*string_local
= (gdb_byte
*) alloca (strlen (p
));
825 gdb_byte
*string_value
;
827 if (quote
!= '\'' && quote
!= '"')
829 SYMBOL_CLASS (sym
) = LOC_CONST
;
830 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
831 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
832 add_symbol_to_list (sym
, &file_symbols
);
836 /* Find matching quote, rejecting escaped quotes. */
837 while (*p
&& *p
!= quote
)
839 if (*p
== '\\' && p
[1] == quote
)
841 string_local
[ind
] = (gdb_byte
) quote
;
847 string_local
[ind
] = (gdb_byte
) (*p
);
854 SYMBOL_CLASS (sym
) = LOC_CONST
;
855 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
856 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
857 add_symbol_to_list (sym
, &file_symbols
);
861 /* NULL terminate the string. */
862 string_local
[ind
] = 0;
864 = create_range_type (NULL
,
865 objfile_type (objfile
)->builtin_int
,
867 SYMBOL_TYPE (sym
) = create_array_type (NULL
,
868 objfile_type (objfile
)->builtin_char
,
870 string_value
= obstack_alloc (&objfile
->objfile_obstack
, ind
+ 1);
871 memcpy (string_value
, string_local
, ind
+ 1);
874 SYMBOL_VALUE_BYTES (sym
) = string_value
;
875 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
880 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
881 can be represented as integral.
882 e.g. "b:c=e6,0" for "const b = blob1"
883 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
885 SYMBOL_CLASS (sym
) = LOC_CONST
;
886 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
890 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
895 /* If the value is too big to fit in an int (perhaps because
896 it is unsigned), or something like that, we silently get
897 a bogus value. The type and everything else about it is
898 correct. Ideally, we should be using whatever we have
899 available for parsing unsigned and long long values,
901 SYMBOL_VALUE (sym
) = atoi (p
);
906 SYMBOL_CLASS (sym
) = LOC_CONST
;
907 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
910 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
911 add_symbol_to_list (sym
, &file_symbols
);
915 /* The name of a caught exception. */
916 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
917 SYMBOL_CLASS (sym
) = LOC_LABEL
;
918 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
919 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
920 add_symbol_to_list (sym
, &local_symbols
);
924 /* A static function definition. */
925 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
926 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
927 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
928 add_symbol_to_list (sym
, &file_symbols
);
929 /* fall into process_function_types. */
931 process_function_types
:
932 /* Function result types are described as the result type in stabs.
933 We need to convert this to the function-returning-type-X type
934 in GDB. E.g. "int" is converted to "function returning int". */
935 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
936 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
938 /* All functions in C++ have prototypes. Stabs does not offer an
939 explicit way to identify prototyped or unprototyped functions,
940 but both GCC and Sun CC emit stabs for the "call-as" type rather
941 than the "declared-as" type for unprototyped functions, so
942 we treat all functions as if they were prototyped. This is used
943 primarily for promotion when calling the function from GDB. */
944 TYPE_PROTOTYPED (SYMBOL_TYPE (sym
)) = 1;
946 /* fall into process_prototype_types. */
948 process_prototype_types
:
949 /* Sun acc puts declared types of arguments here. */
952 struct type
*ftype
= SYMBOL_TYPE (sym
);
957 /* Obtain a worst case guess for the number of arguments
958 by counting the semicolons. */
965 /* Allocate parameter information fields and fill them in. */
966 TYPE_FIELDS (ftype
) = (struct field
*)
967 TYPE_ALLOC (ftype
, nsemi
* sizeof (struct field
));
972 /* A type number of zero indicates the start of varargs.
973 FIXME: GDB currently ignores vararg functions. */
974 if (p
[0] == '0' && p
[1] == '\0')
976 ptype
= read_type (&p
, objfile
);
978 /* The Sun compilers mark integer arguments, which should
979 be promoted to the width of the calling conventions, with
980 a type which references itself. This type is turned into
981 a TYPE_CODE_VOID type by read_type, and we have to turn
982 it back into builtin_int here.
983 FIXME: Do we need a new builtin_promoted_int_arg ? */
984 if (TYPE_CODE (ptype
) == TYPE_CODE_VOID
)
985 ptype
= objfile_type (objfile
)->builtin_int
;
986 TYPE_FIELD_TYPE (ftype
, nparams
) = ptype
;
987 TYPE_FIELD_ARTIFICIAL (ftype
, nparams
++) = 0;
989 TYPE_NFIELDS (ftype
) = nparams
;
990 TYPE_PROTOTYPED (ftype
) = 1;
995 /* A global function definition. */
996 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
997 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
998 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
999 add_symbol_to_list (sym
, &global_symbols
);
1000 goto process_function_types
;
1003 /* For a class G (global) symbol, it appears that the
1004 value is not correct. It is necessary to search for the
1005 corresponding linker definition to find the value.
1006 These definitions appear at the end of the namelist. */
1007 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1008 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1009 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1010 /* Don't add symbol references to global_sym_chain.
1011 Symbol references don't have valid names and wont't match up with
1012 minimal symbols when the global_sym_chain is relocated.
1013 We'll fixup symbol references when we fixup the defining symbol. */
1014 if (SYMBOL_LINKAGE_NAME (sym
) && SYMBOL_LINKAGE_NAME (sym
)[0] != '#')
1016 i
= hashname (SYMBOL_LINKAGE_NAME (sym
));
1017 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1018 global_sym_chain
[i
] = sym
;
1020 add_symbol_to_list (sym
, &global_symbols
);
1023 /* This case is faked by a conditional above,
1024 when there is no code letter in the dbx data.
1025 Dbx data never actually contains 'l'. */
1028 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1029 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1030 SYMBOL_VALUE (sym
) = valu
;
1031 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1032 add_symbol_to_list (sym
, &local_symbols
);
1037 /* pF is a two-letter code that means a function parameter in Fortran.
1038 The type-number specifies the type of the return value.
1039 Translate it into a pointer-to-function type. */
1043 = lookup_pointer_type
1044 (lookup_function_type (read_type (&p
, objfile
)));
1047 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1049 SYMBOL_CLASS (sym
) = LOC_ARG
;
1050 SYMBOL_VALUE (sym
) = valu
;
1051 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1052 SYMBOL_IS_ARGUMENT (sym
) = 1;
1053 add_symbol_to_list (sym
, &local_symbols
);
1055 if (gdbarch_byte_order (gdbarch
) != BFD_ENDIAN_BIG
)
1057 /* On little-endian machines, this crud is never necessary,
1058 and, if the extra bytes contain garbage, is harmful. */
1062 /* If it's gcc-compiled, if it says `short', believe it. */
1063 if (processing_gcc_compilation
1064 || gdbarch_believe_pcc_promotion (gdbarch
))
1067 if (!gdbarch_believe_pcc_promotion (gdbarch
))
1069 /* If PCC says a parameter is a short or a char, it is
1071 if (TYPE_LENGTH (SYMBOL_TYPE (sym
))
1072 < gdbarch_int_bit (gdbarch
) / TARGET_CHAR_BIT
1073 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1076 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1077 ? objfile_type (objfile
)->builtin_unsigned_int
1078 : objfile_type (objfile
)->builtin_int
;
1084 /* acc seems to use P to declare the prototypes of functions that
1085 are referenced by this file. gdb is not prepared to deal
1086 with this extra information. FIXME, it ought to. */
1089 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1090 goto process_prototype_types
;
1095 /* Parameter which is in a register. */
1096 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1097 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1098 SYMBOL_REGISTER_OPS (sym
) = &stab_register_funcs
;
1099 SYMBOL_IS_ARGUMENT (sym
) = 1;
1100 SYMBOL_VALUE (sym
) = valu
;
1101 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1102 add_symbol_to_list (sym
, &local_symbols
);
1106 /* Register variable (either global or local). */
1107 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1108 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1109 SYMBOL_REGISTER_OPS (sym
) = &stab_register_funcs
;
1110 SYMBOL_VALUE (sym
) = valu
;
1111 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1112 if (within_function
)
1114 /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
1115 the same name to represent an argument passed in a
1116 register. GCC uses 'P' for the same case. So if we find
1117 such a symbol pair we combine it into one 'P' symbol.
1118 For Sun cc we need to do this regardless of
1119 stabs_argument_has_addr, because the compiler puts out
1120 the 'p' symbol even if it never saves the argument onto
1123 On most machines, we want to preserve both symbols, so
1124 that we can still get information about what is going on
1125 with the stack (VAX for computing args_printed, using
1126 stack slots instead of saved registers in backtraces,
1129 Note that this code illegally combines
1130 main(argc) struct foo argc; { register struct foo argc; }
1131 but this case is considered pathological and causes a warning
1132 from a decent compiler. */
1135 && local_symbols
->nsyms
> 0
1136 && gdbarch_stabs_argument_has_addr (gdbarch
, SYMBOL_TYPE (sym
)))
1138 struct symbol
*prev_sym
;
1140 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1141 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1142 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1143 && strcmp (SYMBOL_LINKAGE_NAME (prev_sym
),
1144 SYMBOL_LINKAGE_NAME (sym
)) == 0)
1146 SYMBOL_CLASS (prev_sym
) = LOC_REGISTER
;
1147 SYMBOL_REGISTER_OPS (prev_sym
) = &stab_register_funcs
;
1148 /* Use the type from the LOC_REGISTER; that is the type
1149 that is actually in that register. */
1150 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1151 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1156 add_symbol_to_list (sym
, &local_symbols
);
1159 add_symbol_to_list (sym
, &file_symbols
);
1163 /* Static symbol at top level of file. */
1164 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1165 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1166 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1167 if (gdbarch_static_transform_name_p (gdbarch
)
1168 && gdbarch_static_transform_name (gdbarch
,
1169 SYMBOL_LINKAGE_NAME (sym
))
1170 != SYMBOL_LINKAGE_NAME (sym
))
1172 struct minimal_symbol
*msym
;
1174 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1178 char *new_name
= gdbarch_static_transform_name
1179 (gdbarch
, SYMBOL_LINKAGE_NAME (sym
));
1181 SYMBOL_SET_LINKAGE_NAME (sym
, new_name
);
1182 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1185 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1186 add_symbol_to_list (sym
, &file_symbols
);
1190 /* In Ada, there is no distinction between typedef and non-typedef;
1191 any type declaration implicitly has the equivalent of a typedef,
1192 and thus 't' is in fact equivalent to 'Tt'.
1194 Therefore, for Ada units, we check the character immediately
1195 before the 't', and if we do not find a 'T', then make sure to
1196 create the associated symbol in the STRUCT_DOMAIN ('t' definitions
1197 will be stored in the VAR_DOMAIN). If the symbol was indeed
1198 defined as 'Tt' then the STRUCT_DOMAIN symbol will be created
1199 elsewhere, so we don't need to take care of that.
1201 This is important to do, because of forward references:
1202 The cleanup of undefined types stored in undef_types only uses
1203 STRUCT_DOMAIN symbols to perform the replacement. */
1204 synonym
= (SYMBOL_LANGUAGE (sym
) == language_ada
&& p
[-2] != 'T');
1207 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1209 /* For a nameless type, we don't want a create a symbol, thus we
1210 did not use `sym'. Return without further processing. */
1214 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1215 SYMBOL_VALUE (sym
) = valu
;
1216 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1217 /* C++ vagaries: we may have a type which is derived from
1218 a base type which did not have its name defined when the
1219 derived class was output. We fill in the derived class's
1220 base part member's name here in that case. */
1221 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1222 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1223 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1224 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1228 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1229 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1230 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1231 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1234 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1236 /* gcc-2.6 or later (when using -fvtable-thunks)
1237 emits a unique named type for a vtable entry.
1238 Some gdb code depends on that specific name. */
1239 extern const char vtbl_ptr_name
[];
1241 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1242 && strcmp (SYMBOL_LINKAGE_NAME (sym
), vtbl_ptr_name
))
1243 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1245 /* If we are giving a name to a type such as "pointer to
1246 foo" or "function returning foo", we better not set
1247 the TYPE_NAME. If the program contains "typedef char
1248 *caddr_t;", we don't want all variables of type char
1249 * to print as caddr_t. This is not just a
1250 consequence of GDB's type management; PCC and GCC (at
1251 least through version 2.4) both output variables of
1252 either type char * or caddr_t with the type number
1253 defined in the 't' symbol for caddr_t. If a future
1254 compiler cleans this up it GDB is not ready for it
1255 yet, but if it becomes ready we somehow need to
1256 disable this check (without breaking the PCC/GCC2.4
1261 Fortunately, this check seems not to be necessary
1262 for anything except pointers or functions. */
1263 /* ezannoni: 2000-10-26. This seems to apply for
1264 versions of gcc older than 2.8. This was the original
1265 problem: with the following code gdb would tell that
1266 the type for name1 is caddr_t, and func is char().
1268 typedef char *caddr_t;
1280 /* Pascal accepts names for pointer types. */
1281 if (current_subfile
->language
== language_pascal
)
1283 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_LINKAGE_NAME (sym
);
1287 TYPE_NAME (SYMBOL_TYPE (sym
)) = SYMBOL_LINKAGE_NAME (sym
);
1290 add_symbol_to_list (sym
, &file_symbols
);
1294 /* Create the STRUCT_DOMAIN clone. */
1295 struct symbol
*struct_sym
= (struct symbol
*)
1296 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct symbol
));
1299 SYMBOL_CLASS (struct_sym
) = LOC_TYPEDEF
;
1300 SYMBOL_VALUE (struct_sym
) = valu
;
1301 SYMBOL_DOMAIN (struct_sym
) = STRUCT_DOMAIN
;
1302 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1303 TYPE_NAME (SYMBOL_TYPE (sym
))
1304 = obconcat (&objfile
->objfile_obstack
,
1305 SYMBOL_LINKAGE_NAME (sym
),
1307 add_symbol_to_list (struct_sym
, &file_symbols
);
1313 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1314 by 't' which means we are typedef'ing it as well. */
1315 synonym
= *p
== 't';
1320 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1322 /* For a nameless type, we don't want a create a symbol, thus we
1323 did not use `sym'. Return without further processing. */
1327 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1328 SYMBOL_VALUE (sym
) = valu
;
1329 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
1330 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1331 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1332 = obconcat (&objfile
->objfile_obstack
,
1333 SYMBOL_LINKAGE_NAME (sym
),
1335 add_symbol_to_list (sym
, &file_symbols
);
1339 /* Clone the sym and then modify it. */
1340 struct symbol
*typedef_sym
= (struct symbol
*)
1341 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct symbol
));
1343 *typedef_sym
= *sym
;
1344 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1345 SYMBOL_VALUE (typedef_sym
) = valu
;
1346 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
1347 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1348 TYPE_NAME (SYMBOL_TYPE (sym
))
1349 = obconcat (&objfile
->objfile_obstack
,
1350 SYMBOL_LINKAGE_NAME (sym
),
1352 add_symbol_to_list (typedef_sym
, &file_symbols
);
1357 /* Static symbol of local scope. */
1358 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1359 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1360 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1361 if (gdbarch_static_transform_name_p (gdbarch
)
1362 && gdbarch_static_transform_name (gdbarch
,
1363 SYMBOL_LINKAGE_NAME (sym
))
1364 != SYMBOL_LINKAGE_NAME (sym
))
1366 struct minimal_symbol
*msym
;
1368 msym
= lookup_minimal_symbol (SYMBOL_LINKAGE_NAME (sym
),
1372 char *new_name
= gdbarch_static_transform_name
1373 (gdbarch
, SYMBOL_LINKAGE_NAME (sym
));
1375 SYMBOL_SET_LINKAGE_NAME (sym
, new_name
);
1376 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1379 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1380 add_symbol_to_list (sym
, &local_symbols
);
1384 /* Reference parameter */
1385 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1386 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1387 SYMBOL_IS_ARGUMENT (sym
) = 1;
1388 SYMBOL_VALUE (sym
) = valu
;
1389 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1390 add_symbol_to_list (sym
, &local_symbols
);
1394 /* Reference parameter which is in a register. */
1395 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1396 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1397 SYMBOL_REGISTER_OPS (sym
) = &stab_register_funcs
;
1398 SYMBOL_IS_ARGUMENT (sym
) = 1;
1399 SYMBOL_VALUE (sym
) = valu
;
1400 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1401 add_symbol_to_list (sym
, &local_symbols
);
1405 /* This is used by Sun FORTRAN for "function result value".
1406 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1407 that Pascal uses it too, but when I tried it Pascal used
1408 "x:3" (local symbol) instead. */
1409 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1410 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1411 SYMBOL_VALUE (sym
) = valu
;
1412 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1413 add_symbol_to_list (sym
, &local_symbols
);
1417 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1418 SYMBOL_CLASS (sym
) = LOC_CONST
;
1419 SYMBOL_VALUE (sym
) = 0;
1420 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1421 add_symbol_to_list (sym
, &file_symbols
);
1425 /* Some systems pass variables of certain types by reference instead
1426 of by value, i.e. they will pass the address of a structure (in a
1427 register or on the stack) instead of the structure itself. */
1429 if (gdbarch_stabs_argument_has_addr (gdbarch
, SYMBOL_TYPE (sym
))
1430 && SYMBOL_IS_ARGUMENT (sym
))
1432 /* We have to convert LOC_REGISTER to LOC_REGPARM_ADDR (for
1433 variables passed in a register). */
1434 if (SYMBOL_CLASS (sym
) == LOC_REGISTER
)
1435 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1436 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
1437 and subsequent arguments on SPARC, for example). */
1438 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
1439 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1445 /* Skip rest of this symbol and return an error type.
1447 General notes on error recovery: error_type always skips to the
1448 end of the symbol (modulo cretinous dbx symbol name continuation).
1449 Thus code like this:
1451 if (*(*pp)++ != ';')
1452 return error_type (pp, objfile);
1454 is wrong because if *pp starts out pointing at '\0' (typically as the
1455 result of an earlier error), it will be incremented to point to the
1456 start of the next symbol, which might produce strange results, at least
1457 if you run off the end of the string table. Instead use
1460 return error_type (pp, objfile);
1466 foo = error_type (pp, objfile);
1470 And in case it isn't obvious, the point of all this hair is so the compiler
1471 can define new types and new syntaxes, and old versions of the
1472 debugger will be able to read the new symbol tables. */
1474 static struct type
*
1475 error_type (char **pp
, struct objfile
*objfile
)
1477 complaint (&symfile_complaints
,
1478 _("couldn't parse type; debugger out of date?"));
1481 /* Skip to end of symbol. */
1482 while (**pp
!= '\0')
1487 /* Check for and handle cretinous dbx symbol name continuation! */
1488 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1490 *pp
= next_symbol_text (objfile
);
1497 return objfile_type (objfile
)->builtin_error
;
1501 /* Read type information or a type definition; return the type. Even
1502 though this routine accepts either type information or a type
1503 definition, the distinction is relevant--some parts of stabsread.c
1504 assume that type information starts with a digit, '-', or '(' in
1505 deciding whether to call read_type. */
1507 static struct type
*
1508 read_type (char **pp
, struct objfile
*objfile
)
1510 struct type
*type
= 0;
1513 char type_descriptor
;
1515 /* Size in bits of type if specified by a type attribute, or -1 if
1516 there is no size attribute. */
1519 /* Used to distinguish string and bitstring from char-array and set. */
1522 /* Used to distinguish vector from array. */
1525 /* Read type number if present. The type number may be omitted.
1526 for instance in a two-dimensional array declared with type
1527 "ar1;1;10;ar1;1;10;4". */
1528 if ((**pp
>= '0' && **pp
<= '9')
1532 if (read_type_number (pp
, typenums
) != 0)
1533 return error_type (pp
, objfile
);
1537 /* Type is not being defined here. Either it already
1538 exists, or this is a forward reference to it.
1539 dbx_alloc_type handles both cases. */
1540 type
= dbx_alloc_type (typenums
, objfile
);
1542 /* If this is a forward reference, arrange to complain if it
1543 doesn't get patched up by the time we're done
1545 if (TYPE_CODE (type
) == TYPE_CODE_UNDEF
)
1546 add_undefined_type (type
, typenums
);
1551 /* Type is being defined here. */
1553 Also skip the type descriptor - we get it below with (*pp)[-1]. */
1558 /* 'typenums=' not present, type is anonymous. Read and return
1559 the definition, but don't put it in the type vector. */
1560 typenums
[0] = typenums
[1] = -1;
1565 type_descriptor
= (*pp
)[-1];
1566 switch (type_descriptor
)
1570 enum type_code code
;
1572 /* Used to index through file_symbols. */
1573 struct pending
*ppt
;
1576 /* Name including "struct", etc. */
1580 char *from
, *to
, *p
, *q1
, *q2
;
1582 /* Set the type code according to the following letter. */
1586 code
= TYPE_CODE_STRUCT
;
1589 code
= TYPE_CODE_UNION
;
1592 code
= TYPE_CODE_ENUM
;
1596 /* Complain and keep going, so compilers can invent new
1597 cross-reference types. */
1598 complaint (&symfile_complaints
,
1599 _("Unrecognized cross-reference type `%c'"),
1601 code
= TYPE_CODE_STRUCT
;
1606 q1
= strchr (*pp
, '<');
1607 p
= strchr (*pp
, ':');
1609 return error_type (pp
, objfile
);
1610 if (q1
&& p
> q1
&& p
[1] == ':')
1612 int nesting_level
= 0;
1614 for (q2
= q1
; *q2
; q2
++)
1618 else if (*q2
== '>')
1620 else if (*q2
== ':' && nesting_level
== 0)
1625 return error_type (pp
, objfile
);
1628 if (current_subfile
->language
== language_cplus
)
1630 char *new_name
, *name
= alloca (p
- *pp
+ 1);
1632 memcpy (name
, *pp
, p
- *pp
);
1633 name
[p
- *pp
] = '\0';
1634 new_name
= cp_canonicalize_string (name
);
1635 if (new_name
!= NULL
)
1637 type_name
= obsavestring (new_name
, strlen (new_name
),
1638 &objfile
->objfile_obstack
);
1642 if (type_name
== NULL
)
1644 to
= type_name
= (char *)
1645 obstack_alloc (&objfile
->objfile_obstack
, p
- *pp
+ 1);
1647 /* Copy the name. */
1654 /* Set the pointer ahead of the name which we just read, and
1659 /* If this type has already been declared, then reuse the same
1660 type, rather than allocating a new one. This saves some
1663 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1664 for (i
= 0; i
< ppt
->nsyms
; i
++)
1666 struct symbol
*sym
= ppt
->symbol
[i
];
1668 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1669 && SYMBOL_DOMAIN (sym
) == STRUCT_DOMAIN
1670 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1671 && strcmp (SYMBOL_LINKAGE_NAME (sym
), type_name
) == 0)
1673 obstack_free (&objfile
->objfile_obstack
, type_name
);
1674 type
= SYMBOL_TYPE (sym
);
1675 if (typenums
[0] != -1)
1676 *dbx_lookup_type (typenums
, objfile
) = type
;
1681 /* Didn't find the type to which this refers, so we must
1682 be dealing with a forward reference. Allocate a type
1683 structure for it, and keep track of it so we can
1684 fill in the rest of the fields when we get the full
1686 type
= dbx_alloc_type (typenums
, objfile
);
1687 TYPE_CODE (type
) = code
;
1688 TYPE_TAG_NAME (type
) = type_name
;
1689 INIT_CPLUS_SPECIFIC (type
);
1690 TYPE_STUB (type
) = 1;
1692 add_undefined_type (type
, typenums
);
1696 case '-': /* RS/6000 built-in type */
1710 /* We deal with something like t(1,2)=(3,4)=... which
1711 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
1713 /* Allocate and enter the typedef type first.
1714 This handles recursive types. */
1715 type
= dbx_alloc_type (typenums
, objfile
);
1716 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
1718 struct type
*xtype
= read_type (pp
, objfile
);
1722 /* It's being defined as itself. That means it is "void". */
1723 TYPE_CODE (type
) = TYPE_CODE_VOID
;
1724 TYPE_LENGTH (type
) = 1;
1726 else if (type_size
>= 0 || is_string
)
1728 /* This is the absolute wrong way to construct types. Every
1729 other debug format has found a way around this problem and
1730 the related problems with unnecessarily stubbed types;
1731 someone motivated should attempt to clean up the issue
1732 here as well. Once a type pointed to has been created it
1733 should not be modified.
1735 Well, it's not *absolutely* wrong. Constructing recursive
1736 types (trees, linked lists) necessarily entails modifying
1737 types after creating them. Constructing any loop structure
1738 entails side effects. The Dwarf 2 reader does handle this
1739 more gracefully (it never constructs more than once
1740 instance of a type object, so it doesn't have to copy type
1741 objects wholesale), but it still mutates type objects after
1742 other folks have references to them.
1744 Keep in mind that this circularity/mutation issue shows up
1745 at the source language level, too: C's "incomplete types",
1746 for example. So the proper cleanup, I think, would be to
1747 limit GDB's type smashing to match exactly those required
1748 by the source language. So GDB could have a
1749 "complete_this_type" function, but never create unnecessary
1750 copies of a type otherwise. */
1751 replace_type (type
, xtype
);
1752 TYPE_NAME (type
) = NULL
;
1753 TYPE_TAG_NAME (type
) = NULL
;
1757 TYPE_TARGET_STUB (type
) = 1;
1758 TYPE_TARGET_TYPE (type
) = xtype
;
1763 /* In the following types, we must be sure to overwrite any existing
1764 type that the typenums refer to, rather than allocating a new one
1765 and making the typenums point to the new one. This is because there
1766 may already be pointers to the existing type (if it had been
1767 forward-referenced), and we must change it to a pointer, function,
1768 reference, or whatever, *in-place*. */
1770 case '*': /* Pointer to another type */
1771 type1
= read_type (pp
, objfile
);
1772 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
, objfile
));
1775 case '&': /* Reference to another type */
1776 type1
= read_type (pp
, objfile
);
1777 type
= make_reference_type (type1
, dbx_lookup_type (typenums
, objfile
));
1780 case 'f': /* Function returning another type */
1781 type1
= read_type (pp
, objfile
);
1782 type
= make_function_type (type1
, dbx_lookup_type (typenums
, objfile
));
1785 case 'g': /* Prototyped function. (Sun) */
1787 /* Unresolved questions:
1789 - According to Sun's ``STABS Interface Manual'', for 'f'
1790 and 'F' symbol descriptors, a `0' in the argument type list
1791 indicates a varargs function. But it doesn't say how 'g'
1792 type descriptors represent that info. Someone with access
1793 to Sun's toolchain should try it out.
1795 - According to the comment in define_symbol (search for
1796 `process_prototype_types:'), Sun emits integer arguments as
1797 types which ref themselves --- like `void' types. Do we
1798 have to deal with that here, too? Again, someone with
1799 access to Sun's toolchain should try it out and let us
1802 const char *type_start
= (*pp
) - 1;
1803 struct type
*return_type
= read_type (pp
, objfile
);
1804 struct type
*func_type
1805 = make_function_type (return_type
,
1806 dbx_lookup_type (typenums
, objfile
));
1809 struct type_list
*next
;
1813 while (**pp
&& **pp
!= '#')
1815 struct type
*arg_type
= read_type (pp
, objfile
);
1816 struct type_list
*new = alloca (sizeof (*new));
1817 new->type
= arg_type
;
1818 new->next
= arg_types
;
1826 complaint (&symfile_complaints
,
1827 _("Prototyped function type didn't "
1828 "end arguments with `#':\n%s"),
1832 /* If there is just one argument whose type is `void', then
1833 that's just an empty argument list. */
1835 && ! arg_types
->next
1836 && TYPE_CODE (arg_types
->type
) == TYPE_CODE_VOID
)
1839 TYPE_FIELDS (func_type
)
1840 = (struct field
*) TYPE_ALLOC (func_type
,
1841 num_args
* sizeof (struct field
));
1842 memset (TYPE_FIELDS (func_type
), 0, num_args
* sizeof (struct field
));
1845 struct type_list
*t
;
1847 /* We stuck each argument type onto the front of the list
1848 when we read it, so the list is reversed. Build the
1849 fields array right-to-left. */
1850 for (t
= arg_types
, i
= num_args
- 1; t
; t
= t
->next
, i
--)
1851 TYPE_FIELD_TYPE (func_type
, i
) = t
->type
;
1853 TYPE_NFIELDS (func_type
) = num_args
;
1854 TYPE_PROTOTYPED (func_type
) = 1;
1860 case 'k': /* Const qualifier on some type (Sun) */
1861 type
= read_type (pp
, objfile
);
1862 type
= make_cv_type (1, TYPE_VOLATILE (type
), type
,
1863 dbx_lookup_type (typenums
, objfile
));
1866 case 'B': /* Volatile qual on some type (Sun) */
1867 type
= read_type (pp
, objfile
);
1868 type
= make_cv_type (TYPE_CONST (type
), 1, type
,
1869 dbx_lookup_type (typenums
, objfile
));
1873 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
1874 { /* Member (class & variable) type */
1875 /* FIXME -- we should be doing smash_to_XXX types here. */
1877 struct type
*domain
= read_type (pp
, objfile
);
1878 struct type
*memtype
;
1881 /* Invalid member type data format. */
1882 return error_type (pp
, objfile
);
1885 memtype
= read_type (pp
, objfile
);
1886 type
= dbx_alloc_type (typenums
, objfile
);
1887 smash_to_memberptr_type (type
, domain
, memtype
);
1890 /* type attribute */
1894 /* Skip to the semicolon. */
1895 while (**pp
!= ';' && **pp
!= '\0')
1898 return error_type (pp
, objfile
);
1900 ++ * pp
; /* Skip the semicolon. */
1904 case 's': /* Size attribute */
1905 type_size
= atoi (attr
+ 1);
1910 case 'S': /* String attribute */
1911 /* FIXME: check to see if following type is array? */
1915 case 'V': /* Vector attribute */
1916 /* FIXME: check to see if following type is array? */
1921 /* Ignore unrecognized type attributes, so future compilers
1922 can invent new ones. */
1930 case '#': /* Method (class & fn) type */
1931 if ((*pp
)[0] == '#')
1933 /* We'll get the parameter types from the name. */
1934 struct type
*return_type
;
1937 return_type
= read_type (pp
, objfile
);
1938 if (*(*pp
)++ != ';')
1939 complaint (&symfile_complaints
,
1940 _("invalid (minimal) member type "
1941 "data format at symtab pos %d."),
1943 type
= allocate_stub_method (return_type
);
1944 if (typenums
[0] != -1)
1945 *dbx_lookup_type (typenums
, objfile
) = type
;
1949 struct type
*domain
= read_type (pp
, objfile
);
1950 struct type
*return_type
;
1955 /* Invalid member type data format. */
1956 return error_type (pp
, objfile
);
1960 return_type
= read_type (pp
, objfile
);
1961 args
= read_args (pp
, ';', objfile
, &nargs
, &varargs
);
1963 return error_type (pp
, objfile
);
1964 type
= dbx_alloc_type (typenums
, objfile
);
1965 smash_to_method_type (type
, domain
, return_type
, args
,
1970 case 'r': /* Range type */
1971 type
= read_range_type (pp
, typenums
, type_size
, objfile
);
1972 if (typenums
[0] != -1)
1973 *dbx_lookup_type (typenums
, objfile
) = type
;
1978 /* Sun ACC builtin int type */
1979 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
1980 if (typenums
[0] != -1)
1981 *dbx_lookup_type (typenums
, objfile
) = type
;
1985 case 'R': /* Sun ACC builtin float type */
1986 type
= read_sun_floating_type (pp
, typenums
, objfile
);
1987 if (typenums
[0] != -1)
1988 *dbx_lookup_type (typenums
, objfile
) = type
;
1991 case 'e': /* Enumeration type */
1992 type
= dbx_alloc_type (typenums
, objfile
);
1993 type
= read_enum_type (pp
, type
, objfile
);
1994 if (typenums
[0] != -1)
1995 *dbx_lookup_type (typenums
, objfile
) = type
;
1998 case 's': /* Struct type */
1999 case 'u': /* Union type */
2001 enum type_code type_code
= TYPE_CODE_UNDEF
;
2002 type
= dbx_alloc_type (typenums
, objfile
);
2003 switch (type_descriptor
)
2006 type_code
= TYPE_CODE_STRUCT
;
2009 type_code
= TYPE_CODE_UNION
;
2012 type
= read_struct_type (pp
, type
, type_code
, objfile
);
2016 case 'a': /* Array type */
2018 return error_type (pp
, objfile
);
2021 type
= dbx_alloc_type (typenums
, objfile
);
2022 type
= read_array_type (pp
, type
, objfile
);
2024 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2026 make_vector_type (type
);
2029 case 'S': /* Set or bitstring type */
2030 type1
= read_type (pp
, objfile
);
2031 type
= create_set_type ((struct type
*) NULL
, type1
);
2033 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2034 if (typenums
[0] != -1)
2035 *dbx_lookup_type (typenums
, objfile
) = type
;
2039 --*pp
; /* Go back to the symbol in error. */
2040 /* Particularly important if it was \0! */
2041 return error_type (pp
, objfile
);
2046 warning (_("GDB internal error, type is NULL in stabsread.c."));
2047 return error_type (pp
, objfile
);
2050 /* Size specified in a type attribute overrides any other size. */
2051 if (type_size
!= -1)
2052 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2057 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2058 Return the proper type node for a given builtin type number. */
2060 static const struct objfile_data
*rs6000_builtin_type_data
;
2062 static struct type
*
2063 rs6000_builtin_type (int typenum
, struct objfile
*objfile
)
2065 struct type
**negative_types
= objfile_data (objfile
,
2066 rs6000_builtin_type_data
);
2068 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2069 #define NUMBER_RECOGNIZED 34
2070 struct type
*rettype
= NULL
;
2072 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2074 complaint (&symfile_complaints
, _("Unknown builtin type %d"), typenum
);
2075 return objfile_type (objfile
)->builtin_error
;
2078 if (!negative_types
)
2080 /* This includes an empty slot for type number -0. */
2081 negative_types
= OBSTACK_CALLOC (&objfile
->objfile_obstack
,
2082 NUMBER_RECOGNIZED
+ 1, struct type
*);
2083 set_objfile_data (objfile
, rs6000_builtin_type_data
, negative_types
);
2086 if (negative_types
[-typenum
] != NULL
)
2087 return negative_types
[-typenum
];
2089 #if TARGET_CHAR_BIT != 8
2090 #error This code wrong for TARGET_CHAR_BIT not 8
2091 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2092 that if that ever becomes not true, the correct fix will be to
2093 make the size in the struct type to be in bits, not in units of
2100 /* The size of this and all the other types are fixed, defined
2101 by the debugging format. If there is a type called "int" which
2102 is other than 32 bits, then it should use a new negative type
2103 number (or avoid negative type numbers for that case).
2104 See stabs.texinfo. */
2105 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", objfile
);
2108 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", objfile
);
2111 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", objfile
);
2114 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", objfile
);
2117 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2118 "unsigned char", objfile
);
2121 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", objfile
);
2124 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2125 "unsigned short", objfile
);
2128 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2129 "unsigned int", objfile
);
2132 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2133 "unsigned", objfile
);
2136 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2137 "unsigned long", objfile
);
2140 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", objfile
);
2143 /* IEEE single precision (32 bit). */
2144 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", objfile
);
2147 /* IEEE double precision (64 bit). */
2148 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", objfile
);
2151 /* This is an IEEE double on the RS/6000, and different machines with
2152 different sizes for "long double" should use different negative
2153 type numbers. See stabs.texinfo. */
2154 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", objfile
);
2157 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", objfile
);
2160 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2161 "boolean", objfile
);
2164 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", objfile
);
2167 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", objfile
);
2170 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", objfile
);
2173 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2174 "character", objfile
);
2177 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2178 "logical*1", objfile
);
2181 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2182 "logical*2", objfile
);
2185 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2186 "logical*4", objfile
);
2189 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2190 "logical", objfile
);
2193 /* Complex type consisting of two IEEE single precision values. */
2194 rettype
= init_type (TYPE_CODE_COMPLEX
, 8, 0, "complex", objfile
);
2195 TYPE_TARGET_TYPE (rettype
) = init_type (TYPE_CODE_FLT
, 4, 0, "float",
2199 /* Complex type consisting of two IEEE double precision values. */
2200 rettype
= init_type (TYPE_CODE_COMPLEX
, 16, 0, "double complex", NULL
);
2201 TYPE_TARGET_TYPE (rettype
) = init_type (TYPE_CODE_FLT
, 8, 0, "double",
2205 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", objfile
);
2208 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", objfile
);
2211 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", objfile
);
2214 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", objfile
);
2217 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", objfile
);
2220 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2221 "unsigned long long", objfile
);
2224 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2225 "logical*8", objfile
);
2228 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", objfile
);
2231 negative_types
[-typenum
] = rettype
;
2235 /* This page contains subroutines of read_type. */
2237 /* Replace *OLD_NAME with the method name portion of PHYSNAME. */
2240 update_method_name_from_physname (char **old_name
, const char *physname
)
2244 method_name
= method_name_from_physname (physname
);
2246 if (method_name
== NULL
)
2248 complaint (&symfile_complaints
,
2249 _("Method has bad physname %s\n"), physname
);
2253 if (strcmp (*old_name
, method_name
) != 0)
2256 *old_name
= method_name
;
2259 xfree (method_name
);
2262 /* Read member function stabs info for C++ classes. The form of each member
2265 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2267 An example with two member functions is:
2269 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2271 For the case of overloaded operators, the format is op$::*.funcs, where
2272 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2273 name (such as `+=') and `.' marks the end of the operator name.
2275 Returns 1 for success, 0 for failure. */
2278 read_member_functions (struct field_info
*fip
, char **pp
, struct type
*type
,
2279 struct objfile
*objfile
)
2283 /* Total number of member functions defined in this class. If the class
2284 defines two `f' functions, and one `g' function, then this will have
2286 int total_length
= 0;
2290 struct next_fnfield
*next
;
2291 struct fn_field fn_field
;
2294 struct type
*look_ahead_type
;
2295 struct next_fnfieldlist
*new_fnlist
;
2296 struct next_fnfield
*new_sublist
;
2300 /* Process each list until we find something that is not a member function
2301 or find the end of the functions. */
2305 /* We should be positioned at the start of the function name.
2306 Scan forward to find the first ':' and if it is not the
2307 first of a "::" delimiter, then this is not a member function. */
2319 look_ahead_type
= NULL
;
2322 new_fnlist
= (struct next_fnfieldlist
*)
2323 xmalloc (sizeof (struct next_fnfieldlist
));
2324 make_cleanup (xfree
, new_fnlist
);
2325 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2327 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2329 /* This is a completely wierd case. In order to stuff in the
2330 names that might contain colons (the usual name delimiter),
2331 Mike Tiemann defined a different name format which is
2332 signalled if the identifier is "op$". In that case, the
2333 format is "op$::XXXX." where XXXX is the name. This is
2334 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2335 /* This lets the user type "break operator+".
2336 We could just put in "+" as the name, but that wouldn't
2338 static char opname
[32] = "op$";
2339 char *o
= opname
+ 3;
2341 /* Skip past '::'. */
2344 STABS_CONTINUE (pp
, objfile
);
2350 main_fn_name
= savestring (opname
, o
- opname
);
2356 main_fn_name
= savestring (*pp
, p
- *pp
);
2357 /* Skip past '::'. */
2360 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
2365 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2366 make_cleanup (xfree
, new_sublist
);
2367 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2369 /* Check for and handle cretinous dbx symbol name continuation! */
2370 if (look_ahead_type
== NULL
)
2373 STABS_CONTINUE (pp
, objfile
);
2375 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2378 /* Invalid symtab info for member function. */
2384 /* g++ version 1 kludge */
2385 new_sublist
->fn_field
.type
= look_ahead_type
;
2386 look_ahead_type
= NULL
;
2396 /* If this is just a stub, then we don't have the real name here. */
2398 if (TYPE_STUB (new_sublist
->fn_field
.type
))
2400 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
2401 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
2402 new_sublist
->fn_field
.is_stub
= 1;
2404 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2407 /* Set this member function's visibility fields. */
2410 case VISIBILITY_PRIVATE
:
2411 new_sublist
->fn_field
.is_private
= 1;
2413 case VISIBILITY_PROTECTED
:
2414 new_sublist
->fn_field
.is_protected
= 1;
2418 STABS_CONTINUE (pp
, objfile
);
2421 case 'A': /* Normal functions. */
2422 new_sublist
->fn_field
.is_const
= 0;
2423 new_sublist
->fn_field
.is_volatile
= 0;
2426 case 'B': /* `const' member functions. */
2427 new_sublist
->fn_field
.is_const
= 1;
2428 new_sublist
->fn_field
.is_volatile
= 0;
2431 case 'C': /* `volatile' member function. */
2432 new_sublist
->fn_field
.is_const
= 0;
2433 new_sublist
->fn_field
.is_volatile
= 1;
2436 case 'D': /* `const volatile' member function. */
2437 new_sublist
->fn_field
.is_const
= 1;
2438 new_sublist
->fn_field
.is_volatile
= 1;
2441 case '*': /* File compiled with g++ version 1 --
2447 complaint (&symfile_complaints
,
2448 _("const/volatile indicator missing, got '%c'"),
2458 /* virtual member function, followed by index.
2459 The sign bit is set to distinguish pointers-to-methods
2460 from virtual function indicies. Since the array is
2461 in words, the quantity must be shifted left by 1
2462 on 16 bit machine, and by 2 on 32 bit machine, forcing
2463 the sign bit out, and usable as a valid index into
2464 the array. Remove the sign bit here. */
2465 new_sublist
->fn_field
.voffset
=
2466 (0x7fffffff & read_huge_number (pp
, ';', &nbits
, 0)) + 2;
2470 STABS_CONTINUE (pp
, objfile
);
2471 if (**pp
== ';' || **pp
== '\0')
2473 /* Must be g++ version 1. */
2474 new_sublist
->fn_field
.fcontext
= 0;
2478 /* Figure out from whence this virtual function came.
2479 It may belong to virtual function table of
2480 one of its baseclasses. */
2481 look_ahead_type
= read_type (pp
, objfile
);
2484 /* g++ version 1 overloaded methods. */
2488 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2497 look_ahead_type
= NULL
;
2503 /* static member function. */
2505 int slen
= strlen (main_fn_name
);
2507 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2509 /* For static member functions, we can't tell if they
2510 are stubbed, as they are put out as functions, and not as
2512 GCC v2 emits the fully mangled name if
2513 dbxout.c:flag_minimal_debug is not set, so we have to
2514 detect a fully mangled physname here and set is_stub
2515 accordingly. Fully mangled physnames in v2 start with
2516 the member function name, followed by two underscores.
2517 GCC v3 currently always emits stubbed member functions,
2518 but with fully mangled physnames, which start with _Z. */
2519 if (!(strncmp (new_sublist
->fn_field
.physname
,
2520 main_fn_name
, slen
) == 0
2521 && new_sublist
->fn_field
.physname
[slen
] == '_'
2522 && new_sublist
->fn_field
.physname
[slen
+ 1] == '_'))
2524 new_sublist
->fn_field
.is_stub
= 1;
2531 complaint (&symfile_complaints
,
2532 _("member function type missing, got '%c'"),
2534 /* Fall through into normal member function. */
2537 /* normal member function. */
2538 new_sublist
->fn_field
.voffset
= 0;
2539 new_sublist
->fn_field
.fcontext
= 0;
2543 new_sublist
->next
= sublist
;
2544 sublist
= new_sublist
;
2546 STABS_CONTINUE (pp
, objfile
);
2548 while (**pp
!= ';' && **pp
!= '\0');
2551 STABS_CONTINUE (pp
, objfile
);
2553 /* Skip GCC 3.X member functions which are duplicates of the callable
2554 constructor/destructor. */
2555 if (strcmp_iw (main_fn_name
, "__base_ctor ") == 0
2556 || strcmp_iw (main_fn_name
, "__base_dtor ") == 0
2557 || strcmp (main_fn_name
, "__deleting_dtor") == 0)
2559 xfree (main_fn_name
);
2564 int has_destructor
= 0, has_other
= 0;
2566 struct next_fnfield
*tmp_sublist
;
2568 /* Various versions of GCC emit various mostly-useless
2569 strings in the name field for special member functions.
2571 For stub methods, we need to defer correcting the name
2572 until we are ready to unstub the method, because the current
2573 name string is used by gdb_mangle_name. The only stub methods
2574 of concern here are GNU v2 operators; other methods have their
2575 names correct (see caveat below).
2577 For non-stub methods, in GNU v3, we have a complete physname.
2578 Therefore we can safely correct the name now. This primarily
2579 affects constructors and destructors, whose name will be
2580 __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast
2581 operators will also have incorrect names; for instance,
2582 "operator int" will be named "operator i" (i.e. the type is
2585 For non-stub methods in GNU v2, we have no easy way to
2586 know if we have a complete physname or not. For most
2587 methods the result depends on the platform (if CPLUS_MARKER
2588 can be `$' or `.', it will use minimal debug information, or
2589 otherwise the full physname will be included).
2591 Rather than dealing with this, we take a different approach.
2592 For v3 mangled names, we can use the full physname; for v2,
2593 we use cplus_demangle_opname (which is actually v2 specific),
2594 because the only interesting names are all operators - once again
2595 barring the caveat below. Skip this process if any method in the
2596 group is a stub, to prevent our fouling up the workings of
2599 The caveat: GCC 2.95.x (and earlier?) put constructors and
2600 destructors in the same method group. We need to split this
2601 into two groups, because they should have different names.
2602 So for each method group we check whether it contains both
2603 routines whose physname appears to be a destructor (the physnames
2604 for and destructors are always provided, due to quirks in v2
2605 mangling) and routines whose physname does not appear to be a
2606 destructor. If so then we break up the list into two halves.
2607 Even if the constructors and destructors aren't in the same group
2608 the destructor will still lack the leading tilde, so that also
2611 So, to summarize what we expect and handle here:
2613 Given Given Real Real Action
2614 method name physname physname method name
2616 __opi [none] __opi__3Foo operator int opname
2618 Foo _._3Foo _._3Foo ~Foo separate and
2620 operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
2621 __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
2624 tmp_sublist
= sublist
;
2625 while (tmp_sublist
!= NULL
)
2627 if (tmp_sublist
->fn_field
.is_stub
)
2629 if (tmp_sublist
->fn_field
.physname
[0] == '_'
2630 && tmp_sublist
->fn_field
.physname
[1] == 'Z')
2633 if (is_destructor_name (tmp_sublist
->fn_field
.physname
))
2638 tmp_sublist
= tmp_sublist
->next
;
2641 if (has_destructor
&& has_other
)
2643 struct next_fnfieldlist
*destr_fnlist
;
2644 struct next_fnfield
*last_sublist
;
2646 /* Create a new fn_fieldlist for the destructors. */
2648 destr_fnlist
= (struct next_fnfieldlist
*)
2649 xmalloc (sizeof (struct next_fnfieldlist
));
2650 make_cleanup (xfree
, destr_fnlist
);
2651 memset (destr_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2652 destr_fnlist
->fn_fieldlist
.name
2653 = obconcat (&objfile
->objfile_obstack
, "~",
2654 new_fnlist
->fn_fieldlist
.name
, (char *) NULL
);
2656 destr_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
2657 obstack_alloc (&objfile
->objfile_obstack
,
2658 sizeof (struct fn_field
) * has_destructor
);
2659 memset (destr_fnlist
->fn_fieldlist
.fn_fields
, 0,
2660 sizeof (struct fn_field
) * has_destructor
);
2661 tmp_sublist
= sublist
;
2662 last_sublist
= NULL
;
2664 while (tmp_sublist
!= NULL
)
2666 if (!is_destructor_name (tmp_sublist
->fn_field
.physname
))
2668 tmp_sublist
= tmp_sublist
->next
;
2672 destr_fnlist
->fn_fieldlist
.fn_fields
[i
++]
2673 = tmp_sublist
->fn_field
;
2675 last_sublist
->next
= tmp_sublist
->next
;
2677 sublist
= tmp_sublist
->next
;
2678 last_sublist
= tmp_sublist
;
2679 tmp_sublist
= tmp_sublist
->next
;
2682 destr_fnlist
->fn_fieldlist
.length
= has_destructor
;
2683 destr_fnlist
->next
= fip
->fnlist
;
2684 fip
->fnlist
= destr_fnlist
;
2686 total_length
+= has_destructor
;
2687 length
-= has_destructor
;
2691 /* v3 mangling prevents the use of abbreviated physnames,
2692 so we can do this here. There are stubbed methods in v3
2694 - in -gstabs instead of -gstabs+
2695 - or for static methods, which are output as a function type
2696 instead of a method type. */
2698 update_method_name_from_physname (&new_fnlist
->fn_fieldlist
.name
,
2699 sublist
->fn_field
.physname
);
2701 else if (has_destructor
&& new_fnlist
->fn_fieldlist
.name
[0] != '~')
2703 new_fnlist
->fn_fieldlist
.name
=
2704 concat ("~", main_fn_name
, (char *)NULL
);
2705 xfree (main_fn_name
);
2709 char dem_opname
[256];
2712 ret
= cplus_demangle_opname (new_fnlist
->fn_fieldlist
.name
,
2713 dem_opname
, DMGL_ANSI
);
2715 ret
= cplus_demangle_opname (new_fnlist
->fn_fieldlist
.name
,
2718 new_fnlist
->fn_fieldlist
.name
2719 = obsavestring (dem_opname
, strlen (dem_opname
),
2720 &objfile
->objfile_obstack
);
2723 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
2724 obstack_alloc (&objfile
->objfile_obstack
,
2725 sizeof (struct fn_field
) * length
);
2726 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
2727 sizeof (struct fn_field
) * length
);
2728 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2730 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2733 new_fnlist
->fn_fieldlist
.length
= length
;
2734 new_fnlist
->next
= fip
->fnlist
;
2735 fip
->fnlist
= new_fnlist
;
2737 total_length
+= length
;
2743 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2744 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2745 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2746 memset (TYPE_FN_FIELDLISTS (type
), 0,
2747 sizeof (struct fn_fieldlist
) * nfn_fields
);
2748 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2749 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2755 /* Special GNU C++ name.
2757 Returns 1 for success, 0 for failure. "failure" means that we can't
2758 keep parsing and it's time for error_type(). */
2761 read_cpp_abbrev (struct field_info
*fip
, char **pp
, struct type
*type
,
2762 struct objfile
*objfile
)
2767 struct type
*context
;
2777 /* At this point, *pp points to something like "22:23=*22...",
2778 where the type number before the ':' is the "context" and
2779 everything after is a regular type definition. Lookup the
2780 type, find it's name, and construct the field name. */
2782 context
= read_type (pp
, objfile
);
2786 case 'f': /* $vf -- a virtual function table pointer */
2787 name
= type_name_no_tag (context
);
2792 fip
->list
->field
.name
= obconcat (&objfile
->objfile_obstack
,
2793 vptr_name
, name
, (char *) NULL
);
2796 case 'b': /* $vb -- a virtual bsomethingorother */
2797 name
= type_name_no_tag (context
);
2800 complaint (&symfile_complaints
,
2801 _("C++ abbreviated type name "
2802 "unknown at symtab pos %d"),
2806 fip
->list
->field
.name
= obconcat (&objfile
->objfile_obstack
, vb_name
,
2807 name
, (char *) NULL
);
2811 invalid_cpp_abbrev_complaint (*pp
);
2812 fip
->list
->field
.name
= obconcat (&objfile
->objfile_obstack
,
2813 "INVALID_CPLUSPLUS_ABBREV",
2818 /* At this point, *pp points to the ':'. Skip it and read the
2824 invalid_cpp_abbrev_complaint (*pp
);
2827 fip
->list
->field
.type
= read_type (pp
, objfile
);
2829 (*pp
)++; /* Skip the comma. */
2836 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
,
2841 /* This field is unpacked. */
2842 FIELD_BITSIZE (fip
->list
->field
) = 0;
2843 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2847 invalid_cpp_abbrev_complaint (*pp
);
2848 /* We have no idea what syntax an unrecognized abbrev would have, so
2849 better return 0. If we returned 1, we would need to at least advance
2850 *pp to avoid an infinite loop. */
2857 read_one_struct_field (struct field_info
*fip
, char **pp
, char *p
,
2858 struct type
*type
, struct objfile
*objfile
)
2860 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
2862 fip
->list
->field
.name
=
2863 obsavestring (*pp
, p
- *pp
, &objfile
->objfile_obstack
);
2866 /* This means we have a visibility for a field coming. */
2870 fip
->list
->visibility
= *(*pp
)++;
2874 /* normal dbx-style format, no explicit visibility */
2875 fip
->list
->visibility
= VISIBILITY_PUBLIC
;
2878 fip
->list
->field
.type
= read_type (pp
, objfile
);
2883 /* Possible future hook for nested types. */
2886 fip
->list
->field
.bitpos
= (long) -2; /* nested type */
2896 /* Static class member. */
2897 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (*pp
, p
- *pp
));
2901 else if (**pp
!= ',')
2903 /* Bad structure-type format. */
2904 stabs_general_complaint ("bad structure-type format");
2908 (*pp
)++; /* Skip the comma. */
2913 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ',', &nbits
, 0);
2916 stabs_general_complaint ("bad structure-type format");
2919 FIELD_BITSIZE (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
, 0);
2922 stabs_general_complaint ("bad structure-type format");
2927 if (FIELD_BITPOS (fip
->list
->field
) == 0
2928 && FIELD_BITSIZE (fip
->list
->field
) == 0)
2930 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2931 it is a field which has been optimized out. The correct stab for
2932 this case is to use VISIBILITY_IGNORE, but that is a recent
2933 invention. (2) It is a 0-size array. For example
2934 union { int num; char str[0]; } foo. Printing _("<no value>" for
2935 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2936 will continue to work, and a 0-size array as a whole doesn't
2937 have any contents to print.
2939 I suspect this probably could also happen with gcc -gstabs (not
2940 -gstabs+) for static fields, and perhaps other C++ extensions.
2941 Hopefully few people use -gstabs with gdb, since it is intended
2942 for dbx compatibility. */
2944 /* Ignore this field. */
2945 fip
->list
->visibility
= VISIBILITY_IGNORE
;
2949 /* Detect an unpacked field and mark it as such.
2950 dbx gives a bit size for all fields.
2951 Note that forward refs cannot be packed,
2952 and treat enums as if they had the width of ints. */
2954 struct type
*field_type
= check_typedef (FIELD_TYPE (fip
->list
->field
));
2956 if (TYPE_CODE (field_type
) != TYPE_CODE_INT
2957 && TYPE_CODE (field_type
) != TYPE_CODE_RANGE
2958 && TYPE_CODE (field_type
) != TYPE_CODE_BOOL
2959 && TYPE_CODE (field_type
) != TYPE_CODE_ENUM
)
2961 FIELD_BITSIZE (fip
->list
->field
) = 0;
2963 if ((FIELD_BITSIZE (fip
->list
->field
)
2964 == TARGET_CHAR_BIT
* TYPE_LENGTH (field_type
)
2965 || (TYPE_CODE (field_type
) == TYPE_CODE_ENUM
2966 && FIELD_BITSIZE (fip
->list
->field
)
2967 == gdbarch_int_bit (gdbarch
))
2970 FIELD_BITPOS (fip
->list
->field
) % 8 == 0)
2972 FIELD_BITSIZE (fip
->list
->field
) = 0;
2978 /* Read struct or class data fields. They have the form:
2980 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2982 At the end, we see a semicolon instead of a field.
2984 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2987 The optional VISIBILITY is one of:
2989 '/0' (VISIBILITY_PRIVATE)
2990 '/1' (VISIBILITY_PROTECTED)
2991 '/2' (VISIBILITY_PUBLIC)
2992 '/9' (VISIBILITY_IGNORE)
2994 or nothing, for C style fields with public visibility.
2996 Returns 1 for success, 0 for failure. */
2999 read_struct_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3000 struct objfile
*objfile
)
3003 struct nextfield
*new;
3005 /* We better set p right now, in case there are no fields at all... */
3009 /* Read each data member type until we find the terminating ';' at the end of
3010 the data member list, or break for some other reason such as finding the
3011 start of the member function list. */
3012 /* Stab string for structure/union does not end with two ';' in
3013 SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
3015 while (**pp
!= ';' && **pp
!= '\0')
3017 STABS_CONTINUE (pp
, objfile
);
3018 /* Get space to record the next field's data. */
3019 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3020 make_cleanup (xfree
, new);
3021 memset (new, 0, sizeof (struct nextfield
));
3022 new->next
= fip
->list
;
3025 /* Get the field name. */
3028 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3029 unless the CPLUS_MARKER is followed by an underscore, in
3030 which case it is just the name of an anonymous type, which we
3031 should handle like any other type name. */
3033 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3035 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3040 /* Look for the ':' that separates the field name from the field
3041 values. Data members are delimited by a single ':', while member
3042 functions are delimited by a pair of ':'s. When we hit the member
3043 functions (if any), terminate scan loop and return. */
3045 while (*p
!= ':' && *p
!= '\0')
3052 /* Check to see if we have hit the member functions yet. */
3057 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3059 if (p
[0] == ':' && p
[1] == ':')
3061 /* (the deleted) chill the list of fields: the last entry (at
3062 the head) is a partially constructed entry which we now
3064 fip
->list
= fip
->list
->next
;
3069 /* The stabs for C++ derived classes contain baseclass information which
3070 is marked by a '!' character after the total size. This function is
3071 called when we encounter the baseclass marker, and slurps up all the
3072 baseclass information.
3074 Immediately following the '!' marker is the number of base classes that
3075 the class is derived from, followed by information for each base class.
3076 For each base class, there are two visibility specifiers, a bit offset
3077 to the base class information within the derived class, a reference to
3078 the type for the base class, and a terminating semicolon.
3080 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3082 Baseclass information marker __________________|| | | | | | |
3083 Number of baseclasses __________________________| | | | | | |
3084 Visibility specifiers (2) ________________________| | | | | |
3085 Offset in bits from start of class _________________| | | | |
3086 Type number for base class ___________________________| | | |
3087 Visibility specifiers (2) _______________________________| | |
3088 Offset in bits from start of class ________________________| |
3089 Type number of base class ____________________________________|
3091 Return 1 for success, 0 for (error-type-inducing) failure. */
3097 read_baseclasses (struct field_info
*fip
, char **pp
, struct type
*type
,
3098 struct objfile
*objfile
)
3101 struct nextfield
*new;
3109 /* Skip the '!' baseclass information marker. */
3113 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3117 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
, 0);
3123 /* Some stupid compilers have trouble with the following, so break
3124 it up into simpler expressions. */
3125 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3126 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3129 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3132 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3133 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3137 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3139 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3141 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3142 make_cleanup (xfree
, new);
3143 memset (new, 0, sizeof (struct nextfield
));
3144 new->next
= fip
->list
;
3146 FIELD_BITSIZE (new->field
) = 0; /* This should be an unpacked
3149 STABS_CONTINUE (pp
, objfile
);
3153 /* Nothing to do. */
3156 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3159 /* Unknown character. Complain and treat it as non-virtual. */
3161 complaint (&symfile_complaints
,
3162 _("Unknown virtual character `%c' for baseclass"),
3168 new->visibility
= *(*pp
)++;
3169 switch (new->visibility
)
3171 case VISIBILITY_PRIVATE
:
3172 case VISIBILITY_PROTECTED
:
3173 case VISIBILITY_PUBLIC
:
3176 /* Bad visibility format. Complain and treat it as
3179 complaint (&symfile_complaints
,
3180 _("Unknown visibility `%c' for baseclass"),
3182 new->visibility
= VISIBILITY_PUBLIC
;
3189 /* The remaining value is the bit offset of the portion of the object
3190 corresponding to this baseclass. Always zero in the absence of
3191 multiple inheritance. */
3193 FIELD_BITPOS (new->field
) = read_huge_number (pp
, ',', &nbits
, 0);
3198 /* The last piece of baseclass information is the type of the
3199 base class. Read it, and remember it's type name as this
3202 new->field
.type
= read_type (pp
, objfile
);
3203 new->field
.name
= type_name_no_tag (new->field
.type
);
3205 /* Skip trailing ';' and bump count of number of fields seen. */
3214 /* The tail end of stabs for C++ classes that contain a virtual function
3215 pointer contains a tilde, a %, and a type number.
3216 The type number refers to the base class (possibly this class itself) which
3217 contains the vtable pointer for the current class.
3219 This function is called when we have parsed all the method declarations,
3220 so we can look for the vptr base class info. */
3223 read_tilde_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3224 struct objfile
*objfile
)
3228 STABS_CONTINUE (pp
, objfile
);
3230 /* If we are positioned at a ';', then skip it. */
3240 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3242 /* Obsolete flags that used to indicate the presence
3243 of constructors and/or destructors. */
3247 /* Read either a '%' or the final ';'. */
3248 if (*(*pp
)++ == '%')
3250 /* The next number is the type number of the base class
3251 (possibly our own class) which supplies the vtable for
3252 this class. Parse it out, and search that class to find
3253 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3254 and TYPE_VPTR_FIELDNO. */
3259 t
= read_type (pp
, objfile
);
3261 while (*p
!= '\0' && *p
!= ';')
3267 /* Premature end of symbol. */
3271 TYPE_VPTR_BASETYPE (type
) = t
;
3272 if (type
== t
) /* Our own class provides vtbl ptr. */
3274 for (i
= TYPE_NFIELDS (t
) - 1;
3275 i
>= TYPE_N_BASECLASSES (t
);
3278 char *name
= TYPE_FIELD_NAME (t
, i
);
3280 if (!strncmp (name
, vptr_name
, sizeof (vptr_name
) - 2)
3281 && is_cplus_marker (name
[sizeof (vptr_name
) - 2]))
3283 TYPE_VPTR_FIELDNO (type
) = i
;
3287 /* Virtual function table field not found. */
3288 complaint (&symfile_complaints
,
3289 _("virtual function table pointer "
3290 "not found when defining class `%s'"),
3296 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3307 attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
)
3311 for (n
= TYPE_NFN_FIELDS (type
);
3312 fip
->fnlist
!= NULL
;
3313 fip
->fnlist
= fip
->fnlist
->next
)
3315 --n
; /* Circumvent Sun3 compiler bug. */
3316 TYPE_FN_FIELDLISTS (type
)[n
] = fip
->fnlist
->fn_fieldlist
;
3321 /* Create the vector of fields, and record how big it is.
3322 We need this info to record proper virtual function table information
3323 for this class's virtual functions. */
3326 attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3327 struct objfile
*objfile
)
3330 int non_public_fields
= 0;
3331 struct nextfield
*scan
;
3333 /* Count up the number of fields that we have, as well as taking note of
3334 whether or not there are any non-public fields, which requires us to
3335 allocate and build the private_field_bits and protected_field_bits
3338 for (scan
= fip
->list
; scan
!= NULL
; scan
= scan
->next
)
3341 if (scan
->visibility
!= VISIBILITY_PUBLIC
)
3343 non_public_fields
++;
3347 /* Now we know how many fields there are, and whether or not there are any
3348 non-public fields. Record the field count, allocate space for the
3349 array of fields, and create blank visibility bitfields if necessary. */
3351 TYPE_NFIELDS (type
) = nfields
;
3352 TYPE_FIELDS (type
) = (struct field
*)
3353 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3354 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3356 if (non_public_fields
)
3358 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3360 TYPE_FIELD_PRIVATE_BITS (type
) =
3361 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3362 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3364 TYPE_FIELD_PROTECTED_BITS (type
) =
3365 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3366 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3368 TYPE_FIELD_IGNORE_BITS (type
) =
3369 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3370 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3373 /* Copy the saved-up fields into the field vector. Start from the
3374 head of the list, adding to the tail of the field array, so that
3375 they end up in the same order in the array in which they were
3376 added to the list. */
3378 while (nfields
-- > 0)
3380 TYPE_FIELD (type
, nfields
) = fip
->list
->field
;
3381 switch (fip
->list
->visibility
)
3383 case VISIBILITY_PRIVATE
:
3384 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3387 case VISIBILITY_PROTECTED
:
3388 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3391 case VISIBILITY_IGNORE
:
3392 SET_TYPE_FIELD_IGNORE (type
, nfields
);
3395 case VISIBILITY_PUBLIC
:
3399 /* Unknown visibility. Complain and treat it as public. */
3401 complaint (&symfile_complaints
,
3402 _("Unknown visibility `%c' for field"),
3403 fip
->list
->visibility
);
3407 fip
->list
= fip
->list
->next
;
3413 /* Complain that the compiler has emitted more than one definition for the
3414 structure type TYPE. */
3416 complain_about_struct_wipeout (struct type
*type
)
3421 if (TYPE_TAG_NAME (type
))
3423 name
= TYPE_TAG_NAME (type
);
3424 switch (TYPE_CODE (type
))
3426 case TYPE_CODE_STRUCT
: kind
= "struct "; break;
3427 case TYPE_CODE_UNION
: kind
= "union "; break;
3428 case TYPE_CODE_ENUM
: kind
= "enum "; break;
3432 else if (TYPE_NAME (type
))
3434 name
= TYPE_NAME (type
);
3443 complaint (&symfile_complaints
,
3444 _("struct/union type gets multiply defined: %s%s"), kind
, name
);
3447 /* Set the length for all variants of a same main_type, which are
3448 connected in the closed chain.
3450 This is something that needs to be done when a type is defined *after*
3451 some cross references to this type have already been read. Consider
3452 for instance the following scenario where we have the following two
3455 .stabs "t:p(0,21)=*(0,22)=k(0,23)=xsdummy:",160,0,28,-24
3456 .stabs "dummy:T(0,23)=s16x:(0,1),0,3[...]"
3458 A stubbed version of type dummy is created while processing the first
3459 stabs entry. The length of that type is initially set to zero, since
3460 it is unknown at this point. Also, a "constant" variation of type
3461 "dummy" is created as well (this is the "(0,22)=k(0,23)" section of
3464 The second stabs entry allows us to replace the stubbed definition
3465 with the real definition. However, we still need to adjust the length
3466 of the "constant" variation of that type, as its length was left
3467 untouched during the main type replacement... */
3470 set_length_in_type_chain (struct type
*type
)
3472 struct type
*ntype
= TYPE_CHAIN (type
);
3474 while (ntype
!= type
)
3476 if (TYPE_LENGTH(ntype
) == 0)
3477 TYPE_LENGTH (ntype
) = TYPE_LENGTH (type
);
3479 complain_about_struct_wipeout (ntype
);
3480 ntype
= TYPE_CHAIN (ntype
);
3484 /* Read the description of a structure (or union type) and return an object
3485 describing the type.
3487 PP points to a character pointer that points to the next unconsumed token
3488 in the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3489 *PP will point to "4a:1,0,32;;".
3491 TYPE points to an incomplete type that needs to be filled in.
3493 OBJFILE points to the current objfile from which the stabs information is
3494 being read. (Note that it is redundant in that TYPE also contains a pointer
3495 to this same objfile, so it might be a good idea to eliminate it. FIXME).
3498 static struct type
*
3499 read_struct_type (char **pp
, struct type
*type
, enum type_code type_code
,
3500 struct objfile
*objfile
)
3502 struct cleanup
*back_to
;
3503 struct field_info fi
;
3508 /* When describing struct/union/class types in stabs, G++ always drops
3509 all qualifications from the name. So if you've got:
3510 struct A { ... struct B { ... }; ... };
3511 then G++ will emit stabs for `struct A::B' that call it simply
3512 `struct B'. Obviously, if you've got a real top-level definition for
3513 `struct B', or other nested definitions, this is going to cause
3516 Obviously, GDB can't fix this by itself, but it can at least avoid
3517 scribbling on existing structure type objects when new definitions
3519 if (! (TYPE_CODE (type
) == TYPE_CODE_UNDEF
3520 || TYPE_STUB (type
)))
3522 complain_about_struct_wipeout (type
);
3524 /* It's probably best to return the type unchanged. */
3528 back_to
= make_cleanup (null_cleanup
, 0);
3530 INIT_CPLUS_SPECIFIC (type
);
3531 TYPE_CODE (type
) = type_code
;
3532 TYPE_STUB (type
) = 0;
3534 /* First comes the total size in bytes. */
3539 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
, 0);
3541 return error_type (pp
, objfile
);
3542 set_length_in_type_chain (type
);
3545 /* Now read the baseclasses, if any, read the regular C struct or C++
3546 class member fields, attach the fields to the type, read the C++
3547 member functions, attach them to the type, and then read any tilde
3548 field (baseclass specifier for the class holding the main vtable). */
3550 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
3551 || !read_struct_fields (&fi
, pp
, type
, objfile
)
3552 || !attach_fields_to_type (&fi
, type
, objfile
)
3553 || !read_member_functions (&fi
, pp
, type
, objfile
)
3554 || !attach_fn_fields_to_type (&fi
, type
)
3555 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
3557 type
= error_type (pp
, objfile
);
3560 do_cleanups (back_to
);
3564 /* Read a definition of an array type,
3565 and create and return a suitable type object.
3566 Also creates a range type which represents the bounds of that
3569 static struct type
*
3570 read_array_type (char **pp
, struct type
*type
,
3571 struct objfile
*objfile
)
3573 struct type
*index_type
, *element_type
, *range_type
;
3578 /* Format of an array type:
3579 "ar<index type>;lower;upper;<array_contents_type>".
3580 OS9000: "arlower,upper;<array_contents_type>".
3582 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3583 for these, produce a type like float[][]. */
3586 index_type
= read_type (pp
, objfile
);
3588 /* Improper format of array type decl. */
3589 return error_type (pp
, objfile
);
3593 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3598 lower
= read_huge_number (pp
, ';', &nbits
, 0);
3601 return error_type (pp
, objfile
);
3603 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3608 upper
= read_huge_number (pp
, ';', &nbits
, 0);
3610 return error_type (pp
, objfile
);
3612 element_type
= read_type (pp
, objfile
);
3621 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
3622 type
= create_array_type (type
, element_type
, range_type
);
3628 /* Read a definition of an enumeration type,
3629 and create and return a suitable type object.
3630 Also defines the symbols that represent the values of the type. */
3632 static struct type
*
3633 read_enum_type (char **pp
, struct type
*type
,
3634 struct objfile
*objfile
)
3636 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
3642 struct pending
**symlist
;
3643 struct pending
*osyms
, *syms
;
3646 int unsigned_enum
= 1;
3649 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3650 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3651 to do? For now, force all enum values to file scope. */
3652 if (within_function
)
3653 symlist
= &local_symbols
;
3656 symlist
= &file_symbols
;
3658 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3660 /* The aix4 compiler emits an extra field before the enum members;
3661 my guess is it's a type of some sort. Just ignore it. */
3664 /* Skip over the type. */
3668 /* Skip over the colon. */
3672 /* Read the value-names and their values.
3673 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3674 A semicolon or comma instead of a NAME means the end. */
3675 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3677 STABS_CONTINUE (pp
, objfile
);
3681 name
= obsavestring (*pp
, p
- *pp
, &objfile
->objfile_obstack
);
3683 n
= read_huge_number (pp
, ',', &nbits
, 0);
3685 return error_type (pp
, objfile
);
3687 sym
= (struct symbol
*)
3688 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct symbol
));
3689 memset (sym
, 0, sizeof (struct symbol
));
3690 SYMBOL_SET_LINKAGE_NAME (sym
, name
);
3691 SYMBOL_SET_LANGUAGE (sym
, current_subfile
->language
);
3692 SYMBOL_CLASS (sym
) = LOC_CONST
;
3693 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
3694 SYMBOL_VALUE (sym
) = n
;
3697 add_symbol_to_list (sym
, symlist
);
3702 (*pp
)++; /* Skip the semicolon. */
3704 /* Now fill in the fields of the type-structure. */
3706 TYPE_LENGTH (type
) = gdbarch_int_bit (gdbarch
) / HOST_CHAR_BIT
;
3707 set_length_in_type_chain (type
);
3708 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3709 TYPE_STUB (type
) = 0;
3711 TYPE_UNSIGNED (type
) = 1;
3712 TYPE_NFIELDS (type
) = nsyms
;
3713 TYPE_FIELDS (type
) = (struct field
*)
3714 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3715 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3717 /* Find the symbols for the values and put them into the type.
3718 The symbols can be found in the symlist that we put them on
3719 to cause them to be defined. osyms contains the old value
3720 of that symlist; everything up to there was defined by us. */
3721 /* Note that we preserve the order of the enum constants, so
3722 that in something like "enum {FOO, LAST_THING=FOO}" we print
3723 FOO, not LAST_THING. */
3725 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
3727 int last
= syms
== osyms
? o_nsyms
: 0;
3728 int j
= syms
->nsyms
;
3730 for (; --j
>= last
; --n
)
3732 struct symbol
*xsym
= syms
->symbol
[j
];
3734 SYMBOL_TYPE (xsym
) = type
;
3735 TYPE_FIELD_NAME (type
, n
) = SYMBOL_LINKAGE_NAME (xsym
);
3736 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3737 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3746 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3747 typedefs in every file (for int, long, etc):
3749 type = b <signed> <width> <format type>; <offset>; <nbits>
3751 optional format type = c or b for char or boolean.
3752 offset = offset from high order bit to start bit of type.
3753 width is # bytes in object of this type, nbits is # bits in type.
3755 The width/offset stuff appears to be for small objects stored in
3756 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3759 static struct type
*
3760 read_sun_builtin_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
3765 enum type_code code
= TYPE_CODE_INT
;
3776 return error_type (pp
, objfile
);
3780 /* For some odd reason, all forms of char put a c here. This is strange
3781 because no other type has this honor. We can safely ignore this because
3782 we actually determine 'char'acterness by the number of bits specified in
3784 Boolean forms, e.g Fortran logical*X, put a b here. */
3788 else if (**pp
== 'b')
3790 code
= TYPE_CODE_BOOL
;
3794 /* The first number appears to be the number of bytes occupied
3795 by this type, except that unsigned short is 4 instead of 2.
3796 Since this information is redundant with the third number,
3797 we will ignore it. */
3798 read_huge_number (pp
, ';', &nbits
, 0);
3800 return error_type (pp
, objfile
);
3802 /* The second number is always 0, so ignore it too. */
3803 read_huge_number (pp
, ';', &nbits
, 0);
3805 return error_type (pp
, objfile
);
3807 /* The third number is the number of bits for this type. */
3808 type_bits
= read_huge_number (pp
, 0, &nbits
, 0);
3810 return error_type (pp
, objfile
);
3811 /* The type *should* end with a semicolon. If it are embedded
3812 in a larger type the semicolon may be the only way to know where
3813 the type ends. If this type is at the end of the stabstring we
3814 can deal with the omitted semicolon (but we don't have to like
3815 it). Don't bother to complain(), Sun's compiler omits the semicolon
3821 return init_type (TYPE_CODE_VOID
, 1,
3822 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
3825 return init_type (code
,
3826 type_bits
/ TARGET_CHAR_BIT
,
3827 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
3831 static struct type
*
3832 read_sun_floating_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
3837 struct type
*rettype
;
3839 /* The first number has more details about the type, for example
3841 details
= read_huge_number (pp
, ';', &nbits
, 0);
3843 return error_type (pp
, objfile
);
3845 /* The second number is the number of bytes occupied by this type. */
3846 nbytes
= read_huge_number (pp
, ';', &nbits
, 0);
3848 return error_type (pp
, objfile
);
3850 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3851 || details
== NF_COMPLEX32
)
3853 rettype
= init_type (TYPE_CODE_COMPLEX
, nbytes
, 0, NULL
, objfile
);
3854 TYPE_TARGET_TYPE (rettype
)
3855 = init_type (TYPE_CODE_FLT
, nbytes
/ 2, 0, NULL
, objfile
);
3859 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3862 /* Read a number from the string pointed to by *PP.
3863 The value of *PP is advanced over the number.
3864 If END is nonzero, the character that ends the
3865 number must match END, or an error happens;
3866 and that character is skipped if it does match.
3867 If END is zero, *PP is left pointing to that character.
3869 If TWOS_COMPLEMENT_BITS is set to a strictly positive value and if
3870 the number is represented in an octal representation, assume that
3871 it is represented in a 2's complement representation with a size of
3872 TWOS_COMPLEMENT_BITS.
3874 If the number fits in a long, set *BITS to 0 and return the value.
3875 If not, set *BITS to be the number of bits in the number and return 0.
3877 If encounter garbage, set *BITS to -1 and return 0. */
3880 read_huge_number (char **pp
, int end
, int *bits
, int twos_complement_bits
)
3891 int twos_complement_representation
= 0;
3899 /* Leading zero means octal. GCC uses this to output values larger
3900 than an int (because that would be hard in decimal). */
3907 /* Skip extra zeros. */
3911 if (sign
> 0 && radix
== 8 && twos_complement_bits
> 0)
3913 /* Octal, possibly signed. Check if we have enough chars for a
3919 while ((c
= *p1
) >= '0' && c
< '8')
3923 if (len
> twos_complement_bits
/ 3
3924 || (twos_complement_bits
% 3 == 0
3925 && len
== twos_complement_bits
/ 3))
3927 /* Ok, we have enough characters for a signed value, check
3928 for signness by testing if the sign bit is set. */
3929 sign_bit
= (twos_complement_bits
% 3 + 2) % 3;
3931 if (c
& (1 << sign_bit
))
3933 /* Definitely signed. */
3934 twos_complement_representation
= 1;
3940 upper_limit
= LONG_MAX
/ radix
;
3942 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
3944 if (n
<= upper_limit
)
3946 if (twos_complement_representation
)
3948 /* Octal, signed, twos complement representation. In
3949 this case, n is the corresponding absolute value. */
3952 long sn
= c
- '0' - ((2 * (c
- '0')) | (2 << sign_bit
));
3964 /* unsigned representation */
3966 n
+= c
- '0'; /* FIXME this overflows anyway. */
3972 /* This depends on large values being output in octal, which is
3979 /* Ignore leading zeroes. */
3983 else if (c
== '2' || c
== '3')
4004 if (radix
== 8 && twos_complement_bits
> 0 && nbits
> twos_complement_bits
)
4006 /* We were supposed to parse a number with maximum
4007 TWOS_COMPLEMENT_BITS bits, but something went wrong. */
4018 /* Large decimal constants are an error (because it is hard to
4019 count how many bits are in them). */
4025 /* -0x7f is the same as 0x80. So deal with it by adding one to
4026 the number of bits. Two's complement represention octals
4027 can't have a '-' in front. */
4028 if (sign
== -1 && !twos_complement_representation
)
4039 /* It's *BITS which has the interesting information. */
4043 static struct type
*
4044 read_range_type (char **pp
, int typenums
[2], int type_size
,
4045 struct objfile
*objfile
)
4047 struct gdbarch
*gdbarch
= get_objfile_arch (objfile
);
4048 char *orig_pp
= *pp
;
4053 struct type
*result_type
;
4054 struct type
*index_type
= NULL
;
4056 /* First comes a type we are a subrange of.
4057 In C it is usually 0, 1 or the type being defined. */
4058 if (read_type_number (pp
, rangenums
) != 0)
4059 return error_type (pp
, objfile
);
4060 self_subrange
= (rangenums
[0] == typenums
[0] &&
4061 rangenums
[1] == typenums
[1]);
4066 index_type
= read_type (pp
, objfile
);
4069 /* A semicolon should now follow; skip it. */
4073 /* The remaining two operands are usually lower and upper bounds
4074 of the range. But in some special cases they mean something else. */
4075 n2
= read_huge_number (pp
, ';', &n2bits
, type_size
);
4076 n3
= read_huge_number (pp
, ';', &n3bits
, type_size
);
4078 if (n2bits
== -1 || n3bits
== -1)
4079 return error_type (pp
, objfile
);
4082 goto handle_true_range
;
4084 /* If limits are huge, must be large integral type. */
4085 if (n2bits
!= 0 || n3bits
!= 0)
4087 char got_signed
= 0;
4088 char got_unsigned
= 0;
4089 /* Number of bits in the type. */
4092 /* If a type size attribute has been specified, the bounds of
4093 the range should fit in this size. If the lower bounds needs
4094 more bits than the upper bound, then the type is signed. */
4095 if (n2bits
<= type_size
&& n3bits
<= type_size
)
4097 if (n2bits
== type_size
&& n2bits
> n3bits
)
4103 /* Range from 0 to <large number> is an unsigned large integral type. */
4104 else if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4109 /* Range from <large number> to <large number>-1 is a large signed
4110 integral type. Take care of the case where <large number> doesn't
4111 fit in a long but <large number>-1 does. */
4112 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4113 || (n2bits
!= 0 && n3bits
== 0
4114 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4121 if (got_signed
|| got_unsigned
)
4123 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4124 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4128 return error_type (pp
, objfile
);
4131 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4132 if (self_subrange
&& n2
== 0 && n3
== 0)
4133 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4135 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4136 is the width in bytes.
4138 Fortran programs appear to use this for complex types also. To
4139 distinguish between floats and complex, g77 (and others?) seem
4140 to use self-subranges for the complexes, and subranges of int for
4143 Also note that for complexes, g77 sets n2 to the size of one of
4144 the member floats, not the whole complex beast. My guess is that
4145 this was to work well with pre-COMPLEX versions of gdb. */
4147 if (n3
== 0 && n2
> 0)
4149 struct type
*float_type
4150 = init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4154 struct type
*complex_type
=
4155 init_type (TYPE_CODE_COMPLEX
, 2 * n2
, 0, NULL
, objfile
);
4157 TYPE_TARGET_TYPE (complex_type
) = float_type
;
4158 return complex_type
;
4164 /* If the upper bound is -1, it must really be an unsigned integral. */
4166 else if (n2
== 0 && n3
== -1)
4168 int bits
= type_size
;
4172 /* We don't know its size. It is unsigned int or unsigned
4173 long. GCC 2.3.3 uses this for long long too, but that is
4174 just a GDB 3.5 compatibility hack. */
4175 bits
= gdbarch_int_bit (gdbarch
);
4178 return init_type (TYPE_CODE_INT
, bits
/ TARGET_CHAR_BIT
,
4179 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4182 /* Special case: char is defined (Who knows why) as a subrange of
4183 itself with range 0-127. */
4184 else if (self_subrange
&& n2
== 0 && n3
== 127)
4185 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_NOSIGN
, NULL
, objfile
);
4187 /* We used to do this only for subrange of self or subrange of int. */
4190 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4191 "unsigned long", and we already checked for that,
4192 so don't need to test for it here. */
4195 /* n3 actually gives the size. */
4196 return init_type (TYPE_CODE_INT
, -n3
, TYPE_FLAG_UNSIGNED
,
4199 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4200 unsigned n-byte integer. But do require n to be a power of
4201 two; we don't want 3- and 5-byte integers flying around. */
4207 for (bytes
= 0; (bits
& 0xff) == 0xff; bytes
++)
4210 && ((bytes
- 1) & bytes
) == 0) /* "bytes is a power of two" */
4211 return init_type (TYPE_CODE_INT
, bytes
, TYPE_FLAG_UNSIGNED
, NULL
,
4215 /* I think this is for Convex "long long". Since I don't know whether
4216 Convex sets self_subrange, I also accept that particular size regardless
4217 of self_subrange. */
4218 else if (n3
== 0 && n2
< 0
4220 || n2
== -gdbarch_long_long_bit
4221 (gdbarch
) / TARGET_CHAR_BIT
))
4222 return init_type (TYPE_CODE_INT
, -n2
, 0, NULL
, objfile
);
4223 else if (n2
== -n3
- 1)
4226 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4228 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4229 if (n3
== 0x7fffffff)
4230 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4233 /* We have a real range type on our hands. Allocate space and
4234 return a real pointer. */
4238 index_type
= objfile_type (objfile
)->builtin_int
;
4240 index_type
= *dbx_lookup_type (rangenums
, objfile
);
4241 if (index_type
== NULL
)
4243 /* Does this actually ever happen? Is that why we are worrying
4244 about dealing with it rather than just calling error_type? */
4246 complaint (&symfile_complaints
,
4247 _("base type %d of range type is not defined"), rangenums
[1]);
4249 index_type
= objfile_type (objfile
)->builtin_int
;
4252 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4253 return (result_type
);
4256 /* Read in an argument list. This is a list of types, separated by commas
4257 and terminated with END. Return the list of types read in, or NULL
4258 if there is an error. */
4260 static struct field
*
4261 read_args (char **pp
, int end
, struct objfile
*objfile
, int *nargsp
,
4264 /* FIXME! Remove this arbitrary limit! */
4265 struct type
*types
[1024]; /* Allow for fns of 1023 parameters. */
4272 /* Invalid argument list: no ','. */
4275 STABS_CONTINUE (pp
, objfile
);
4276 types
[n
++] = read_type (pp
, objfile
);
4278 (*pp
)++; /* get past `end' (the ':' character). */
4282 /* We should read at least the THIS parameter here. Some broken stabs
4283 output contained `(0,41),(0,42)=@s8;-16;,(0,43),(0,1);' where should
4284 have been present ";-16,(0,43)" reference instead. This way the
4285 excessive ";" marker prematurely stops the parameters parsing. */
4287 complaint (&symfile_complaints
, _("Invalid (empty) method arguments"));
4290 else if (TYPE_CODE (types
[n
- 1]) != TYPE_CODE_VOID
)
4298 rval
= (struct field
*) xmalloc (n
* sizeof (struct field
));
4299 memset (rval
, 0, n
* sizeof (struct field
));
4300 for (i
= 0; i
< n
; i
++)
4301 rval
[i
].type
= types
[i
];
4306 /* Common block handling. */
4308 /* List of symbols declared since the last BCOMM. This list is a tail
4309 of local_symbols. When ECOMM is seen, the symbols on the list
4310 are noted so their proper addresses can be filled in later,
4311 using the common block base address gotten from the assembler
4314 static struct pending
*common_block
;
4315 static int common_block_i
;
4317 /* Name of the current common block. We get it from the BCOMM instead of the
4318 ECOMM to match IBM documentation (even though IBM puts the name both places
4319 like everyone else). */
4320 static char *common_block_name
;
4322 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4323 to remain after this function returns. */
4326 common_block_start (char *name
, struct objfile
*objfile
)
4328 if (common_block_name
!= NULL
)
4330 complaint (&symfile_complaints
,
4331 _("Invalid symbol data: common block within common block"));
4333 common_block
= local_symbols
;
4334 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
4335 common_block_name
= obsavestring (name
, strlen (name
),
4336 &objfile
->objfile_obstack
);
4339 /* Process a N_ECOMM symbol. */
4342 common_block_end (struct objfile
*objfile
)
4344 /* Symbols declared since the BCOMM are to have the common block
4345 start address added in when we know it. common_block and
4346 common_block_i point to the first symbol after the BCOMM in
4347 the local_symbols list; copy the list and hang it off the
4348 symbol for the common block name for later fixup. */
4351 struct pending
*new = 0;
4352 struct pending
*next
;
4355 if (common_block_name
== NULL
)
4357 complaint (&symfile_complaints
, _("ECOMM symbol unmatched by BCOMM"));
4361 sym
= (struct symbol
*)
4362 obstack_alloc (&objfile
->objfile_obstack
, sizeof (struct symbol
));
4363 memset (sym
, 0, sizeof (struct symbol
));
4364 /* Note: common_block_name already saved on objfile_obstack. */
4365 SYMBOL_SET_LINKAGE_NAME (sym
, common_block_name
);
4366 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
4368 /* Now we copy all the symbols which have been defined since the BCOMM. */
4370 /* Copy all the struct pendings before common_block. */
4371 for (next
= local_symbols
;
4372 next
!= NULL
&& next
!= common_block
;
4375 for (j
= 0; j
< next
->nsyms
; j
++)
4376 add_symbol_to_list (next
->symbol
[j
], &new);
4379 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4380 NULL, it means copy all the local symbols (which we already did
4383 if (common_block
!= NULL
)
4384 for (j
= common_block_i
; j
< common_block
->nsyms
; j
++)
4385 add_symbol_to_list (common_block
->symbol
[j
], &new);
4387 SYMBOL_TYPE (sym
) = (struct type
*) new;
4389 /* Should we be putting local_symbols back to what it was?
4392 i
= hashname (SYMBOL_LINKAGE_NAME (sym
));
4393 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
4394 global_sym_chain
[i
] = sym
;
4395 common_block_name
= NULL
;
4398 /* Add a common block's start address to the offset of each symbol
4399 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4400 the common block name). */
4403 fix_common_block (struct symbol
*sym
, int valu
)
4405 struct pending
*next
= (struct pending
*) SYMBOL_TYPE (sym
);
4407 for (; next
; next
= next
->next
)
4411 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4412 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4418 /* Add {TYPE, TYPENUMS} to the NONAME_UNDEFS vector.
4419 See add_undefined_type for more details. */
4422 add_undefined_type_noname (struct type
*type
, int typenums
[2])
4426 nat
.typenums
[0] = typenums
[0];
4427 nat
.typenums
[1] = typenums
[1];
4430 if (noname_undefs_length
== noname_undefs_allocated
)
4432 noname_undefs_allocated
*= 2;
4433 noname_undefs
= (struct nat
*)
4434 xrealloc ((char *) noname_undefs
,
4435 noname_undefs_allocated
* sizeof (struct nat
));
4437 noname_undefs
[noname_undefs_length
++] = nat
;
4440 /* Add TYPE to the UNDEF_TYPES vector.
4441 See add_undefined_type for more details. */
4444 add_undefined_type_1 (struct type
*type
)
4446 if (undef_types_length
== undef_types_allocated
)
4448 undef_types_allocated
*= 2;
4449 undef_types
= (struct type
**)
4450 xrealloc ((char *) undef_types
,
4451 undef_types_allocated
* sizeof (struct type
*));
4453 undef_types
[undef_types_length
++] = type
;
4456 /* What about types defined as forward references inside of a small lexical
4458 /* Add a type to the list of undefined types to be checked through
4459 once this file has been read in.
4461 In practice, we actually maintain two such lists: The first list
4462 (UNDEF_TYPES) is used for types whose name has been provided, and
4463 concerns forward references (eg 'xs' or 'xu' forward references);
4464 the second list (NONAME_UNDEFS) is used for types whose name is
4465 unknown at creation time, because they were referenced through
4466 their type number before the actual type was declared.
4467 This function actually adds the given type to the proper list. */
4470 add_undefined_type (struct type
*type
, int typenums
[2])
4472 if (TYPE_TAG_NAME (type
) == NULL
)
4473 add_undefined_type_noname (type
, typenums
);
4475 add_undefined_type_1 (type
);
4478 /* Try to fix all undefined types pushed on the UNDEF_TYPES vector. */
4481 cleanup_undefined_types_noname (struct objfile
*objfile
)
4485 for (i
= 0; i
< noname_undefs_length
; i
++)
4487 struct nat nat
= noname_undefs
[i
];
4490 type
= dbx_lookup_type (nat
.typenums
, objfile
);
4491 if (nat
.type
!= *type
&& TYPE_CODE (*type
) != TYPE_CODE_UNDEF
)
4493 /* The instance flags of the undefined type are still unset,
4494 and needs to be copied over from the reference type.
4495 Since replace_type expects them to be identical, we need
4496 to set these flags manually before hand. */
4497 TYPE_INSTANCE_FLAGS (nat
.type
) = TYPE_INSTANCE_FLAGS (*type
);
4498 replace_type (nat
.type
, *type
);
4502 noname_undefs_length
= 0;
4505 /* Go through each undefined type, see if it's still undefined, and fix it
4506 up if possible. We have two kinds of undefined types:
4508 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4509 Fix: update array length using the element bounds
4510 and the target type's length.
4511 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4512 yet defined at the time a pointer to it was made.
4513 Fix: Do a full lookup on the struct/union tag. */
4516 cleanup_undefined_types_1 (void)
4520 /* Iterate over every undefined type, and look for a symbol whose type
4521 matches our undefined type. The symbol matches if:
4522 1. It is a typedef in the STRUCT domain;
4523 2. It has the same name, and same type code;
4524 3. The instance flags are identical.
4526 It is important to check the instance flags, because we have seen
4527 examples where the debug info contained definitions such as:
4529 "foo_t:t30=B31=xefoo_t:"
4531 In this case, we have created an undefined type named "foo_t" whose
4532 instance flags is null (when processing "xefoo_t"), and then created
4533 another type with the same name, but with different instance flags
4534 ('B' means volatile). I think that the definition above is wrong,
4535 since the same type cannot be volatile and non-volatile at the same
4536 time, but we need to be able to cope with it when it happens. The
4537 approach taken here is to treat these two types as different. */
4539 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4541 switch (TYPE_CODE (*type
))
4544 case TYPE_CODE_STRUCT
:
4545 case TYPE_CODE_UNION
:
4546 case TYPE_CODE_ENUM
:
4548 /* Check if it has been defined since. Need to do this here
4549 as well as in check_typedef to deal with the (legitimate in
4550 C though not C++) case of several types with the same name
4551 in different source files. */
4552 if (TYPE_STUB (*type
))
4554 struct pending
*ppt
;
4556 /* Name of the type, without "struct" or "union". */
4557 char *typename
= TYPE_TAG_NAME (*type
);
4559 if (typename
== NULL
)
4561 complaint (&symfile_complaints
, _("need a type name"));
4564 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4566 for (i
= 0; i
< ppt
->nsyms
; i
++)
4568 struct symbol
*sym
= ppt
->symbol
[i
];
4570 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4571 && SYMBOL_DOMAIN (sym
) == STRUCT_DOMAIN
4572 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4574 && (TYPE_INSTANCE_FLAGS (*type
) ==
4575 TYPE_INSTANCE_FLAGS (SYMBOL_TYPE (sym
)))
4576 && strcmp (SYMBOL_LINKAGE_NAME (sym
),
4578 replace_type (*type
, SYMBOL_TYPE (sym
));
4587 complaint (&symfile_complaints
,
4588 _("forward-referenced types left unresolved, "
4596 undef_types_length
= 0;
4599 /* Try to fix all the undefined types we ecountered while processing
4603 cleanup_undefined_types (struct objfile
*objfile
)
4605 cleanup_undefined_types_1 ();
4606 cleanup_undefined_types_noname (objfile
);
4609 /* Scan through all of the global symbols defined in the object file,
4610 assigning values to the debugging symbols that need to be assigned
4611 to. Get these symbols from the minimal symbol table. */
4614 scan_file_globals (struct objfile
*objfile
)
4617 struct minimal_symbol
*msymbol
;
4618 struct symbol
*sym
, *prev
;
4619 struct objfile
*resolve_objfile
;
4621 /* SVR4 based linkers copy referenced global symbols from shared
4622 libraries to the main executable.
4623 If we are scanning the symbols for a shared library, try to resolve
4624 them from the minimal symbols of the main executable first. */
4626 if (symfile_objfile
&& objfile
!= symfile_objfile
)
4627 resolve_objfile
= symfile_objfile
;
4629 resolve_objfile
= objfile
;
4633 /* Avoid expensive loop through all minimal symbols if there are
4634 no unresolved symbols. */
4635 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4637 if (global_sym_chain
[hash
])
4640 if (hash
>= HASHSIZE
)
4643 ALL_OBJFILE_MSYMBOLS (resolve_objfile
, msymbol
)
4647 /* Skip static symbols. */
4648 switch (MSYMBOL_TYPE (msymbol
))
4660 /* Get the hash index and check all the symbols
4661 under that hash index. */
4663 hash
= hashname (SYMBOL_LINKAGE_NAME (msymbol
));
4665 for (sym
= global_sym_chain
[hash
]; sym
;)
4667 if (strcmp (SYMBOL_LINKAGE_NAME (msymbol
),
4668 SYMBOL_LINKAGE_NAME (sym
)) == 0)
4670 /* Splice this symbol out of the hash chain and
4671 assign the value we have to it. */
4674 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
4678 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
4681 /* Check to see whether we need to fix up a common block. */
4682 /* Note: this code might be executed several times for
4683 the same symbol if there are multiple references. */
4686 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
4688 fix_common_block (sym
,
4689 SYMBOL_VALUE_ADDRESS (msymbol
));
4693 SYMBOL_VALUE_ADDRESS (sym
)
4694 = SYMBOL_VALUE_ADDRESS (msymbol
);
4696 SYMBOL_SECTION (sym
) = SYMBOL_SECTION (msymbol
);
4701 sym
= SYMBOL_VALUE_CHAIN (prev
);
4705 sym
= global_sym_chain
[hash
];
4711 sym
= SYMBOL_VALUE_CHAIN (sym
);
4715 if (resolve_objfile
== objfile
)
4717 resolve_objfile
= objfile
;
4720 /* Change the storage class of any remaining unresolved globals to
4721 LOC_UNRESOLVED and remove them from the chain. */
4722 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4724 sym
= global_sym_chain
[hash
];
4728 sym
= SYMBOL_VALUE_CHAIN (sym
);
4730 /* Change the symbol address from the misleading chain value
4732 SYMBOL_VALUE_ADDRESS (prev
) = 0;
4734 /* Complain about unresolved common block symbols. */
4735 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
4736 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
4738 complaint (&symfile_complaints
,
4739 _("%s: common block `%s' from "
4740 "global_sym_chain unresolved"),
4741 objfile
->name
, SYMBOL_PRINT_NAME (prev
));
4744 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4747 /* Initialize anything that needs initializing when starting to read
4748 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4752 stabsread_init (void)
4756 /* Initialize anything that needs initializing when a completely new
4757 symbol file is specified (not just adding some symbols from another
4758 file, e.g. a shared library). */
4761 stabsread_new_init (void)
4763 /* Empty the hash table of global syms looking for values. */
4764 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4767 /* Initialize anything that needs initializing at the same time as
4768 start_symtab() is called. */
4773 global_stabs
= NULL
; /* AIX COFF */
4774 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4775 n_this_object_header_files
= 1;
4776 type_vector_length
= 0;
4777 type_vector
= (struct type
**) 0;
4779 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4780 common_block_name
= NULL
;
4783 /* Call after end_symtab(). */
4790 xfree (type_vector
);
4793 type_vector_length
= 0;
4794 previous_stab_code
= 0;
4798 finish_global_stabs (struct objfile
*objfile
)
4802 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
4803 xfree (global_stabs
);
4804 global_stabs
= NULL
;
4808 /* Find the end of the name, delimited by a ':', but don't match
4809 ObjC symbols which look like -[Foo bar::]:bla. */
4811 find_name_end (char *name
)
4815 if (s
[0] == '-' || *s
== '+')
4817 /* Must be an ObjC method symbol. */
4820 error (_("invalid symbol name \"%s\""), name
);
4822 s
= strchr (s
, ']');
4825 error (_("invalid symbol name \"%s\""), name
);
4827 return strchr (s
, ':');
4831 return strchr (s
, ':');
4835 /* Initializer for this module. */
4838 _initialize_stabsread (void)
4840 rs6000_builtin_type_data
= register_objfile_data ();
4842 undef_types_allocated
= 20;
4843 undef_types_length
= 0;
4844 undef_types
= (struct type
**)
4845 xmalloc (undef_types_allocated
* sizeof (struct type
*));
4847 noname_undefs_allocated
= 20;
4848 noname_undefs_length
= 0;
4849 noname_undefs
= (struct nat
*)
4850 xmalloc (noname_undefs_allocated
* sizeof (struct nat
));