1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995,
3 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003
4 Free Software Foundation, Inc.
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
23 /* Support routines for reading and decoding debugging information in
24 the "stabs" format. This format is used with many systems that use
25 the a.out object file format, as well as some systems that use
26 COFF or ELF where the stabs data is placed in a special section.
27 Avoid placing any object file format specific code in this file. */
30 #include "gdb_string.h"
32 #include "gdb_obstack.h"
35 #include "expression.h"
38 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
40 #include "aout/aout64.h"
41 #include "gdb-stabs.h"
43 #include "complaints.h"
48 #include "cp-support.h"
52 /* Ask stabsread.h to define the vars it normally declares `extern'. */
55 #include "stabsread.h" /* Our own declarations */
58 extern void _initialize_stabsread (void);
60 /* The routines that read and process a complete stabs for a C struct or
61 C++ class pass lists of data member fields and lists of member function
62 fields in an instance of a field_info structure, as defined below.
63 This is part of some reorganization of low level C++ support and is
64 expected to eventually go away... (FIXME) */
70 struct nextfield
*next
;
72 /* This is the raw visibility from the stab. It is not checked
73 for being one of the visibilities we recognize, so code which
74 examines this field better be able to deal. */
80 struct next_fnfieldlist
82 struct next_fnfieldlist
*next
;
83 struct fn_fieldlist fn_fieldlist
;
89 read_one_struct_field (struct field_info
*, char **, char *,
90 struct type
*, struct objfile
*);
92 static char *get_substring (char **, int);
94 static struct type
*dbx_alloc_type (int[2], struct objfile
*);
96 static long read_huge_number (char **, int, int *);
98 static struct type
*error_type (char **, struct objfile
*);
101 patch_block_stabs (struct pending
*, struct pending_stabs
*,
104 static void fix_common_block (struct symbol
*, int);
106 static int read_type_number (char **, int *);
108 static struct type
*read_type (char **, struct objfile
*);
110 static struct type
*read_range_type (char **, int[2], struct objfile
*);
112 static struct type
*read_sun_builtin_type (char **, int[2], struct objfile
*);
114 static struct type
*read_sun_floating_type (char **, int[2],
117 static struct type
*read_enum_type (char **, struct type
*, struct objfile
*);
119 static struct type
*rs6000_builtin_type (int);
122 read_member_functions (struct field_info
*, char **, struct type
*,
126 read_struct_fields (struct field_info
*, char **, struct type
*,
130 read_baseclasses (struct field_info
*, char **, struct type
*,
134 read_tilde_fields (struct field_info
*, char **, struct type
*,
137 static int attach_fn_fields_to_type (struct field_info
*, struct type
*);
139 static int attach_fields_to_type (struct field_info
*, struct type
*,
142 static struct type
*read_struct_type (char **, struct type
*,
146 static struct type
*read_array_type (char **, struct type
*,
149 static struct field
*read_args (char **, int, struct objfile
*, int *, int *);
151 static void add_undefined_type (struct type
*);
154 read_cpp_abbrev (struct field_info
*, char **, struct type
*,
157 static char *find_name_end (char *name
);
159 static void add_live_range (struct objfile
*, struct symbol
*, CORE_ADDR
,
162 static int resolve_live_range (struct objfile
*, struct symbol
*, char *);
164 static int process_reference (char **string
);
166 static CORE_ADDR
ref_search_value (int refnum
);
168 static int resolve_symbol_reference (struct objfile
*, struct symbol
*,
171 void stabsread_clear_cache (void);
173 static const char vptr_name
[] = "_vptr$";
174 static const char vb_name
[] = "_vb$";
176 /* Define this as 1 if a pcc declaration of a char or short argument
177 gives the correct address. Otherwise assume pcc gives the
178 address of the corresponding int, which is not the same on a
179 big-endian machine. */
181 #if !defined (BELIEVE_PCC_PROMOTION)
182 #define BELIEVE_PCC_PROMOTION 0
186 invalid_cpp_abbrev_complaint (const char *arg1
)
188 complaint (&symfile_complaints
, "invalid C++ abbreviation `%s'", arg1
);
192 reg_value_complaint (int arg1
, int arg2
, const char *arg3
)
194 complaint (&symfile_complaints
,
195 "register number %d too large (max %d) in symbol %s", arg1
, arg2
,
200 stabs_general_complaint (const char *arg1
)
202 complaint (&symfile_complaints
, "%s", arg1
);
206 lrs_general_complaint (const char *arg1
)
208 complaint (&symfile_complaints
, "%s", arg1
);
211 /* Make a list of forward references which haven't been defined. */
213 static struct type
**undef_types
;
214 static int undef_types_allocated
;
215 static int undef_types_length
;
216 static struct symbol
*current_symbol
= NULL
;
218 /* Check for and handle cretinous stabs symbol name continuation! */
219 #define STABS_CONTINUE(pp,objfile) \
221 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
222 *(pp) = next_symbol_text (objfile); \
226 /* Look up a dbx type-number pair. Return the address of the slot
227 where the type for that number-pair is stored.
228 The number-pair is in TYPENUMS.
230 This can be used for finding the type associated with that pair
231 or for associating a new type with the pair. */
233 static struct type
**
234 dbx_lookup_type (int typenums
[2])
236 int filenum
= typenums
[0];
237 int index
= typenums
[1];
240 struct header_file
*f
;
243 if (filenum
== -1) /* -1,-1 is for temporary types. */
246 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
248 complaint (&symfile_complaints
,
249 "Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
250 filenum
, index
, symnum
);
258 /* Caller wants address of address of type. We think
259 that negative (rs6k builtin) types will never appear as
260 "lvalues", (nor should they), so we stuff the real type
261 pointer into a temp, and return its address. If referenced,
262 this will do the right thing. */
263 static struct type
*temp_type
;
265 temp_type
= rs6000_builtin_type (index
);
269 /* Type is defined outside of header files.
270 Find it in this object file's type vector. */
271 if (index
>= type_vector_length
)
273 old_len
= type_vector_length
;
276 type_vector_length
= INITIAL_TYPE_VECTOR_LENGTH
;
277 type_vector
= (struct type
**)
278 xmalloc (type_vector_length
* sizeof (struct type
*));
280 while (index
>= type_vector_length
)
282 type_vector_length
*= 2;
284 type_vector
= (struct type
**)
285 xrealloc ((char *) type_vector
,
286 (type_vector_length
* sizeof (struct type
*)));
287 memset (&type_vector
[old_len
], 0,
288 (type_vector_length
- old_len
) * sizeof (struct type
*));
290 return (&type_vector
[index
]);
294 real_filenum
= this_object_header_files
[filenum
];
296 if (real_filenum
>= N_HEADER_FILES (current_objfile
))
298 struct type
*temp_type
;
299 struct type
**temp_type_p
;
301 warning ("GDB internal error: bad real_filenum");
304 temp_type
= init_type (TYPE_CODE_ERROR
, 0, 0, NULL
, NULL
);
305 temp_type_p
= (struct type
**) xmalloc (sizeof (struct type
*));
306 *temp_type_p
= temp_type
;
310 f
= HEADER_FILES (current_objfile
) + real_filenum
;
312 f_orig_length
= f
->length
;
313 if (index
>= f_orig_length
)
315 while (index
>= f
->length
)
319 f
->vector
= (struct type
**)
320 xrealloc ((char *) f
->vector
, f
->length
* sizeof (struct type
*));
321 memset (&f
->vector
[f_orig_length
], 0,
322 (f
->length
- f_orig_length
) * sizeof (struct type
*));
324 return (&f
->vector
[index
]);
328 /* Make sure there is a type allocated for type numbers TYPENUMS
329 and return the type object.
330 This can create an empty (zeroed) type object.
331 TYPENUMS may be (-1, -1) to return a new type object that is not
332 put into the type vector, and so may not be referred to by number. */
335 dbx_alloc_type (int typenums
[2], struct objfile
*objfile
)
337 struct type
**type_addr
;
339 if (typenums
[0] == -1)
341 return (alloc_type (objfile
));
344 type_addr
= dbx_lookup_type (typenums
);
346 /* If we are referring to a type not known at all yet,
347 allocate an empty type for it.
348 We will fill it in later if we find out how. */
351 *type_addr
= alloc_type (objfile
);
357 /* for all the stabs in a given stab vector, build appropriate types
358 and fix their symbols in given symbol vector. */
361 patch_block_stabs (struct pending
*symbols
, struct pending_stabs
*stabs
,
362 struct objfile
*objfile
)
372 /* for all the stab entries, find their corresponding symbols and
373 patch their types! */
375 for (ii
= 0; ii
< stabs
->count
; ++ii
)
377 name
= stabs
->stab
[ii
];
378 pp
= (char *) strchr (name
, ':');
382 pp
= (char *) strchr (pp
, ':');
384 sym
= find_symbol_in_list (symbols
, name
, pp
- name
);
387 /* FIXME-maybe: it would be nice if we noticed whether
388 the variable was defined *anywhere*, not just whether
389 it is defined in this compilation unit. But neither
390 xlc or GCC seem to need such a definition, and until
391 we do psymtabs (so that the minimal symbols from all
392 compilation units are available now), I'm not sure
393 how to get the information. */
395 /* On xcoff, if a global is defined and never referenced,
396 ld will remove it from the executable. There is then
397 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
398 sym
= (struct symbol
*)
399 obstack_alloc (&objfile
->symbol_obstack
,
400 sizeof (struct symbol
));
402 memset (sym
, 0, sizeof (struct symbol
));
403 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
404 SYMBOL_CLASS (sym
) = LOC_OPTIMIZED_OUT
;
405 DEPRECATED_SYMBOL_NAME (sym
) =
406 obsavestring (name
, pp
- name
, &objfile
->symbol_obstack
);
408 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
410 /* I don't think the linker does this with functions,
411 so as far as I know this is never executed.
412 But it doesn't hurt to check. */
414 lookup_function_type (read_type (&pp
, objfile
));
418 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
420 add_symbol_to_list (sym
, &global_symbols
);
425 if (*(pp
- 1) == 'F' || *(pp
- 1) == 'f')
428 lookup_function_type (read_type (&pp
, objfile
));
432 SYMBOL_TYPE (sym
) = read_type (&pp
, objfile
);
440 /* Read a number by which a type is referred to in dbx data,
441 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
442 Just a single number N is equivalent to (0,N).
443 Return the two numbers by storing them in the vector TYPENUMS.
444 TYPENUMS will then be used as an argument to dbx_lookup_type.
446 Returns 0 for success, -1 for error. */
449 read_type_number (char **pp
, int *typenums
)
455 typenums
[0] = read_huge_number (pp
, ',', &nbits
);
458 typenums
[1] = read_huge_number (pp
, ')', &nbits
);
465 typenums
[1] = read_huge_number (pp
, 0, &nbits
);
473 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
474 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
475 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
476 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
478 /* This routine fixes up symbol references/aliases to point to the original
479 symbol definition. Returns 0 on failure, non-zero on success. */
482 resolve_symbol_reference (struct objfile
*objfile
, struct symbol
*sym
, char *p
)
485 struct symbol
*ref_sym
= 0;
486 struct alias_list
*alias
;
488 /* If this is not a symbol reference return now. */
492 /* Use "#<num>" as the name; we'll fix the name later.
493 We stored the original symbol name as "#<id>=<name>"
494 so we can now search for "#<id>" to resolving the reference.
495 We'll fix the names later by removing the "#<id>" or "#<id>=" */
497 /*---------------------------------------------------------*/
498 /* Get the reference id number, and
499 advance p past the names so we can parse the rest.
500 eg: id=2 for p : "2=", "2=z:r(0,1)" "2:r(0,1);l(#5,#6),l(#7,#4)" */
501 /*---------------------------------------------------------*/
503 /* This gets reference name from string. sym may not have a name. */
505 /* Get the reference number associated with the reference id in the
506 gdb stab string. From that reference number, get the main/primary
507 symbol for this alias. */
508 refnum
= process_reference (&p
);
509 ref_sym
= ref_search (refnum
);
512 lrs_general_complaint ("symbol for reference not found");
516 /* Parse the stab of the referencing symbol
517 now that we have the referenced symbol.
518 Add it as a new symbol and a link back to the referenced symbol.
519 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
522 /* If the stab symbol table and string contain:
523 RSYM 0 5 00000000 868 #15=z:r(0,1)
524 LBRAC 0 0 00000000 899 #5=
525 SLINE 0 16 00000003 923 #6=
526 Then the same symbols can be later referenced by:
527 RSYM 0 5 00000000 927 #15:r(0,1);l(#5,#6)
528 This is used in live range splitting to:
529 1) specify that a symbol (#15) is actually just a new storage
530 class for a symbol (#15=z) which was previously defined.
531 2) specify that the beginning and ending ranges for a symbol
532 (#15) are the values of the beginning (#5) and ending (#6)
535 /* Read number as reference id.
536 eg: p : "=", "=z:r(0,1)" ":r(0,1);l(#5,#6),l(#7,#4)" */
537 /* FIXME! Might I want to use SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
538 in case of "l(0,0)"? */
540 /*--------------------------------------------------*/
541 /* Add this symbol to the reference list. */
542 /*--------------------------------------------------*/
544 alias
= (struct alias_list
*) obstack_alloc (&objfile
->type_obstack
,
545 sizeof (struct alias_list
));
548 lrs_general_complaint ("Unable to allocate alias list memory");
555 if (!SYMBOL_ALIASES (ref_sym
))
557 SYMBOL_ALIASES (ref_sym
) = alias
;
561 struct alias_list
*temp
;
563 /* Get to the end of the list. */
564 for (temp
= SYMBOL_ALIASES (ref_sym
);
571 /* Want to fix up name so that other functions (eg. valops)
572 will correctly print the name.
573 Don't add_symbol_to_list so that lookup_symbol won't find it.
574 nope... needed for fixups. */
575 DEPRECATED_SYMBOL_NAME (sym
) = DEPRECATED_SYMBOL_NAME (ref_sym
);
581 /* Structure for storing pointers to reference definitions for fast lookup
582 during "process_later". */
591 #define MAX_CHUNK_REFS 100
592 #define REF_CHUNK_SIZE (MAX_CHUNK_REFS * sizeof (struct ref_map))
593 #define REF_MAP_SIZE(ref_chunk) ((ref_chunk) * REF_CHUNK_SIZE)
595 static struct ref_map
*ref_map
;
597 /* Ptr to free cell in chunk's linked list. */
598 static int ref_count
= 0;
600 /* Number of chunks malloced. */
601 static int ref_chunk
= 0;
603 /* This file maintains a cache of stabs aliases found in the symbol
604 table. If the symbol table changes, this cache must be cleared
605 or we are left holding onto data in invalid obstacks. */
607 stabsread_clear_cache (void)
613 /* Create array of pointers mapping refids to symbols and stab strings.
614 Add pointers to reference definition symbols and/or their values as we
615 find them, using their reference numbers as our index.
616 These will be used later when we resolve references. */
618 ref_add (int refnum
, struct symbol
*sym
, char *stabs
, CORE_ADDR value
)
622 if (refnum
>= ref_count
)
623 ref_count
= refnum
+ 1;
624 if (ref_count
> ref_chunk
* MAX_CHUNK_REFS
)
626 int new_slots
= ref_count
- ref_chunk
* MAX_CHUNK_REFS
;
627 int new_chunks
= new_slots
/ MAX_CHUNK_REFS
+ 1;
628 ref_map
= (struct ref_map
*)
629 xrealloc (ref_map
, REF_MAP_SIZE (ref_chunk
+ new_chunks
));
630 memset (ref_map
+ ref_chunk
* MAX_CHUNK_REFS
, 0, new_chunks
* REF_CHUNK_SIZE
);
631 ref_chunk
+= new_chunks
;
633 ref_map
[refnum
].stabs
= stabs
;
634 ref_map
[refnum
].sym
= sym
;
635 ref_map
[refnum
].value
= value
;
638 /* Return defined sym for the reference REFNUM. */
640 ref_search (int refnum
)
642 if (refnum
< 0 || refnum
> ref_count
)
644 return ref_map
[refnum
].sym
;
647 /* Return value for the reference REFNUM. */
650 ref_search_value (int refnum
)
652 if (refnum
< 0 || refnum
> ref_count
)
654 return ref_map
[refnum
].value
;
657 /* Parse a reference id in STRING and return the resulting
658 reference number. Move STRING beyond the reference id. */
661 process_reference (char **string
)
669 /* Advance beyond the initial '#'. */
672 /* Read number as reference id. */
673 while (*p
&& isdigit (*p
))
675 refnum
= refnum
* 10 + *p
- '0';
682 /* If STRING defines a reference, store away a pointer to the reference
683 definition for later use. Return the reference number. */
686 symbol_reference_defined (char **string
)
691 refnum
= process_reference (&p
);
693 /* Defining symbols end in '=' */
696 /* Symbol is being defined here. */
702 /* Must be a reference. Either the symbol has already been defined,
703 or this is a forward reference to it. */
710 define_symbol (CORE_ADDR valu
, char *string
, int desc
, int type
,
711 struct objfile
*objfile
)
714 char *p
= (char *) find_name_end (string
);
719 /* We would like to eliminate nameless symbols, but keep their types.
720 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
721 to type 2, but, should not create a symbol to address that type. Since
722 the symbol will be nameless, there is no way any user can refer to it. */
726 /* Ignore syms with empty names. */
730 /* Ignore old-style symbols from cc -go */
740 /* If a nameless stab entry, all we need is the type, not the symbol.
741 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
742 nameless
= (p
== string
|| ((string
[0] == ' ') && (string
[1] == ':')));
744 current_symbol
= sym
= (struct symbol
*)
745 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
746 memset (sym
, 0, sizeof (struct symbol
));
748 switch (type
& N_TYPE
)
751 SYMBOL_SECTION (sym
) = SECT_OFF_TEXT (objfile
);
754 SYMBOL_SECTION (sym
) = SECT_OFF_DATA (objfile
);
757 SYMBOL_SECTION (sym
) = SECT_OFF_BSS (objfile
);
761 if (processing_gcc_compilation
)
763 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
764 number of bytes occupied by a type or object, which we ignore. */
765 SYMBOL_LINE (sym
) = desc
;
769 SYMBOL_LINE (sym
) = 0; /* unknown */
772 if (is_cplus_marker (string
[0]))
774 /* Special GNU C++ names. */
778 DEPRECATED_SYMBOL_NAME (sym
) = obsavestring ("this", strlen ("this"),
779 &objfile
->symbol_obstack
);
782 case 'v': /* $vtbl_ptr_type */
783 /* Was: DEPRECATED_SYMBOL_NAME (sym) = "vptr"; */
787 DEPRECATED_SYMBOL_NAME (sym
) = obsavestring ("eh_throw", strlen ("eh_throw"),
788 &objfile
->symbol_obstack
);
792 /* This was an anonymous type that was never fixed up. */
795 #ifdef STATIC_TRANSFORM_NAME
797 /* SunPRO (3.0 at least) static variable encoding. */
802 complaint (&symfile_complaints
, "Unknown C++ symbol name `%s'",
804 goto normal
; /* Do *something* with it */
807 else if (string
[0] == '#')
809 /* Special GNU C extension for referencing symbols. */
813 /* If STRING defines a new reference id, then add it to the
814 reference map. Else it must be referring to a previously
815 defined symbol, so add it to the alias list of the previously
818 refnum
= symbol_reference_defined (&s
);
820 ref_add (refnum
, sym
, string
, SYMBOL_VALUE (sym
));
821 else if (!resolve_symbol_reference (objfile
, sym
, string
))
824 /* S..P contains the name of the symbol. We need to store
825 the correct name into DEPRECATED_SYMBOL_NAME. */
830 SYMBOL_SET_NAMES (sym
, s
, nlen
, objfile
);
832 /* FIXME! Want DEPRECATED_SYMBOL_NAME (sym) = 0;
833 Get error if leave name 0. So give it something. */
836 SYMBOL_SET_NAMES (sym
, string
, nlen
, objfile
);
839 /* Advance STRING beyond the reference id. */
845 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
846 SYMBOL_SET_NAMES (sym
, string
, p
- string
, objfile
);
850 /* Determine the type of name being defined. */
852 /* Getting GDB to correctly skip the symbol on an undefined symbol
853 descriptor and not ever dump core is a very dodgy proposition if
854 we do things this way. I say the acorn RISC machine can just
855 fix their compiler. */
856 /* The Acorn RISC machine's compiler can put out locals that don't
857 start with "234=" or "(3,4)=", so assume anything other than the
858 deftypes we know how to handle is a local. */
859 if (!strchr ("cfFGpPrStTvVXCR", *p
))
861 if (isdigit (*p
) || *p
== '(' || *p
== '-')
870 /* c is a special case, not followed by a type-number.
871 SYMBOL:c=iVALUE for an integer constant symbol.
872 SYMBOL:c=rVALUE for a floating constant symbol.
873 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
874 e.g. "b:c=e6,0" for "const b = blob1"
875 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
878 SYMBOL_CLASS (sym
) = LOC_CONST
;
879 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
880 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
881 add_symbol_to_list (sym
, &file_symbols
);
892 /* FIXME-if-picky-about-floating-accuracy: Should be using
893 target arithmetic to get the value. real.c in GCC
894 probably has the necessary code. */
896 /* FIXME: lookup_fundamental_type is a hack. We should be
897 creating a type especially for the type of float constants.
898 Problem is, what type should it be?
900 Also, what should the name of this type be? Should we
901 be using 'S' constants (see stabs.texinfo) instead? */
903 SYMBOL_TYPE (sym
) = lookup_fundamental_type (objfile
,
906 obstack_alloc (&objfile
->symbol_obstack
,
907 TYPE_LENGTH (SYMBOL_TYPE (sym
)));
908 store_typed_floating (dbl_valu
, SYMBOL_TYPE (sym
), d
);
909 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
910 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
915 /* Defining integer constants this way is kind of silly,
916 since 'e' constants allows the compiler to give not
917 only the value, but the type as well. C has at least
918 int, long, unsigned int, and long long as constant
919 types; other languages probably should have at least
920 unsigned as well as signed constants. */
922 /* We just need one int constant type for all objfiles.
923 It doesn't depend on languages or anything (arguably its
924 name should be a language-specific name for a type of
925 that size, but I'm inclined to say that if the compiler
926 wants a nice name for the type, it can use 'e'). */
927 static struct type
*int_const_type
;
929 /* Yes, this is as long as a *host* int. That is because we
931 if (int_const_type
== NULL
)
933 init_type (TYPE_CODE_INT
,
934 sizeof (int) * HOST_CHAR_BIT
/ TARGET_CHAR_BIT
, 0,
936 (struct objfile
*) NULL
);
937 SYMBOL_TYPE (sym
) = int_const_type
;
938 SYMBOL_VALUE (sym
) = atoi (p
);
939 SYMBOL_CLASS (sym
) = LOC_CONST
;
943 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
944 can be represented as integral.
945 e.g. "b:c=e6,0" for "const b = blob1"
946 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
948 SYMBOL_CLASS (sym
) = LOC_CONST
;
949 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
953 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
958 /* If the value is too big to fit in an int (perhaps because
959 it is unsigned), or something like that, we silently get
960 a bogus value. The type and everything else about it is
961 correct. Ideally, we should be using whatever we have
962 available for parsing unsigned and long long values,
964 SYMBOL_VALUE (sym
) = atoi (p
);
969 SYMBOL_CLASS (sym
) = LOC_CONST
;
970 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
973 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
974 add_symbol_to_list (sym
, &file_symbols
);
978 /* The name of a caught exception. */
979 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
980 SYMBOL_CLASS (sym
) = LOC_LABEL
;
981 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
982 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
983 add_symbol_to_list (sym
, &local_symbols
);
987 /* A static function definition. */
988 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
989 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
990 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
991 add_symbol_to_list (sym
, &file_symbols
);
992 /* fall into process_function_types. */
994 process_function_types
:
995 /* Function result types are described as the result type in stabs.
996 We need to convert this to the function-returning-type-X type
997 in GDB. E.g. "int" is converted to "function returning int". */
998 if (TYPE_CODE (SYMBOL_TYPE (sym
)) != TYPE_CODE_FUNC
)
999 SYMBOL_TYPE (sym
) = lookup_function_type (SYMBOL_TYPE (sym
));
1001 /* All functions in C++ have prototypes. Stabs does not offer an
1002 explicit way to identify prototyped or unprototyped functions,
1003 but both GCC and Sun CC emit stabs for the "call-as" type rather
1004 than the "declared-as" type for unprototyped functions, so
1005 we treat all functions as if they were prototyped. This is used
1006 primarily for promotion when calling the function from GDB. */
1007 TYPE_FLAGS (SYMBOL_TYPE (sym
)) |= TYPE_FLAG_PROTOTYPED
;
1009 /* fall into process_prototype_types */
1011 process_prototype_types
:
1012 /* Sun acc puts declared types of arguments here. */
1015 struct type
*ftype
= SYMBOL_TYPE (sym
);
1020 /* Obtain a worst case guess for the number of arguments
1021 by counting the semicolons. */
1028 /* Allocate parameter information fields and fill them in. */
1029 TYPE_FIELDS (ftype
) = (struct field
*)
1030 TYPE_ALLOC (ftype
, nsemi
* sizeof (struct field
));
1035 /* A type number of zero indicates the start of varargs.
1036 FIXME: GDB currently ignores vararg functions. */
1037 if (p
[0] == '0' && p
[1] == '\0')
1039 ptype
= read_type (&p
, objfile
);
1041 /* The Sun compilers mark integer arguments, which should
1042 be promoted to the width of the calling conventions, with
1043 a type which references itself. This type is turned into
1044 a TYPE_CODE_VOID type by read_type, and we have to turn
1045 it back into builtin_type_int here.
1046 FIXME: Do we need a new builtin_type_promoted_int_arg ? */
1047 if (TYPE_CODE (ptype
) == TYPE_CODE_VOID
)
1048 ptype
= builtin_type_int
;
1049 TYPE_FIELD_TYPE (ftype
, nparams
) = ptype
;
1050 TYPE_FIELD_ARTIFICIAL (ftype
, nparams
++) = 0;
1052 TYPE_NFIELDS (ftype
) = nparams
;
1053 TYPE_FLAGS (ftype
) |= TYPE_FLAG_PROTOTYPED
;
1058 /* A global function definition. */
1059 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1060 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
1061 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1062 add_symbol_to_list (sym
, &global_symbols
);
1063 goto process_function_types
;
1066 /* For a class G (global) symbol, it appears that the
1067 value is not correct. It is necessary to search for the
1068 corresponding linker definition to find the value.
1069 These definitions appear at the end of the namelist. */
1070 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1071 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1072 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1073 /* Don't add symbol references to global_sym_chain.
1074 Symbol references don't have valid names and wont't match up with
1075 minimal symbols when the global_sym_chain is relocated.
1076 We'll fixup symbol references when we fixup the defining symbol. */
1077 if (DEPRECATED_SYMBOL_NAME (sym
) && DEPRECATED_SYMBOL_NAME (sym
)[0] != '#')
1079 i
= hashname (DEPRECATED_SYMBOL_NAME (sym
));
1080 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
1081 global_sym_chain
[i
] = sym
;
1083 add_symbol_to_list (sym
, &global_symbols
);
1086 /* This case is faked by a conditional above,
1087 when there is no code letter in the dbx data.
1088 Dbx data never actually contains 'l'. */
1091 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1092 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1093 SYMBOL_VALUE (sym
) = valu
;
1094 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1095 add_symbol_to_list (sym
, &local_symbols
);
1100 /* pF is a two-letter code that means a function parameter in Fortran.
1101 The type-number specifies the type of the return value.
1102 Translate it into a pointer-to-function type. */
1106 = lookup_pointer_type
1107 (lookup_function_type (read_type (&p
, objfile
)));
1110 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1112 SYMBOL_CLASS (sym
) = LOC_ARG
;
1113 SYMBOL_VALUE (sym
) = valu
;
1114 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1115 add_symbol_to_list (sym
, &local_symbols
);
1117 if (TARGET_BYTE_ORDER
!= BFD_ENDIAN_BIG
)
1119 /* On little-endian machines, this crud is never necessary,
1120 and, if the extra bytes contain garbage, is harmful. */
1124 /* If it's gcc-compiled, if it says `short', believe it. */
1125 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
1128 if (!BELIEVE_PCC_PROMOTION
)
1130 /* This is the signed type which arguments get promoted to. */
1131 static struct type
*pcc_promotion_type
;
1132 /* This is the unsigned type which arguments get promoted to. */
1133 static struct type
*pcc_unsigned_promotion_type
;
1135 /* Call it "int" because this is mainly C lossage. */
1136 if (pcc_promotion_type
== NULL
)
1137 pcc_promotion_type
=
1138 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1141 if (pcc_unsigned_promotion_type
== NULL
)
1142 pcc_unsigned_promotion_type
=
1143 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
1144 TYPE_FLAG_UNSIGNED
, "unsigned int", NULL
);
1146 if (BELIEVE_PCC_PROMOTION_TYPE
)
1148 /* This is defined on machines (e.g. sparc) where we
1149 should believe the type of a PCC 'short' argument,
1150 but shouldn't believe the address (the address is the
1151 address of the corresponding int).
1153 My guess is that this correction, as opposed to
1154 changing the parameter to an 'int' (as done below,
1155 for PCC on most machines), is the right thing to do
1156 on all machines, but I don't want to risk breaking
1157 something that already works. On most PCC machines,
1158 the sparc problem doesn't come up because the calling
1159 function has to zero the top bytes (not knowing
1160 whether the called function wants an int or a short),
1161 so there is little practical difference between an
1162 int and a short (except perhaps what happens when the
1163 GDB user types "print short_arg = 0x10000;").
1165 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the
1166 compiler actually produces the correct address (we
1167 don't need to fix it up). I made this code adapt so
1168 that it will offset the symbol if it was pointing at
1169 an int-aligned location and not otherwise. This way
1170 you can use the same gdb for 4.0.x and 4.1 systems.
1172 If the parameter is shorter than an int, and is
1173 integral (e.g. char, short, or unsigned equivalent),
1174 and is claimed to be passed on an integer boundary,
1175 don't believe it! Offset the parameter's address to
1176 the tail-end of that integer. */
1178 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1179 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
1180 && 0 == SYMBOL_VALUE (sym
) % TYPE_LENGTH (pcc_promotion_type
))
1182 SYMBOL_VALUE (sym
) += TYPE_LENGTH (pcc_promotion_type
)
1183 - TYPE_LENGTH (SYMBOL_TYPE (sym
));
1189 /* If PCC says a parameter is a short or a char,
1190 it is really an int. */
1191 if (TYPE_LENGTH (SYMBOL_TYPE (sym
)) < TYPE_LENGTH (pcc_promotion_type
)
1192 && TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_INT
)
1195 TYPE_UNSIGNED (SYMBOL_TYPE (sym
))
1196 ? pcc_unsigned_promotion_type
1197 : pcc_promotion_type
;
1204 /* acc seems to use P to declare the prototypes of functions that
1205 are referenced by this file. gdb is not prepared to deal
1206 with this extra information. FIXME, it ought to. */
1209 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1210 goto process_prototype_types
;
1215 /* Parameter which is in a register. */
1216 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1217 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1218 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1219 if (SYMBOL_VALUE (sym
) >= NUM_REGS
+ NUM_PSEUDO_REGS
)
1221 reg_value_complaint (SYMBOL_VALUE (sym
),
1222 NUM_REGS
+ NUM_PSEUDO_REGS
,
1223 SYMBOL_PRINT_NAME (sym
));
1224 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1226 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1227 add_symbol_to_list (sym
, &local_symbols
);
1231 /* Register variable (either global or local). */
1232 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1233 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1234 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1235 if (SYMBOL_VALUE (sym
) >= NUM_REGS
+ NUM_PSEUDO_REGS
)
1237 reg_value_complaint (SYMBOL_VALUE (sym
),
1238 NUM_REGS
+ NUM_PSEUDO_REGS
,
1239 SYMBOL_PRINT_NAME (sym
));
1240 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1242 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1243 if (within_function
)
1245 /* Sun cc uses a pair of symbols, one 'p' and one 'r', with
1246 the same name to represent an argument passed in a
1247 register. GCC uses 'P' for the same case. So if we find
1248 such a symbol pair we combine it into one 'P' symbol.
1249 For Sun cc we need to do this regardless of
1250 stabs_argument_has_addr, because the compiler puts out
1251 the 'p' symbol even if it never saves the argument onto
1254 On most machines, we want to preserve both symbols, so
1255 that we can still get information about what is going on
1256 with the stack (VAX for computing args_printed, using
1257 stack slots instead of saved registers in backtraces,
1260 Note that this code illegally combines
1261 main(argc) struct foo argc; { register struct foo argc; }
1262 but this case is considered pathological and causes a warning
1263 from a decent compiler. */
1266 && local_symbols
->nsyms
> 0
1267 #ifndef USE_REGISTER_NOT_ARG
1268 && gdbarch_stabs_argument_has_addr (current_gdbarch
,
1273 struct symbol
*prev_sym
;
1274 prev_sym
= local_symbols
->symbol
[local_symbols
->nsyms
- 1];
1275 if ((SYMBOL_CLASS (prev_sym
) == LOC_REF_ARG
1276 || SYMBOL_CLASS (prev_sym
) == LOC_ARG
)
1277 && STREQ (DEPRECATED_SYMBOL_NAME (prev_sym
), DEPRECATED_SYMBOL_NAME (sym
)))
1279 SYMBOL_CLASS (prev_sym
) = LOC_REGPARM
;
1280 /* Use the type from the LOC_REGISTER; that is the type
1281 that is actually in that register. */
1282 SYMBOL_TYPE (prev_sym
) = SYMBOL_TYPE (sym
);
1283 SYMBOL_VALUE (prev_sym
) = SYMBOL_VALUE (sym
);
1288 add_symbol_to_list (sym
, &local_symbols
);
1291 add_symbol_to_list (sym
, &file_symbols
);
1295 /* Static symbol at top level of file */
1296 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1297 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1298 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1299 #ifdef STATIC_TRANSFORM_NAME
1300 if (IS_STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym
)))
1302 struct minimal_symbol
*msym
;
1303 msym
= lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym
), NULL
, objfile
);
1306 DEPRECATED_SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym
));
1307 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1311 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1312 add_symbol_to_list (sym
, &file_symbols
);
1317 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1319 /* For a nameless type, we don't want a create a symbol, thus we
1320 did not use `sym'. Return without further processing. */
1324 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1325 SYMBOL_VALUE (sym
) = valu
;
1326 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1327 /* C++ vagaries: we may have a type which is derived from
1328 a base type which did not have its name defined when the
1329 derived class was output. We fill in the derived class's
1330 base part member's name here in that case. */
1331 if (TYPE_NAME (SYMBOL_TYPE (sym
)) != NULL
)
1332 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1333 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1334 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1337 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1338 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1339 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1340 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1343 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == NULL
)
1345 /* gcc-2.6 or later (when using -fvtable-thunks)
1346 emits a unique named type for a vtable entry.
1347 Some gdb code depends on that specific name. */
1348 extern const char vtbl_ptr_name
[];
1350 if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_PTR
1351 && strcmp (DEPRECATED_SYMBOL_NAME (sym
), vtbl_ptr_name
))
1352 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_FUNC
)
1354 /* If we are giving a name to a type such as "pointer to
1355 foo" or "function returning foo", we better not set
1356 the TYPE_NAME. If the program contains "typedef char
1357 *caddr_t;", we don't want all variables of type char
1358 * to print as caddr_t. This is not just a
1359 consequence of GDB's type management; PCC and GCC (at
1360 least through version 2.4) both output variables of
1361 either type char * or caddr_t with the type number
1362 defined in the 't' symbol for caddr_t. If a future
1363 compiler cleans this up it GDB is not ready for it
1364 yet, but if it becomes ready we somehow need to
1365 disable this check (without breaking the PCC/GCC2.4
1370 Fortunately, this check seems not to be necessary
1371 for anything except pointers or functions. */
1372 /* ezannoni: 2000-10-26. This seems to apply for
1373 versions of gcc older than 2.8. This was the original
1374 problem: with the following code gdb would tell that
1375 the type for name1 is caddr_t, and func is char()
1376 typedef char *caddr_t;
1388 /* Pascal accepts names for pointer types. */
1389 if (current_subfile
->language
== language_pascal
)
1391 TYPE_NAME (SYMBOL_TYPE (sym
)) = DEPRECATED_SYMBOL_NAME (sym
);
1395 TYPE_NAME (SYMBOL_TYPE (sym
)) = DEPRECATED_SYMBOL_NAME (sym
);
1398 add_symbol_to_list (sym
, &file_symbols
);
1402 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1403 by 't' which means we are typedef'ing it as well. */
1404 synonym
= *p
== 't';
1409 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1411 /* For a nameless type, we don't want a create a symbol, thus we
1412 did not use `sym'. Return without further processing. */
1416 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1417 SYMBOL_VALUE (sym
) = valu
;
1418 SYMBOL_DOMAIN (sym
) = STRUCT_DOMAIN
;
1419 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym
)) == 0)
1420 TYPE_TAG_NAME (SYMBOL_TYPE (sym
))
1421 = obconcat (&objfile
->type_obstack
, "", "", DEPRECATED_SYMBOL_NAME (sym
));
1422 add_symbol_to_list (sym
, &file_symbols
);
1426 /* Clone the sym and then modify it. */
1427 struct symbol
*typedef_sym
= (struct symbol
*)
1428 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
1429 *typedef_sym
= *sym
;
1430 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1431 SYMBOL_VALUE (typedef_sym
) = valu
;
1432 SYMBOL_DOMAIN (typedef_sym
) = VAR_DOMAIN
;
1433 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0)
1434 TYPE_NAME (SYMBOL_TYPE (sym
))
1435 = obconcat (&objfile
->type_obstack
, "", "", DEPRECATED_SYMBOL_NAME (sym
));
1436 add_symbol_to_list (typedef_sym
, &file_symbols
);
1441 /* Static symbol of local scope */
1442 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1443 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1444 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1445 #ifdef STATIC_TRANSFORM_NAME
1446 if (IS_STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym
)))
1448 struct minimal_symbol
*msym
;
1449 msym
= lookup_minimal_symbol (DEPRECATED_SYMBOL_NAME (sym
), NULL
, objfile
);
1452 DEPRECATED_SYMBOL_NAME (sym
) = STATIC_TRANSFORM_NAME (DEPRECATED_SYMBOL_NAME (sym
));
1453 SYMBOL_VALUE_ADDRESS (sym
) = SYMBOL_VALUE_ADDRESS (msym
);
1457 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1458 add_symbol_to_list (sym
, &local_symbols
);
1462 /* Reference parameter */
1463 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1464 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1465 SYMBOL_VALUE (sym
) = valu
;
1466 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1467 add_symbol_to_list (sym
, &local_symbols
);
1471 /* Reference parameter which is in a register. */
1472 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1473 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1474 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1475 if (SYMBOL_VALUE (sym
) >= NUM_REGS
+ NUM_PSEUDO_REGS
)
1477 reg_value_complaint (SYMBOL_VALUE (sym
),
1478 NUM_REGS
+ NUM_PSEUDO_REGS
,
1479 SYMBOL_PRINT_NAME (sym
));
1480 SYMBOL_VALUE (sym
) = SP_REGNUM
; /* Known safe, though useless */
1482 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1483 add_symbol_to_list (sym
, &local_symbols
);
1487 /* This is used by Sun FORTRAN for "function result value".
1488 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1489 that Pascal uses it too, but when I tried it Pascal used
1490 "x:3" (local symbol) instead. */
1491 SYMBOL_TYPE (sym
) = read_type (&p
, objfile
);
1492 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1493 SYMBOL_VALUE (sym
) = valu
;
1494 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1495 add_symbol_to_list (sym
, &local_symbols
);
1499 SYMBOL_TYPE (sym
) = error_type (&p
, objfile
);
1500 SYMBOL_CLASS (sym
) = LOC_CONST
;
1501 SYMBOL_VALUE (sym
) = 0;
1502 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
1503 add_symbol_to_list (sym
, &file_symbols
);
1507 /* Some systems pass variables of certain types by reference instead
1508 of by value, i.e. they will pass the address of a structure (in a
1509 register or on the stack) instead of the structure itself. */
1511 if (gdbarch_stabs_argument_has_addr (current_gdbarch
, SYMBOL_TYPE (sym
))
1512 && (SYMBOL_CLASS (sym
) == LOC_REGPARM
|| SYMBOL_CLASS (sym
) == LOC_ARG
))
1514 /* We have to convert LOC_REGPARM to LOC_REGPARM_ADDR (for
1515 variables passed in a register). */
1516 if (SYMBOL_CLASS (sym
) == LOC_REGPARM
)
1517 SYMBOL_CLASS (sym
) = LOC_REGPARM_ADDR
;
1518 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
1519 and subsequent arguments on SPARC, for example). */
1520 else if (SYMBOL_CLASS (sym
) == LOC_ARG
)
1521 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1524 /* Is there more to parse? For example LRS/alias information? */
1525 while (*p
&& *p
== ';')
1528 if (*p
&& p
[0] == 'l' && p
[1] == '(')
1530 /* GNU extensions for live range splitting may be appended to
1531 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
1533 /* Resolve the live range and add it to SYM's live range list. */
1534 if (!resolve_live_range (objfile
, sym
, p
))
1537 /* Find end of live range info. */
1538 p
= strchr (p
, ')');
1539 if (!*p
|| *p
!= ')')
1541 lrs_general_complaint ("live range format not recognized");
1550 /* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
1551 non-zero on success, zero otherwise. */
1554 resolve_live_range (struct objfile
*objfile
, struct symbol
*sym
, char *p
)
1557 CORE_ADDR start
, end
;
1559 /* Sanity check the beginning of the stabs string. */
1560 if (!*p
|| *p
!= 'l')
1562 lrs_general_complaint ("live range string 1");
1567 if (!*p
|| *p
!= '(')
1569 lrs_general_complaint ("live range string 2");
1574 /* Get starting value of range and advance P past the reference id.
1576 ?!? In theory, the process_reference should never fail, but we should
1577 catch that case just in case the compiler scrogged the stabs. */
1578 refnum
= process_reference (&p
);
1579 start
= ref_search_value (refnum
);
1582 lrs_general_complaint ("Live range symbol not found 1");
1586 if (!*p
|| *p
!= ',')
1588 lrs_general_complaint ("live range string 3");
1593 /* Get ending value of range and advance P past the reference id.
1595 ?!? In theory, the process_reference should never fail, but we should
1596 catch that case just in case the compiler scrogged the stabs. */
1597 refnum
= process_reference (&p
);
1598 end
= ref_search_value (refnum
);
1601 lrs_general_complaint ("Live range symbol not found 2");
1605 if (!*p
|| *p
!= ')')
1607 lrs_general_complaint ("live range string 4");
1611 /* Now that we know the bounds of the range, add it to the
1613 add_live_range (objfile
, sym
, start
, end
);
1618 /* Add a new live range defined by START and END to the symbol SYM
1619 in objfile OBJFILE. */
1622 add_live_range (struct objfile
*objfile
, struct symbol
*sym
, CORE_ADDR start
,
1625 struct range_list
*r
, *rs
;
1629 lrs_general_complaint ("end of live range follows start");
1633 /* Alloc new live range structure. */
1634 r
= (struct range_list
*)
1635 obstack_alloc (&objfile
->type_obstack
,
1636 sizeof (struct range_list
));
1641 /* Append this range to the symbol's range list. */
1642 if (!SYMBOL_RANGES (sym
))
1643 SYMBOL_RANGES (sym
) = r
;
1646 /* Get the last range for the symbol. */
1647 for (rs
= SYMBOL_RANGES (sym
); rs
->next
; rs
= rs
->next
)
1654 /* Skip rest of this symbol and return an error type.
1656 General notes on error recovery: error_type always skips to the
1657 end of the symbol (modulo cretinous dbx symbol name continuation).
1658 Thus code like this:
1660 if (*(*pp)++ != ';')
1661 return error_type (pp, objfile);
1663 is wrong because if *pp starts out pointing at '\0' (typically as the
1664 result of an earlier error), it will be incremented to point to the
1665 start of the next symbol, which might produce strange results, at least
1666 if you run off the end of the string table. Instead use
1669 return error_type (pp, objfile);
1675 foo = error_type (pp, objfile);
1679 And in case it isn't obvious, the point of all this hair is so the compiler
1680 can define new types and new syntaxes, and old versions of the
1681 debugger will be able to read the new symbol tables. */
1683 static struct type
*
1684 error_type (char **pp
, struct objfile
*objfile
)
1686 complaint (&symfile_complaints
, "couldn't parse type; debugger out of date?");
1689 /* Skip to end of symbol. */
1690 while (**pp
!= '\0')
1695 /* Check for and handle cretinous dbx symbol name continuation! */
1696 if ((*pp
)[-1] == '\\' || (*pp
)[-1] == '?')
1698 *pp
= next_symbol_text (objfile
);
1705 return (builtin_type_error
);
1709 /* Read type information or a type definition; return the type. Even
1710 though this routine accepts either type information or a type
1711 definition, the distinction is relevant--some parts of stabsread.c
1712 assume that type information starts with a digit, '-', or '(' in
1713 deciding whether to call read_type. */
1715 static struct type
*
1716 read_type (char **pp
, struct objfile
*objfile
)
1718 struct type
*type
= 0;
1721 char type_descriptor
;
1723 /* Size in bits of type if specified by a type attribute, or -1 if
1724 there is no size attribute. */
1727 /* Used to distinguish string and bitstring from char-array and set. */
1730 /* Used to distinguish vector from array. */
1733 /* Read type number if present. The type number may be omitted.
1734 for instance in a two-dimensional array declared with type
1735 "ar1;1;10;ar1;1;10;4". */
1736 if ((**pp
>= '0' && **pp
<= '9')
1740 if (read_type_number (pp
, typenums
) != 0)
1741 return error_type (pp
, objfile
);
1743 /* Type is not being defined here. Either it already exists,
1744 or this is a forward reference to it. dbx_alloc_type handles
1747 return dbx_alloc_type (typenums
, objfile
);
1749 /* Type is being defined here. */
1751 Also skip the type descriptor - we get it below with (*pp)[-1]. */
1756 /* 'typenums=' not present, type is anonymous. Read and return
1757 the definition, but don't put it in the type vector. */
1758 typenums
[0] = typenums
[1] = -1;
1763 type_descriptor
= (*pp
)[-1];
1764 switch (type_descriptor
)
1768 enum type_code code
;
1770 /* Used to index through file_symbols. */
1771 struct pending
*ppt
;
1774 /* Name including "struct", etc. */
1778 char *from
, *to
, *p
, *q1
, *q2
;
1780 /* Set the type code according to the following letter. */
1784 code
= TYPE_CODE_STRUCT
;
1787 code
= TYPE_CODE_UNION
;
1790 code
= TYPE_CODE_ENUM
;
1794 /* Complain and keep going, so compilers can invent new
1795 cross-reference types. */
1796 complaint (&symfile_complaints
,
1797 "Unrecognized cross-reference type `%c'", (*pp
)[0]);
1798 code
= TYPE_CODE_STRUCT
;
1803 q1
= strchr (*pp
, '<');
1804 p
= strchr (*pp
, ':');
1806 return error_type (pp
, objfile
);
1807 if (q1
&& p
> q1
&& p
[1] == ':')
1809 int nesting_level
= 0;
1810 for (q2
= q1
; *q2
; q2
++)
1814 else if (*q2
== '>')
1816 else if (*q2
== ':' && nesting_level
== 0)
1821 return error_type (pp
, objfile
);
1824 (char *) obstack_alloc (&objfile
->type_obstack
, p
- *pp
+ 1);
1826 /* Copy the name. */
1832 /* Set the pointer ahead of the name which we just read, and
1837 /* Now check to see whether the type has already been
1838 declared. This was written for arrays of cross-referenced
1839 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1840 sure it is not necessary anymore. But it might be a good
1841 idea, to save a little memory. */
1843 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1844 for (i
= 0; i
< ppt
->nsyms
; i
++)
1846 struct symbol
*sym
= ppt
->symbol
[i
];
1848 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1849 && SYMBOL_DOMAIN (sym
) == STRUCT_DOMAIN
1850 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1851 && STREQ (DEPRECATED_SYMBOL_NAME (sym
), type_name
))
1853 obstack_free (&objfile
->type_obstack
, type_name
);
1854 type
= SYMBOL_TYPE (sym
);
1859 /* Didn't find the type to which this refers, so we must
1860 be dealing with a forward reference. Allocate a type
1861 structure for it, and keep track of it so we can
1862 fill in the rest of the fields when we get the full
1864 type
= dbx_alloc_type (typenums
, objfile
);
1865 TYPE_CODE (type
) = code
;
1866 TYPE_TAG_NAME (type
) = type_name
;
1867 INIT_CPLUS_SPECIFIC (type
);
1868 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1870 add_undefined_type (type
);
1874 case '-': /* RS/6000 built-in type */
1888 /* We deal with something like t(1,2)=(3,4)=... which
1889 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
1891 /* Allocate and enter the typedef type first.
1892 This handles recursive types. */
1893 type
= dbx_alloc_type (typenums
, objfile
);
1894 TYPE_CODE (type
) = TYPE_CODE_TYPEDEF
;
1896 struct type
*xtype
= read_type (pp
, objfile
);
1899 /* It's being defined as itself. That means it is "void". */
1900 TYPE_CODE (type
) = TYPE_CODE_VOID
;
1901 TYPE_LENGTH (type
) = 1;
1903 else if (type_size
>= 0 || is_string
)
1905 /* This is the absolute wrong way to construct types. Every
1906 other debug format has found a way around this problem and
1907 the related problems with unnecessarily stubbed types;
1908 someone motivated should attempt to clean up the issue
1909 here as well. Once a type pointed to has been created it
1910 should not be modified.
1912 Well, it's not *absolutely* wrong. Constructing recursive
1913 types (trees, linked lists) necessarily entails modifying
1914 types after creating them. Constructing any loop structure
1915 entails side effects. The Dwarf 2 reader does handle this
1916 more gracefully (it never constructs more than once
1917 instance of a type object, so it doesn't have to copy type
1918 objects wholesale), but it still mutates type objects after
1919 other folks have references to them.
1921 Keep in mind that this circularity/mutation issue shows up
1922 at the source language level, too: C's "incomplete types",
1923 for example. So the proper cleanup, I think, would be to
1924 limit GDB's type smashing to match exactly those required
1925 by the source language. So GDB could have a
1926 "complete_this_type" function, but never create unnecessary
1927 copies of a type otherwise. */
1928 replace_type (type
, xtype
);
1929 TYPE_NAME (type
) = NULL
;
1930 TYPE_TAG_NAME (type
) = NULL
;
1934 TYPE_FLAGS (type
) |= TYPE_FLAG_TARGET_STUB
;
1935 TYPE_TARGET_TYPE (type
) = xtype
;
1940 /* In the following types, we must be sure to overwrite any existing
1941 type that the typenums refer to, rather than allocating a new one
1942 and making the typenums point to the new one. This is because there
1943 may already be pointers to the existing type (if it had been
1944 forward-referenced), and we must change it to a pointer, function,
1945 reference, or whatever, *in-place*. */
1947 case '*': /* Pointer to another type */
1948 type1
= read_type (pp
, objfile
);
1949 type
= make_pointer_type (type1
, dbx_lookup_type (typenums
));
1952 case '&': /* Reference to another type */
1953 type1
= read_type (pp
, objfile
);
1954 type
= make_reference_type (type1
, dbx_lookup_type (typenums
));
1957 case 'f': /* Function returning another type */
1958 type1
= read_type (pp
, objfile
);
1959 type
= make_function_type (type1
, dbx_lookup_type (typenums
));
1962 case 'g': /* Prototyped function. (Sun) */
1964 /* Unresolved questions:
1966 - According to Sun's ``STABS Interface Manual'', for 'f'
1967 and 'F' symbol descriptors, a `0' in the argument type list
1968 indicates a varargs function. But it doesn't say how 'g'
1969 type descriptors represent that info. Someone with access
1970 to Sun's toolchain should try it out.
1972 - According to the comment in define_symbol (search for
1973 `process_prototype_types:'), Sun emits integer arguments as
1974 types which ref themselves --- like `void' types. Do we
1975 have to deal with that here, too? Again, someone with
1976 access to Sun's toolchain should try it out and let us
1979 const char *type_start
= (*pp
) - 1;
1980 struct type
*return_type
= read_type (pp
, objfile
);
1981 struct type
*func_type
1982 = make_function_type (return_type
, dbx_lookup_type (typenums
));
1985 struct type_list
*next
;
1989 while (**pp
&& **pp
!= '#')
1991 struct type
*arg_type
= read_type (pp
, objfile
);
1992 struct type_list
*new = alloca (sizeof (*new));
1993 new->type
= arg_type
;
1994 new->next
= arg_types
;
2002 complaint (&symfile_complaints
,
2003 "Prototyped function type didn't end arguments with `#':\n%s",
2007 /* If there is just one argument whose type is `void', then
2008 that's just an empty argument list. */
2010 && ! arg_types
->next
2011 && TYPE_CODE (arg_types
->type
) == TYPE_CODE_VOID
)
2014 TYPE_FIELDS (func_type
)
2015 = (struct field
*) TYPE_ALLOC (func_type
,
2016 num_args
* sizeof (struct field
));
2017 memset (TYPE_FIELDS (func_type
), 0, num_args
* sizeof (struct field
));
2020 struct type_list
*t
;
2022 /* We stuck each argument type onto the front of the list
2023 when we read it, so the list is reversed. Build the
2024 fields array right-to-left. */
2025 for (t
= arg_types
, i
= num_args
- 1; t
; t
= t
->next
, i
--)
2026 TYPE_FIELD_TYPE (func_type
, i
) = t
->type
;
2028 TYPE_NFIELDS (func_type
) = num_args
;
2029 TYPE_FLAGS (func_type
) |= TYPE_FLAG_PROTOTYPED
;
2035 case 'k': /* Const qualifier on some type (Sun) */
2036 type
= read_type (pp
, objfile
);
2037 type
= make_cv_type (1, TYPE_VOLATILE (type
), type
,
2038 dbx_lookup_type (typenums
));
2041 case 'B': /* Volatile qual on some type (Sun) */
2042 type
= read_type (pp
, objfile
);
2043 type
= make_cv_type (TYPE_CONST (type
), 1, type
,
2044 dbx_lookup_type (typenums
));
2048 if (isdigit (**pp
) || **pp
== '(' || **pp
== '-')
2049 { /* Member (class & variable) type */
2050 /* FIXME -- we should be doing smash_to_XXX types here. */
2052 struct type
*domain
= read_type (pp
, objfile
);
2053 struct type
*memtype
;
2056 /* Invalid member type data format. */
2057 return error_type (pp
, objfile
);
2060 memtype
= read_type (pp
, objfile
);
2061 type
= dbx_alloc_type (typenums
, objfile
);
2062 smash_to_member_type (type
, domain
, memtype
);
2065 /* type attribute */
2068 /* Skip to the semicolon. */
2069 while (**pp
!= ';' && **pp
!= '\0')
2072 return error_type (pp
, objfile
);
2074 ++ * pp
; /* Skip the semicolon. */
2078 case 's': /* Size attribute */
2079 type_size
= atoi (attr
+ 1);
2084 case 'S': /* String attribute */
2085 /* FIXME: check to see if following type is array? */
2089 case 'V': /* Vector attribute */
2090 /* FIXME: check to see if following type is array? */
2095 /* Ignore unrecognized type attributes, so future compilers
2096 can invent new ones. */
2104 case '#': /* Method (class & fn) type */
2105 if ((*pp
)[0] == '#')
2107 /* We'll get the parameter types from the name. */
2108 struct type
*return_type
;
2111 return_type
= read_type (pp
, objfile
);
2112 if (*(*pp
)++ != ';')
2113 complaint (&symfile_complaints
,
2114 "invalid (minimal) member type data format at symtab pos %d.",
2116 type
= allocate_stub_method (return_type
);
2117 if (typenums
[0] != -1)
2118 *dbx_lookup_type (typenums
) = type
;
2122 struct type
*domain
= read_type (pp
, objfile
);
2123 struct type
*return_type
;
2128 /* Invalid member type data format. */
2129 return error_type (pp
, objfile
);
2133 return_type
= read_type (pp
, objfile
);
2134 args
= read_args (pp
, ';', objfile
, &nargs
, &varargs
);
2135 type
= dbx_alloc_type (typenums
, objfile
);
2136 smash_to_method_type (type
, domain
, return_type
, args
,
2141 case 'r': /* Range type */
2142 type
= read_range_type (pp
, typenums
, objfile
);
2143 if (typenums
[0] != -1)
2144 *dbx_lookup_type (typenums
) = type
;
2149 /* Sun ACC builtin int type */
2150 type
= read_sun_builtin_type (pp
, typenums
, objfile
);
2151 if (typenums
[0] != -1)
2152 *dbx_lookup_type (typenums
) = type
;
2156 case 'R': /* Sun ACC builtin float type */
2157 type
= read_sun_floating_type (pp
, typenums
, objfile
);
2158 if (typenums
[0] != -1)
2159 *dbx_lookup_type (typenums
) = type
;
2162 case 'e': /* Enumeration type */
2163 type
= dbx_alloc_type (typenums
, objfile
);
2164 type
= read_enum_type (pp
, type
, objfile
);
2165 if (typenums
[0] != -1)
2166 *dbx_lookup_type (typenums
) = type
;
2169 case 's': /* Struct type */
2170 case 'u': /* Union type */
2172 enum type_code type_code
= TYPE_CODE_UNDEF
;
2173 type
= dbx_alloc_type (typenums
, objfile
);
2174 switch (type_descriptor
)
2177 type_code
= TYPE_CODE_STRUCT
;
2180 type_code
= TYPE_CODE_UNION
;
2183 type
= read_struct_type (pp
, type
, type_code
, objfile
);
2187 case 'a': /* Array type */
2189 return error_type (pp
, objfile
);
2192 type
= dbx_alloc_type (typenums
, objfile
);
2193 type
= read_array_type (pp
, type
, objfile
);
2195 TYPE_CODE (type
) = TYPE_CODE_STRING
;
2197 TYPE_FLAGS (type
) |= TYPE_FLAG_VECTOR
;
2200 case 'S': /* Set or bitstring type */
2201 type1
= read_type (pp
, objfile
);
2202 type
= create_set_type ((struct type
*) NULL
, type1
);
2204 TYPE_CODE (type
) = TYPE_CODE_BITSTRING
;
2205 if (typenums
[0] != -1)
2206 *dbx_lookup_type (typenums
) = type
;
2210 --*pp
; /* Go back to the symbol in error */
2211 /* Particularly important if it was \0! */
2212 return error_type (pp
, objfile
);
2217 warning ("GDB internal error, type is NULL in stabsread.c\n");
2218 return error_type (pp
, objfile
);
2221 /* Size specified in a type attribute overrides any other size. */
2222 if (type_size
!= -1)
2223 TYPE_LENGTH (type
) = (type_size
+ TARGET_CHAR_BIT
- 1) / TARGET_CHAR_BIT
;
2228 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2229 Return the proper type node for a given builtin type number. */
2231 static struct type
*
2232 rs6000_builtin_type (int typenum
)
2234 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2235 #define NUMBER_RECOGNIZED 34
2236 /* This includes an empty slot for type number -0. */
2237 static struct type
*negative_types
[NUMBER_RECOGNIZED
+ 1];
2238 struct type
*rettype
= NULL
;
2240 if (typenum
>= 0 || typenum
< -NUMBER_RECOGNIZED
)
2242 complaint (&symfile_complaints
, "Unknown builtin type %d", typenum
);
2243 return builtin_type_error
;
2245 if (negative_types
[-typenum
] != NULL
)
2246 return negative_types
[-typenum
];
2248 #if TARGET_CHAR_BIT != 8
2249 #error This code wrong for TARGET_CHAR_BIT not 8
2250 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2251 that if that ever becomes not true, the correct fix will be to
2252 make the size in the struct type to be in bits, not in units of
2259 /* The size of this and all the other types are fixed, defined
2260 by the debugging format. If there is a type called "int" which
2261 is other than 32 bits, then it should use a new negative type
2262 number (or avoid negative type numbers for that case).
2263 See stabs.texinfo. */
2264 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "int", NULL
);
2267 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "char", NULL
);
2270 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "short", NULL
);
2273 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "long", NULL
);
2276 rettype
= init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_UNSIGNED
,
2277 "unsigned char", NULL
);
2280 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "signed char", NULL
);
2283 rettype
= init_type (TYPE_CODE_INT
, 2, TYPE_FLAG_UNSIGNED
,
2284 "unsigned short", NULL
);
2287 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2288 "unsigned int", NULL
);
2291 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2294 rettype
= init_type (TYPE_CODE_INT
, 4, TYPE_FLAG_UNSIGNED
,
2295 "unsigned long", NULL
);
2298 rettype
= init_type (TYPE_CODE_VOID
, 1, 0, "void", NULL
);
2301 /* IEEE single precision (32 bit). */
2302 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "float", NULL
);
2305 /* IEEE double precision (64 bit). */
2306 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "double", NULL
);
2309 /* This is an IEEE double on the RS/6000, and different machines with
2310 different sizes for "long double" should use different negative
2311 type numbers. See stabs.texinfo. */
2312 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "long double", NULL
);
2315 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer", NULL
);
2318 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2322 rettype
= init_type (TYPE_CODE_FLT
, 4, 0, "short real", NULL
);
2325 rettype
= init_type (TYPE_CODE_FLT
, 8, 0, "real", NULL
);
2328 rettype
= init_type (TYPE_CODE_ERROR
, 0, 0, "stringptr", NULL
);
2331 rettype
= init_type (TYPE_CODE_CHAR
, 1, TYPE_FLAG_UNSIGNED
,
2335 rettype
= init_type (TYPE_CODE_BOOL
, 1, TYPE_FLAG_UNSIGNED
,
2339 rettype
= init_type (TYPE_CODE_BOOL
, 2, TYPE_FLAG_UNSIGNED
,
2343 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2347 rettype
= init_type (TYPE_CODE_BOOL
, 4, TYPE_FLAG_UNSIGNED
,
2351 /* Complex type consisting of two IEEE single precision values. */
2352 rettype
= init_type (TYPE_CODE_COMPLEX
, 8, 0, "complex", NULL
);
2353 TYPE_TARGET_TYPE (rettype
) = init_type (TYPE_CODE_FLT
, 4, 0, "float",
2357 /* Complex type consisting of two IEEE double precision values. */
2358 rettype
= init_type (TYPE_CODE_COMPLEX
, 16, 0, "double complex", NULL
);
2359 TYPE_TARGET_TYPE (rettype
) = init_type (TYPE_CODE_FLT
, 8, 0, "double",
2363 rettype
= init_type (TYPE_CODE_INT
, 1, 0, "integer*1", NULL
);
2366 rettype
= init_type (TYPE_CODE_INT
, 2, 0, "integer*2", NULL
);
2369 rettype
= init_type (TYPE_CODE_INT
, 4, 0, "integer*4", NULL
);
2372 rettype
= init_type (TYPE_CODE_CHAR
, 2, 0, "wchar", NULL
);
2375 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "long long", NULL
);
2378 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2379 "unsigned long long", NULL
);
2382 rettype
= init_type (TYPE_CODE_INT
, 8, TYPE_FLAG_UNSIGNED
,
2386 rettype
= init_type (TYPE_CODE_INT
, 8, 0, "integer*8", NULL
);
2389 negative_types
[-typenum
] = rettype
;
2393 /* This page contains subroutines of read_type. */
2395 /* Replace *OLD_NAME with the method name portion of PHYSNAME. */
2398 update_method_name_from_physname (char **old_name
, char *physname
)
2402 method_name
= method_name_from_physname (physname
);
2404 if (method_name
== NULL
)
2406 complaint (&symfile_complaints
,
2407 "Method has bad physname %s\n", physname
);
2411 if (strcmp (*old_name
, method_name
) != 0)
2414 *old_name
= method_name
;
2417 xfree (method_name
);
2420 /* Read member function stabs info for C++ classes. The form of each member
2423 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
2425 An example with two member functions is:
2427 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
2429 For the case of overloaded operators, the format is op$::*.funcs, where
2430 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2431 name (such as `+=') and `.' marks the end of the operator name.
2433 Returns 1 for success, 0 for failure. */
2436 read_member_functions (struct field_info
*fip
, char **pp
, struct type
*type
,
2437 struct objfile
*objfile
)
2441 /* Total number of member functions defined in this class. If the class
2442 defines two `f' functions, and one `g' function, then this will have
2444 int total_length
= 0;
2448 struct next_fnfield
*next
;
2449 struct fn_field fn_field
;
2452 struct type
*look_ahead_type
;
2453 struct next_fnfieldlist
*new_fnlist
;
2454 struct next_fnfield
*new_sublist
;
2458 /* Process each list until we find something that is not a member function
2459 or find the end of the functions. */
2463 /* We should be positioned at the start of the function name.
2464 Scan forward to find the first ':' and if it is not the
2465 first of a "::" delimiter, then this is not a member function. */
2477 look_ahead_type
= NULL
;
2480 new_fnlist
= (struct next_fnfieldlist
*)
2481 xmalloc (sizeof (struct next_fnfieldlist
));
2482 make_cleanup (xfree
, new_fnlist
);
2483 memset (new_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2485 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && is_cplus_marker ((*pp
)[2]))
2487 /* This is a completely wierd case. In order to stuff in the
2488 names that might contain colons (the usual name delimiter),
2489 Mike Tiemann defined a different name format which is
2490 signalled if the identifier is "op$". In that case, the
2491 format is "op$::XXXX." where XXXX is the name. This is
2492 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2493 /* This lets the user type "break operator+".
2494 We could just put in "+" as the name, but that wouldn't
2496 static char opname
[32] = "op$";
2497 char *o
= opname
+ 3;
2499 /* Skip past '::'. */
2502 STABS_CONTINUE (pp
, objfile
);
2508 main_fn_name
= savestring (opname
, o
- opname
);
2514 main_fn_name
= savestring (*pp
, p
- *pp
);
2515 /* Skip past '::'. */
2518 new_fnlist
->fn_fieldlist
.name
= main_fn_name
;
2523 (struct next_fnfield
*) xmalloc (sizeof (struct next_fnfield
));
2524 make_cleanup (xfree
, new_sublist
);
2525 memset (new_sublist
, 0, sizeof (struct next_fnfield
));
2527 /* Check for and handle cretinous dbx symbol name continuation! */
2528 if (look_ahead_type
== NULL
)
2531 STABS_CONTINUE (pp
, objfile
);
2533 new_sublist
->fn_field
.type
= read_type (pp
, objfile
);
2536 /* Invalid symtab info for member function. */
2542 /* g++ version 1 kludge */
2543 new_sublist
->fn_field
.type
= look_ahead_type
;
2544 look_ahead_type
= NULL
;
2554 /* If this is just a stub, then we don't have the real name here. */
2556 if (TYPE_STUB (new_sublist
->fn_field
.type
))
2558 if (!TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
))
2559 TYPE_DOMAIN_TYPE (new_sublist
->fn_field
.type
) = type
;
2560 new_sublist
->fn_field
.is_stub
= 1;
2562 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
2565 /* Set this member function's visibility fields. */
2568 case VISIBILITY_PRIVATE
:
2569 new_sublist
->fn_field
.is_private
= 1;
2571 case VISIBILITY_PROTECTED
:
2572 new_sublist
->fn_field
.is_protected
= 1;
2576 STABS_CONTINUE (pp
, objfile
);
2579 case 'A': /* Normal functions. */
2580 new_sublist
->fn_field
.is_const
= 0;
2581 new_sublist
->fn_field
.is_volatile
= 0;
2584 case 'B': /* `const' member functions. */
2585 new_sublist
->fn_field
.is_const
= 1;
2586 new_sublist
->fn_field
.is_volatile
= 0;
2589 case 'C': /* `volatile' member function. */
2590 new_sublist
->fn_field
.is_const
= 0;
2591 new_sublist
->fn_field
.is_volatile
= 1;
2594 case 'D': /* `const volatile' member function. */
2595 new_sublist
->fn_field
.is_const
= 1;
2596 new_sublist
->fn_field
.is_volatile
= 1;
2599 case '*': /* File compiled with g++ version 1 -- no info */
2604 complaint (&symfile_complaints
,
2605 "const/volatile indicator missing, got '%c'", **pp
);
2614 /* virtual member function, followed by index.
2615 The sign bit is set to distinguish pointers-to-methods
2616 from virtual function indicies. Since the array is
2617 in words, the quantity must be shifted left by 1
2618 on 16 bit machine, and by 2 on 32 bit machine, forcing
2619 the sign bit out, and usable as a valid index into
2620 the array. Remove the sign bit here. */
2621 new_sublist
->fn_field
.voffset
=
2622 (0x7fffffff & read_huge_number (pp
, ';', &nbits
)) + 2;
2626 STABS_CONTINUE (pp
, objfile
);
2627 if (**pp
== ';' || **pp
== '\0')
2629 /* Must be g++ version 1. */
2630 new_sublist
->fn_field
.fcontext
= 0;
2634 /* Figure out from whence this virtual function came.
2635 It may belong to virtual function table of
2636 one of its baseclasses. */
2637 look_ahead_type
= read_type (pp
, objfile
);
2640 /* g++ version 1 overloaded methods. */
2644 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2653 look_ahead_type
= NULL
;
2659 /* static member function. */
2661 int slen
= strlen (main_fn_name
);
2663 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2665 /* For static member functions, we can't tell if they
2666 are stubbed, as they are put out as functions, and not as
2668 GCC v2 emits the fully mangled name if
2669 dbxout.c:flag_minimal_debug is not set, so we have to
2670 detect a fully mangled physname here and set is_stub
2671 accordingly. Fully mangled physnames in v2 start with
2672 the member function name, followed by two underscores.
2673 GCC v3 currently always emits stubbed member functions,
2674 but with fully mangled physnames, which start with _Z. */
2675 if (!(strncmp (new_sublist
->fn_field
.physname
,
2676 main_fn_name
, slen
) == 0
2677 && new_sublist
->fn_field
.physname
[slen
] == '_'
2678 && new_sublist
->fn_field
.physname
[slen
+ 1] == '_'))
2680 new_sublist
->fn_field
.is_stub
= 1;
2687 complaint (&symfile_complaints
,
2688 "member function type missing, got '%c'", (*pp
)[-1]);
2689 /* Fall through into normal member function. */
2692 /* normal member function. */
2693 new_sublist
->fn_field
.voffset
= 0;
2694 new_sublist
->fn_field
.fcontext
= 0;
2698 new_sublist
->next
= sublist
;
2699 sublist
= new_sublist
;
2701 STABS_CONTINUE (pp
, objfile
);
2703 while (**pp
!= ';' && **pp
!= '\0');
2706 STABS_CONTINUE (pp
, objfile
);
2708 /* Skip GCC 3.X member functions which are duplicates of the callable
2709 constructor/destructor. */
2710 if (strcmp (main_fn_name
, "__base_ctor") == 0
2711 || strcmp (main_fn_name
, "__base_dtor") == 0
2712 || strcmp (main_fn_name
, "__deleting_dtor") == 0)
2714 xfree (main_fn_name
);
2719 int has_destructor
= 0, has_other
= 0;
2721 struct next_fnfield
*tmp_sublist
;
2723 /* Various versions of GCC emit various mostly-useless
2724 strings in the name field for special member functions.
2726 For stub methods, we need to defer correcting the name
2727 until we are ready to unstub the method, because the current
2728 name string is used by gdb_mangle_name. The only stub methods
2729 of concern here are GNU v2 operators; other methods have their
2730 names correct (see caveat below).
2732 For non-stub methods, in GNU v3, we have a complete physname.
2733 Therefore we can safely correct the name now. This primarily
2734 affects constructors and destructors, whose name will be
2735 __comp_ctor or __comp_dtor instead of Foo or ~Foo. Cast
2736 operators will also have incorrect names; for instance,
2737 "operator int" will be named "operator i" (i.e. the type is
2740 For non-stub methods in GNU v2, we have no easy way to
2741 know if we have a complete physname or not. For most
2742 methods the result depends on the platform (if CPLUS_MARKER
2743 can be `$' or `.', it will use minimal debug information, or
2744 otherwise the full physname will be included).
2746 Rather than dealing with this, we take a different approach.
2747 For v3 mangled names, we can use the full physname; for v2,
2748 we use cplus_demangle_opname (which is actually v2 specific),
2749 because the only interesting names are all operators - once again
2750 barring the caveat below. Skip this process if any method in the
2751 group is a stub, to prevent our fouling up the workings of
2754 The caveat: GCC 2.95.x (and earlier?) put constructors and
2755 destructors in the same method group. We need to split this
2756 into two groups, because they should have different names.
2757 So for each method group we check whether it contains both
2758 routines whose physname appears to be a destructor (the physnames
2759 for and destructors are always provided, due to quirks in v2
2760 mangling) and routines whose physname does not appear to be a
2761 destructor. If so then we break up the list into two halves.
2762 Even if the constructors and destructors aren't in the same group
2763 the destructor will still lack the leading tilde, so that also
2766 So, to summarize what we expect and handle here:
2768 Given Given Real Real Action
2769 method name physname physname method name
2771 __opi [none] __opi__3Foo operator int opname
2773 Foo _._3Foo _._3Foo ~Foo separate and
2775 operator i _ZN3FoocviEv _ZN3FoocviEv operator int demangle
2776 __comp_ctor _ZN3FooC1ERKS_ _ZN3FooC1ERKS_ Foo demangle
2779 tmp_sublist
= sublist
;
2780 while (tmp_sublist
!= NULL
)
2782 if (tmp_sublist
->fn_field
.is_stub
)
2784 if (tmp_sublist
->fn_field
.physname
[0] == '_'
2785 && tmp_sublist
->fn_field
.physname
[1] == 'Z')
2788 if (is_destructor_name (tmp_sublist
->fn_field
.physname
))
2793 tmp_sublist
= tmp_sublist
->next
;
2796 if (has_destructor
&& has_other
)
2798 struct next_fnfieldlist
*destr_fnlist
;
2799 struct next_fnfield
*last_sublist
;
2801 /* Create a new fn_fieldlist for the destructors. */
2803 destr_fnlist
= (struct next_fnfieldlist
*)
2804 xmalloc (sizeof (struct next_fnfieldlist
));
2805 make_cleanup (xfree
, destr_fnlist
);
2806 memset (destr_fnlist
, 0, sizeof (struct next_fnfieldlist
));
2807 destr_fnlist
->fn_fieldlist
.name
2808 = obconcat (&objfile
->type_obstack
, "", "~",
2809 new_fnlist
->fn_fieldlist
.name
);
2811 destr_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
2812 obstack_alloc (&objfile
->type_obstack
,
2813 sizeof (struct fn_field
) * has_destructor
);
2814 memset (destr_fnlist
->fn_fieldlist
.fn_fields
, 0,
2815 sizeof (struct fn_field
) * has_destructor
);
2816 tmp_sublist
= sublist
;
2817 last_sublist
= NULL
;
2819 while (tmp_sublist
!= NULL
)
2821 if (!is_destructor_name (tmp_sublist
->fn_field
.physname
))
2823 tmp_sublist
= tmp_sublist
->next
;
2827 destr_fnlist
->fn_fieldlist
.fn_fields
[i
++]
2828 = tmp_sublist
->fn_field
;
2830 last_sublist
->next
= tmp_sublist
->next
;
2832 sublist
= tmp_sublist
->next
;
2833 last_sublist
= tmp_sublist
;
2834 tmp_sublist
= tmp_sublist
->next
;
2837 destr_fnlist
->fn_fieldlist
.length
= has_destructor
;
2838 destr_fnlist
->next
= fip
->fnlist
;
2839 fip
->fnlist
= destr_fnlist
;
2841 total_length
+= has_destructor
;
2842 length
-= has_destructor
;
2846 /* v3 mangling prevents the use of abbreviated physnames,
2847 so we can do this here. There are stubbed methods in v3
2849 - in -gstabs instead of -gstabs+
2850 - or for static methods, which are output as a function type
2851 instead of a method type. */
2853 update_method_name_from_physname (&new_fnlist
->fn_fieldlist
.name
,
2854 sublist
->fn_field
.physname
);
2856 else if (has_destructor
&& new_fnlist
->fn_fieldlist
.name
[0] != '~')
2858 new_fnlist
->fn_fieldlist
.name
= concat ("~", main_fn_name
, NULL
);
2859 xfree (main_fn_name
);
2863 char dem_opname
[256];
2865 ret
= cplus_demangle_opname (new_fnlist
->fn_fieldlist
.name
,
2866 dem_opname
, DMGL_ANSI
);
2868 ret
= cplus_demangle_opname (new_fnlist
->fn_fieldlist
.name
,
2871 new_fnlist
->fn_fieldlist
.name
2872 = obsavestring (dem_opname
, strlen (dem_opname
),
2873 &objfile
->type_obstack
);
2876 new_fnlist
->fn_fieldlist
.fn_fields
= (struct fn_field
*)
2877 obstack_alloc (&objfile
->type_obstack
,
2878 sizeof (struct fn_field
) * length
);
2879 memset (new_fnlist
->fn_fieldlist
.fn_fields
, 0,
2880 sizeof (struct fn_field
) * length
);
2881 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2883 new_fnlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2886 new_fnlist
->fn_fieldlist
.length
= length
;
2887 new_fnlist
->next
= fip
->fnlist
;
2888 fip
->fnlist
= new_fnlist
;
2890 total_length
+= length
;
2896 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
2897 TYPE_FN_FIELDLISTS (type
) = (struct fn_fieldlist
*)
2898 TYPE_ALLOC (type
, sizeof (struct fn_fieldlist
) * nfn_fields
);
2899 memset (TYPE_FN_FIELDLISTS (type
), 0,
2900 sizeof (struct fn_fieldlist
) * nfn_fields
);
2901 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2902 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2908 /* Special GNU C++ name.
2910 Returns 1 for success, 0 for failure. "failure" means that we can't
2911 keep parsing and it's time for error_type(). */
2914 read_cpp_abbrev (struct field_info
*fip
, char **pp
, struct type
*type
,
2915 struct objfile
*objfile
)
2920 struct type
*context
;
2930 /* At this point, *pp points to something like "22:23=*22...",
2931 where the type number before the ':' is the "context" and
2932 everything after is a regular type definition. Lookup the
2933 type, find it's name, and construct the field name. */
2935 context
= read_type (pp
, objfile
);
2939 case 'f': /* $vf -- a virtual function table pointer */
2940 name
= type_name_no_tag (context
);
2945 fip
->list
->field
.name
=
2946 obconcat (&objfile
->type_obstack
, vptr_name
, name
, "");
2949 case 'b': /* $vb -- a virtual bsomethingorother */
2950 name
= type_name_no_tag (context
);
2953 complaint (&symfile_complaints
,
2954 "C++ abbreviated type name unknown at symtab pos %d",
2958 fip
->list
->field
.name
=
2959 obconcat (&objfile
->type_obstack
, vb_name
, name
, "");
2963 invalid_cpp_abbrev_complaint (*pp
);
2964 fip
->list
->field
.name
=
2965 obconcat (&objfile
->type_obstack
,
2966 "INVALID_CPLUSPLUS_ABBREV", "", "");
2970 /* At this point, *pp points to the ':'. Skip it and read the
2976 invalid_cpp_abbrev_complaint (*pp
);
2979 fip
->list
->field
.type
= read_type (pp
, objfile
);
2981 (*pp
)++; /* Skip the comma. */
2987 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
2991 /* This field is unpacked. */
2992 FIELD_BITSIZE (fip
->list
->field
) = 0;
2993 fip
->list
->visibility
= VISIBILITY_PRIVATE
;
2997 invalid_cpp_abbrev_complaint (*pp
);
2998 /* We have no idea what syntax an unrecognized abbrev would have, so
2999 better return 0. If we returned 1, we would need to at least advance
3000 *pp to avoid an infinite loop. */
3007 read_one_struct_field (struct field_info
*fip
, char **pp
, char *p
,
3008 struct type
*type
, struct objfile
*objfile
)
3010 fip
->list
->field
.name
=
3011 obsavestring (*pp
, p
- *pp
, &objfile
->type_obstack
);
3014 /* This means we have a visibility for a field coming. */
3018 fip
->list
->visibility
= *(*pp
)++;
3022 /* normal dbx-style format, no explicit visibility */
3023 fip
->list
->visibility
= VISIBILITY_PUBLIC
;
3026 fip
->list
->field
.type
= read_type (pp
, objfile
);
3031 /* Possible future hook for nested types. */
3034 fip
->list
->field
.bitpos
= (long) -2; /* nested type */
3044 /* Static class member. */
3045 SET_FIELD_PHYSNAME (fip
->list
->field
, savestring (*pp
, p
- *pp
));
3049 else if (**pp
!= ',')
3051 /* Bad structure-type format. */
3052 stabs_general_complaint ("bad structure-type format");
3056 (*pp
)++; /* Skip the comma. */
3060 FIELD_BITPOS (fip
->list
->field
) = read_huge_number (pp
, ',', &nbits
);
3063 stabs_general_complaint ("bad structure-type format");
3066 FIELD_BITSIZE (fip
->list
->field
) = read_huge_number (pp
, ';', &nbits
);
3069 stabs_general_complaint ("bad structure-type format");
3074 if (FIELD_BITPOS (fip
->list
->field
) == 0
3075 && FIELD_BITSIZE (fip
->list
->field
) == 0)
3077 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
3078 it is a field which has been optimized out. The correct stab for
3079 this case is to use VISIBILITY_IGNORE, but that is a recent
3080 invention. (2) It is a 0-size array. For example
3081 union { int num; char str[0]; } foo. Printing "<no value>" for
3082 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3083 will continue to work, and a 0-size array as a whole doesn't
3084 have any contents to print.
3086 I suspect this probably could also happen with gcc -gstabs (not
3087 -gstabs+) for static fields, and perhaps other C++ extensions.
3088 Hopefully few people use -gstabs with gdb, since it is intended
3089 for dbx compatibility. */
3091 /* Ignore this field. */
3092 fip
->list
->visibility
= VISIBILITY_IGNORE
;
3096 /* Detect an unpacked field and mark it as such.
3097 dbx gives a bit size for all fields.
3098 Note that forward refs cannot be packed,
3099 and treat enums as if they had the width of ints. */
3101 struct type
*field_type
= check_typedef (FIELD_TYPE (fip
->list
->field
));
3103 if (TYPE_CODE (field_type
) != TYPE_CODE_INT
3104 && TYPE_CODE (field_type
) != TYPE_CODE_RANGE
3105 && TYPE_CODE (field_type
) != TYPE_CODE_BOOL
3106 && TYPE_CODE (field_type
) != TYPE_CODE_ENUM
)
3108 FIELD_BITSIZE (fip
->list
->field
) = 0;
3110 if ((FIELD_BITSIZE (fip
->list
->field
)
3111 == TARGET_CHAR_BIT
* TYPE_LENGTH (field_type
)
3112 || (TYPE_CODE (field_type
) == TYPE_CODE_ENUM
3113 && FIELD_BITSIZE (fip
->list
->field
) == TARGET_INT_BIT
)
3116 FIELD_BITPOS (fip
->list
->field
) % 8 == 0)
3118 FIELD_BITSIZE (fip
->list
->field
) = 0;
3124 /* Read struct or class data fields. They have the form:
3126 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
3128 At the end, we see a semicolon instead of a field.
3130 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3133 The optional VISIBILITY is one of:
3135 '/0' (VISIBILITY_PRIVATE)
3136 '/1' (VISIBILITY_PROTECTED)
3137 '/2' (VISIBILITY_PUBLIC)
3138 '/9' (VISIBILITY_IGNORE)
3140 or nothing, for C style fields with public visibility.
3142 Returns 1 for success, 0 for failure. */
3145 read_struct_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3146 struct objfile
*objfile
)
3149 struct nextfield
*new;
3151 /* We better set p right now, in case there are no fields at all... */
3155 /* Read each data member type until we find the terminating ';' at the end of
3156 the data member list, or break for some other reason such as finding the
3157 start of the member function list. */
3158 /* Stab string for structure/union does not end with two ';' in
3159 SUN C compiler 5.3 i.e. F6U2, hence check for end of string. */
3161 while (**pp
!= ';' && **pp
!= '\0')
3163 STABS_CONTINUE (pp
, objfile
);
3164 /* Get space to record the next field's data. */
3165 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3166 make_cleanup (xfree
, new);
3167 memset (new, 0, sizeof (struct nextfield
));
3168 new->next
= fip
->list
;
3171 /* Get the field name. */
3174 /* If is starts with CPLUS_MARKER it is a special abbreviation,
3175 unless the CPLUS_MARKER is followed by an underscore, in
3176 which case it is just the name of an anonymous type, which we
3177 should handle like any other type name. */
3179 if (is_cplus_marker (p
[0]) && p
[1] != '_')
3181 if (!read_cpp_abbrev (fip
, pp
, type
, objfile
))
3186 /* Look for the ':' that separates the field name from the field
3187 values. Data members are delimited by a single ':', while member
3188 functions are delimited by a pair of ':'s. When we hit the member
3189 functions (if any), terminate scan loop and return. */
3191 while (*p
!= ':' && *p
!= '\0')
3198 /* Check to see if we have hit the member functions yet. */
3203 read_one_struct_field (fip
, pp
, p
, type
, objfile
);
3205 if (p
[0] == ':' && p
[1] == ':')
3207 /* (the deleted) chill the list of fields: the last entry (at
3208 the head) is a partially constructed entry which we now
3210 fip
->list
= fip
->list
->next
;
3215 /* The stabs for C++ derived classes contain baseclass information which
3216 is marked by a '!' character after the total size. This function is
3217 called when we encounter the baseclass marker, and slurps up all the
3218 baseclass information.
3220 Immediately following the '!' marker is the number of base classes that
3221 the class is derived from, followed by information for each base class.
3222 For each base class, there are two visibility specifiers, a bit offset
3223 to the base class information within the derived class, a reference to
3224 the type for the base class, and a terminating semicolon.
3226 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3228 Baseclass information marker __________________|| | | | | | |
3229 Number of baseclasses __________________________| | | | | | |
3230 Visibility specifiers (2) ________________________| | | | | |
3231 Offset in bits from start of class _________________| | | | |
3232 Type number for base class ___________________________| | | |
3233 Visibility specifiers (2) _______________________________| | |
3234 Offset in bits from start of class ________________________| |
3235 Type number of base class ____________________________________|
3237 Return 1 for success, 0 for (error-type-inducing) failure. */
3243 read_baseclasses (struct field_info
*fip
, char **pp
, struct type
*type
,
3244 struct objfile
*objfile
)
3247 struct nextfield
*new;
3255 /* Skip the '!' baseclass information marker. */
3259 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3262 TYPE_N_BASECLASSES (type
) = read_huge_number (pp
, ',', &nbits
);
3268 /* Some stupid compilers have trouble with the following, so break
3269 it up into simpler expressions. */
3270 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*)
3271 TYPE_ALLOC (type
, B_BYTES (TYPE_N_BASECLASSES (type
)));
3274 int num_bytes
= B_BYTES (TYPE_N_BASECLASSES (type
));
3277 pointer
= (char *) TYPE_ALLOC (type
, num_bytes
);
3278 TYPE_FIELD_VIRTUAL_BITS (type
) = (B_TYPE
*) pointer
;
3282 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), TYPE_N_BASECLASSES (type
));
3284 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); i
++)
3286 new = (struct nextfield
*) xmalloc (sizeof (struct nextfield
));
3287 make_cleanup (xfree
, new);
3288 memset (new, 0, sizeof (struct nextfield
));
3289 new->next
= fip
->list
;
3291 FIELD_BITSIZE (new->field
) = 0; /* this should be an unpacked field! */
3293 STABS_CONTINUE (pp
, objfile
);
3297 /* Nothing to do. */
3300 SET_TYPE_FIELD_VIRTUAL (type
, i
);
3303 /* Unknown character. Complain and treat it as non-virtual. */
3305 complaint (&symfile_complaints
,
3306 "Unknown virtual character `%c' for baseclass", **pp
);
3311 new->visibility
= *(*pp
)++;
3312 switch (new->visibility
)
3314 case VISIBILITY_PRIVATE
:
3315 case VISIBILITY_PROTECTED
:
3316 case VISIBILITY_PUBLIC
:
3319 /* Bad visibility format. Complain and treat it as
3322 complaint (&symfile_complaints
,
3323 "Unknown visibility `%c' for baseclass",
3325 new->visibility
= VISIBILITY_PUBLIC
;
3332 /* The remaining value is the bit offset of the portion of the object
3333 corresponding to this baseclass. Always zero in the absence of
3334 multiple inheritance. */
3336 FIELD_BITPOS (new->field
) = read_huge_number (pp
, ',', &nbits
);
3341 /* The last piece of baseclass information is the type of the
3342 base class. Read it, and remember it's type name as this
3345 new->field
.type
= read_type (pp
, objfile
);
3346 new->field
.name
= type_name_no_tag (new->field
.type
);
3348 /* skip trailing ';' and bump count of number of fields seen */
3357 /* The tail end of stabs for C++ classes that contain a virtual function
3358 pointer contains a tilde, a %, and a type number.
3359 The type number refers to the base class (possibly this class itself) which
3360 contains the vtable pointer for the current class.
3362 This function is called when we have parsed all the method declarations,
3363 so we can look for the vptr base class info. */
3366 read_tilde_fields (struct field_info
*fip
, char **pp
, struct type
*type
,
3367 struct objfile
*objfile
)
3371 STABS_CONTINUE (pp
, objfile
);
3373 /* If we are positioned at a ';', then skip it. */
3383 if (**pp
== '=' || **pp
== '+' || **pp
== '-')
3385 /* Obsolete flags that used to indicate the presence
3386 of constructors and/or destructors. */
3390 /* Read either a '%' or the final ';'. */
3391 if (*(*pp
)++ == '%')
3393 /* The next number is the type number of the base class
3394 (possibly our own class) which supplies the vtable for
3395 this class. Parse it out, and search that class to find
3396 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3397 and TYPE_VPTR_FIELDNO. */
3402 t
= read_type (pp
, objfile
);
3404 while (*p
!= '\0' && *p
!= ';')
3410 /* Premature end of symbol. */
3414 TYPE_VPTR_BASETYPE (type
) = t
;
3415 if (type
== t
) /* Our own class provides vtbl ptr */
3417 for (i
= TYPE_NFIELDS (t
) - 1;
3418 i
>= TYPE_N_BASECLASSES (t
);
3421 char *name
= TYPE_FIELD_NAME (t
, i
);
3422 if (!strncmp (name
, vptr_name
, sizeof (vptr_name
) - 2)
3423 && is_cplus_marker (name
[sizeof (vptr_name
) - 2]))
3425 TYPE_VPTR_FIELDNO (type
) = i
;
3429 /* Virtual function table field not found. */
3430 complaint (&symfile_complaints
,
3431 "virtual function table pointer not found when defining class `%s'",
3437 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
3448 attach_fn_fields_to_type (struct field_info
*fip
, struct type
*type
)
3452 for (n
= TYPE_NFN_FIELDS (type
);
3453 fip
->fnlist
!= NULL
;
3454 fip
->fnlist
= fip
->fnlist
->next
)
3456 --n
; /* Circumvent Sun3 compiler bug */
3457 TYPE_FN_FIELDLISTS (type
)[n
] = fip
->fnlist
->fn_fieldlist
;
3462 /* Create the vector of fields, and record how big it is.
3463 We need this info to record proper virtual function table information
3464 for this class's virtual functions. */
3467 attach_fields_to_type (struct field_info
*fip
, struct type
*type
,
3468 struct objfile
*objfile
)
3471 int non_public_fields
= 0;
3472 struct nextfield
*scan
;
3474 /* Count up the number of fields that we have, as well as taking note of
3475 whether or not there are any non-public fields, which requires us to
3476 allocate and build the private_field_bits and protected_field_bits
3479 for (scan
= fip
->list
; scan
!= NULL
; scan
= scan
->next
)
3482 if (scan
->visibility
!= VISIBILITY_PUBLIC
)
3484 non_public_fields
++;
3488 /* Now we know how many fields there are, and whether or not there are any
3489 non-public fields. Record the field count, allocate space for the
3490 array of fields, and create blank visibility bitfields if necessary. */
3492 TYPE_NFIELDS (type
) = nfields
;
3493 TYPE_FIELDS (type
) = (struct field
*)
3494 TYPE_ALLOC (type
, sizeof (struct field
) * nfields
);
3495 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nfields
);
3497 if (non_public_fields
)
3499 ALLOCATE_CPLUS_STRUCT_TYPE (type
);
3501 TYPE_FIELD_PRIVATE_BITS (type
) =
3502 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3503 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
3505 TYPE_FIELD_PROTECTED_BITS (type
) =
3506 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3507 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
3509 TYPE_FIELD_IGNORE_BITS (type
) =
3510 (B_TYPE
*) TYPE_ALLOC (type
, B_BYTES (nfields
));
3511 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type
), nfields
);
3514 /* Copy the saved-up fields into the field vector. Start from the head
3515 of the list, adding to the tail of the field array, so that they end
3516 up in the same order in the array in which they were added to the list. */
3518 while (nfields
-- > 0)
3520 TYPE_FIELD (type
, nfields
) = fip
->list
->field
;
3521 switch (fip
->list
->visibility
)
3523 case VISIBILITY_PRIVATE
:
3524 SET_TYPE_FIELD_PRIVATE (type
, nfields
);
3527 case VISIBILITY_PROTECTED
:
3528 SET_TYPE_FIELD_PROTECTED (type
, nfields
);
3531 case VISIBILITY_IGNORE
:
3532 SET_TYPE_FIELD_IGNORE (type
, nfields
);
3535 case VISIBILITY_PUBLIC
:
3539 /* Unknown visibility. Complain and treat it as public. */
3541 complaint (&symfile_complaints
, "Unknown visibility `%c' for field",
3542 fip
->list
->visibility
);
3546 fip
->list
= fip
->list
->next
;
3552 /* Complain that the compiler has emitted more than one definition for the
3553 structure type TYPE. */
3555 complain_about_struct_wipeout (struct type
*type
)
3560 if (TYPE_TAG_NAME (type
))
3562 name
= TYPE_TAG_NAME (type
);
3563 switch (TYPE_CODE (type
))
3565 case TYPE_CODE_STRUCT
: kind
= "struct "; break;
3566 case TYPE_CODE_UNION
: kind
= "union "; break;
3567 case TYPE_CODE_ENUM
: kind
= "enum "; break;
3571 else if (TYPE_NAME (type
))
3573 name
= TYPE_NAME (type
);
3582 complaint (&symfile_complaints
,
3583 "struct/union type gets multiply defined: %s%s", kind
, name
);
3587 /* Read the description of a structure (or union type) and return an object
3588 describing the type.
3590 PP points to a character pointer that points to the next unconsumed token
3591 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3592 *PP will point to "4a:1,0,32;;".
3594 TYPE points to an incomplete type that needs to be filled in.
3596 OBJFILE points to the current objfile from which the stabs information is
3597 being read. (Note that it is redundant in that TYPE also contains a pointer
3598 to this same objfile, so it might be a good idea to eliminate it. FIXME).
3601 static struct type
*
3602 read_struct_type (char **pp
, struct type
*type
, enum type_code type_code
,
3603 struct objfile
*objfile
)
3605 struct cleanup
*back_to
;
3606 struct field_info fi
;
3611 /* When describing struct/union/class types in stabs, G++ always drops
3612 all qualifications from the name. So if you've got:
3613 struct A { ... struct B { ... }; ... };
3614 then G++ will emit stabs for `struct A::B' that call it simply
3615 `struct B'. Obviously, if you've got a real top-level definition for
3616 `struct B', or other nested definitions, this is going to cause
3619 Obviously, GDB can't fix this by itself, but it can at least avoid
3620 scribbling on existing structure type objects when new definitions
3622 if (! (TYPE_CODE (type
) == TYPE_CODE_UNDEF
3623 || TYPE_STUB (type
)))
3625 complain_about_struct_wipeout (type
);
3627 /* It's probably best to return the type unchanged. */
3631 back_to
= make_cleanup (null_cleanup
, 0);
3633 INIT_CPLUS_SPECIFIC (type
);
3634 TYPE_CODE (type
) = type_code
;
3635 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3637 /* First comes the total size in bytes. */
3641 TYPE_LENGTH (type
) = read_huge_number (pp
, 0, &nbits
);
3643 return error_type (pp
, objfile
);
3646 /* Now read the baseclasses, if any, read the regular C struct or C++
3647 class member fields, attach the fields to the type, read the C++
3648 member functions, attach them to the type, and then read any tilde
3649 field (baseclass specifier for the class holding the main vtable). */
3651 if (!read_baseclasses (&fi
, pp
, type
, objfile
)
3652 || !read_struct_fields (&fi
, pp
, type
, objfile
)
3653 || !attach_fields_to_type (&fi
, type
, objfile
)
3654 || !read_member_functions (&fi
, pp
, type
, objfile
)
3655 || !attach_fn_fields_to_type (&fi
, type
)
3656 || !read_tilde_fields (&fi
, pp
, type
, objfile
))
3658 type
= error_type (pp
, objfile
);
3661 do_cleanups (back_to
);
3665 /* Read a definition of an array type,
3666 and create and return a suitable type object.
3667 Also creates a range type which represents the bounds of that
3670 static struct type
*
3671 read_array_type (char **pp
, struct type
*type
,
3672 struct objfile
*objfile
)
3674 struct type
*index_type
, *element_type
, *range_type
;
3679 /* Format of an array type:
3680 "ar<index type>;lower;upper;<array_contents_type>".
3681 OS9000: "arlower,upper;<array_contents_type>".
3683 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3684 for these, produce a type like float[][]. */
3687 index_type
= read_type (pp
, objfile
);
3689 /* Improper format of array type decl. */
3690 return error_type (pp
, objfile
);
3694 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3699 lower
= read_huge_number (pp
, ';', &nbits
);
3702 return error_type (pp
, objfile
);
3704 if (!(**pp
>= '0' && **pp
<= '9') && **pp
!= '-')
3709 upper
= read_huge_number (pp
, ';', &nbits
);
3711 return error_type (pp
, objfile
);
3713 element_type
= read_type (pp
, objfile
);
3722 create_range_type ((struct type
*) NULL
, index_type
, lower
, upper
);
3723 type
= create_array_type (type
, element_type
, range_type
);
3729 /* Read a definition of an enumeration type,
3730 and create and return a suitable type object.
3731 Also defines the symbols that represent the values of the type. */
3733 static struct type
*
3734 read_enum_type (char **pp
, struct type
*type
,
3735 struct objfile
*objfile
)
3742 struct pending
**symlist
;
3743 struct pending
*osyms
, *syms
;
3746 int unsigned_enum
= 1;
3749 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3750 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3751 to do? For now, force all enum values to file scope. */
3752 if (within_function
)
3753 symlist
= &local_symbols
;
3756 symlist
= &file_symbols
;
3758 o_nsyms
= osyms
? osyms
->nsyms
: 0;
3760 /* The aix4 compiler emits an extra field before the enum members;
3761 my guess is it's a type of some sort. Just ignore it. */
3764 /* Skip over the type. */
3768 /* Skip over the colon. */
3772 /* Read the value-names and their values.
3773 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3774 A semicolon or comma instead of a NAME means the end. */
3775 while (**pp
&& **pp
!= ';' && **pp
!= ',')
3777 STABS_CONTINUE (pp
, objfile
);
3781 name
= obsavestring (*pp
, p
- *pp
, &objfile
->symbol_obstack
);
3783 n
= read_huge_number (pp
, ',', &nbits
);
3785 return error_type (pp
, objfile
);
3787 sym
= (struct symbol
*)
3788 obstack_alloc (&objfile
->symbol_obstack
, sizeof (struct symbol
));
3789 memset (sym
, 0, sizeof (struct symbol
));
3790 DEPRECATED_SYMBOL_NAME (sym
) = name
;
3791 SYMBOL_LANGUAGE (sym
) = current_subfile
->language
;
3792 SYMBOL_CLASS (sym
) = LOC_CONST
;
3793 SYMBOL_DOMAIN (sym
) = VAR_DOMAIN
;
3794 SYMBOL_VALUE (sym
) = n
;
3797 add_symbol_to_list (sym
, symlist
);
3802 (*pp
)++; /* Skip the semicolon. */
3804 /* Now fill in the fields of the type-structure. */
3806 TYPE_LENGTH (type
) = TARGET_INT_BIT
/ HOST_CHAR_BIT
;
3807 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
3808 TYPE_FLAGS (type
) &= ~TYPE_FLAG_STUB
;
3810 TYPE_FLAGS (type
) |= TYPE_FLAG_UNSIGNED
;
3811 TYPE_NFIELDS (type
) = nsyms
;
3812 TYPE_FIELDS (type
) = (struct field
*)
3813 TYPE_ALLOC (type
, sizeof (struct field
) * nsyms
);
3814 memset (TYPE_FIELDS (type
), 0, sizeof (struct field
) * nsyms
);
3816 /* Find the symbols for the values and put them into the type.
3817 The symbols can be found in the symlist that we put them on
3818 to cause them to be defined. osyms contains the old value
3819 of that symlist; everything up to there was defined by us. */
3820 /* Note that we preserve the order of the enum constants, so
3821 that in something like "enum {FOO, LAST_THING=FOO}" we print
3822 FOO, not LAST_THING. */
3824 for (syms
= *symlist
, n
= nsyms
- 1; syms
; syms
= syms
->next
)
3826 int last
= syms
== osyms
? o_nsyms
: 0;
3827 int j
= syms
->nsyms
;
3828 for (; --j
>= last
; --n
)
3830 struct symbol
*xsym
= syms
->symbol
[j
];
3831 SYMBOL_TYPE (xsym
) = type
;
3832 TYPE_FIELD_NAME (type
, n
) = DEPRECATED_SYMBOL_NAME (xsym
);
3833 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
3834 TYPE_FIELD_BITSIZE (type
, n
) = 0;
3843 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3844 typedefs in every file (for int, long, etc):
3846 type = b <signed> <width> <format type>; <offset>; <nbits>
3848 optional format type = c or b for char or boolean.
3849 offset = offset from high order bit to start bit of type.
3850 width is # bytes in object of this type, nbits is # bits in type.
3852 The width/offset stuff appears to be for small objects stored in
3853 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3856 static struct type
*
3857 read_sun_builtin_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
3862 enum type_code code
= TYPE_CODE_INT
;
3873 return error_type (pp
, objfile
);
3877 /* For some odd reason, all forms of char put a c here. This is strange
3878 because no other type has this honor. We can safely ignore this because
3879 we actually determine 'char'acterness by the number of bits specified in
3881 Boolean forms, e.g Fortran logical*X, put a b here. */
3885 else if (**pp
== 'b')
3887 code
= TYPE_CODE_BOOL
;
3891 /* The first number appears to be the number of bytes occupied
3892 by this type, except that unsigned short is 4 instead of 2.
3893 Since this information is redundant with the third number,
3894 we will ignore it. */
3895 read_huge_number (pp
, ';', &nbits
);
3897 return error_type (pp
, objfile
);
3899 /* The second number is always 0, so ignore it too. */
3900 read_huge_number (pp
, ';', &nbits
);
3902 return error_type (pp
, objfile
);
3904 /* The third number is the number of bits for this type. */
3905 type_bits
= read_huge_number (pp
, 0, &nbits
);
3907 return error_type (pp
, objfile
);
3908 /* The type *should* end with a semicolon. If it are embedded
3909 in a larger type the semicolon may be the only way to know where
3910 the type ends. If this type is at the end of the stabstring we
3911 can deal with the omitted semicolon (but we don't have to like
3912 it). Don't bother to complain(), Sun's compiler omits the semicolon
3918 return init_type (TYPE_CODE_VOID
, 1,
3919 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
3922 return init_type (code
,
3923 type_bits
/ TARGET_CHAR_BIT
,
3924 signed_type
? 0 : TYPE_FLAG_UNSIGNED
, (char *) NULL
,
3928 static struct type
*
3929 read_sun_floating_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
3934 struct type
*rettype
;
3936 /* The first number has more details about the type, for example
3938 details
= read_huge_number (pp
, ';', &nbits
);
3940 return error_type (pp
, objfile
);
3942 /* The second number is the number of bytes occupied by this type */
3943 nbytes
= read_huge_number (pp
, ';', &nbits
);
3945 return error_type (pp
, objfile
);
3947 if (details
== NF_COMPLEX
|| details
== NF_COMPLEX16
3948 || details
== NF_COMPLEX32
)
3950 rettype
= init_type (TYPE_CODE_COMPLEX
, nbytes
, 0, NULL
, objfile
);
3951 TYPE_TARGET_TYPE (rettype
)
3952 = init_type (TYPE_CODE_FLT
, nbytes
/ 2, 0, NULL
, objfile
);
3956 return init_type (TYPE_CODE_FLT
, nbytes
, 0, NULL
, objfile
);
3959 /* Read a number from the string pointed to by *PP.
3960 The value of *PP is advanced over the number.
3961 If END is nonzero, the character that ends the
3962 number must match END, or an error happens;
3963 and that character is skipped if it does match.
3964 If END is zero, *PP is left pointing to that character.
3966 If the number fits in a long, set *BITS to 0 and return the value.
3967 If not, set *BITS to be the number of bits in the number and return 0.
3969 If encounter garbage, set *BITS to -1 and return 0. */
3972 read_huge_number (char **pp
, int end
, int *bits
)
3989 /* Leading zero means octal. GCC uses this to output values larger
3990 than an int (because that would be hard in decimal). */
3997 upper_limit
= LONG_MAX
/ radix
;
3999 while ((c
= *p
++) >= '0' && c
< ('0' + radix
))
4001 if (n
<= upper_limit
)
4004 n
+= c
- '0'; /* FIXME this overflows anyway */
4009 /* This depends on large values being output in octal, which is
4016 /* Ignore leading zeroes. */
4020 else if (c
== '2' || c
== '3')
4046 /* Large decimal constants are an error (because it is hard to
4047 count how many bits are in them). */
4053 /* -0x7f is the same as 0x80. So deal with it by adding one to
4054 the number of bits. */
4066 /* It's *BITS which has the interesting information. */
4070 static struct type
*
4071 read_range_type (char **pp
, int typenums
[2], struct objfile
*objfile
)
4073 char *orig_pp
= *pp
;
4078 struct type
*result_type
;
4079 struct type
*index_type
= NULL
;
4081 /* First comes a type we are a subrange of.
4082 In C it is usually 0, 1 or the type being defined. */
4083 if (read_type_number (pp
, rangenums
) != 0)
4084 return error_type (pp
, objfile
);
4085 self_subrange
= (rangenums
[0] == typenums
[0] &&
4086 rangenums
[1] == typenums
[1]);
4091 index_type
= read_type (pp
, objfile
);
4094 /* A semicolon should now follow; skip it. */
4098 /* The remaining two operands are usually lower and upper bounds
4099 of the range. But in some special cases they mean something else. */
4100 n2
= read_huge_number (pp
, ';', &n2bits
);
4101 n3
= read_huge_number (pp
, ';', &n3bits
);
4103 if (n2bits
== -1 || n3bits
== -1)
4104 return error_type (pp
, objfile
);
4107 goto handle_true_range
;
4109 /* If limits are huge, must be large integral type. */
4110 if (n2bits
!= 0 || n3bits
!= 0)
4112 char got_signed
= 0;
4113 char got_unsigned
= 0;
4114 /* Number of bits in the type. */
4117 /* Range from 0 to <large number> is an unsigned large integral type. */
4118 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
4123 /* Range from <large number> to <large number>-1 is a large signed
4124 integral type. Take care of the case where <large number> doesn't
4125 fit in a long but <large number>-1 does. */
4126 else if ((n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
4127 || (n2bits
!= 0 && n3bits
== 0
4128 && (n2bits
== sizeof (long) * HOST_CHAR_BIT
)
4135 if (got_signed
|| got_unsigned
)
4137 return init_type (TYPE_CODE_INT
, nbits
/ TARGET_CHAR_BIT
,
4138 got_unsigned
? TYPE_FLAG_UNSIGNED
: 0, NULL
,
4142 return error_type (pp
, objfile
);
4145 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4146 if (self_subrange
&& n2
== 0 && n3
== 0)
4147 return init_type (TYPE_CODE_VOID
, 1, 0, NULL
, objfile
);
4149 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4150 is the width in bytes.
4152 Fortran programs appear to use this for complex types also. To
4153 distinguish between floats and complex, g77 (and others?) seem
4154 to use self-subranges for the complexes, and subranges of int for
4157 Also note that for complexes, g77 sets n2 to the size of one of
4158 the member floats, not the whole complex beast. My guess is that
4159 this was to work well with pre-COMPLEX versions of gdb. */
4161 if (n3
== 0 && n2
> 0)
4163 struct type
*float_type
4164 = init_type (TYPE_CODE_FLT
, n2
, 0, NULL
, objfile
);
4168 struct type
*complex_type
=
4169 init_type (TYPE_CODE_COMPLEX
, 2 * n2
, 0, NULL
, objfile
);
4170 TYPE_TARGET_TYPE (complex_type
) = float_type
;
4171 return complex_type
;
4177 /* If the upper bound is -1, it must really be an unsigned int. */
4179 else if (n2
== 0 && n3
== -1)
4181 /* It is unsigned int or unsigned long. */
4182 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4183 compatibility hack. */
4184 return init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4185 TYPE_FLAG_UNSIGNED
, NULL
, objfile
);
4188 /* Special case: char is defined (Who knows why) as a subrange of
4189 itself with range 0-127. */
4190 else if (self_subrange
&& n2
== 0 && n3
== 127)
4191 return init_type (TYPE_CODE_INT
, 1, TYPE_FLAG_NOSIGN
, NULL
, objfile
);
4193 /* We used to do this only for subrange of self or subrange of int. */
4196 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4197 "unsigned long", and we already checked for that,
4198 so don't need to test for it here. */
4201 /* n3 actually gives the size. */
4202 return init_type (TYPE_CODE_INT
, -n3
, TYPE_FLAG_UNSIGNED
,
4205 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
4206 unsigned n-byte integer. But do require n to be a power of
4207 two; we don't want 3- and 5-byte integers flying around. */
4213 for (bytes
= 0; (bits
& 0xff) == 0xff; bytes
++)
4216 && ((bytes
- 1) & bytes
) == 0) /* "bytes is a power of two" */
4217 return init_type (TYPE_CODE_INT
, bytes
, TYPE_FLAG_UNSIGNED
, NULL
,
4221 /* I think this is for Convex "long long". Since I don't know whether
4222 Convex sets self_subrange, I also accept that particular size regardless
4223 of self_subrange. */
4224 else if (n3
== 0 && n2
< 0
4226 || n2
== -TARGET_LONG_LONG_BIT
/ TARGET_CHAR_BIT
))
4227 return init_type (TYPE_CODE_INT
, -n2
, 0, NULL
, objfile
);
4228 else if (n2
== -n3
- 1)
4231 return init_type (TYPE_CODE_INT
, 1, 0, NULL
, objfile
);
4233 return init_type (TYPE_CODE_INT
, 2, 0, NULL
, objfile
);
4234 if (n3
== 0x7fffffff)
4235 return init_type (TYPE_CODE_INT
, 4, 0, NULL
, objfile
);
4238 /* We have a real range type on our hands. Allocate space and
4239 return a real pointer. */
4243 index_type
= builtin_type_int
;
4245 index_type
= *dbx_lookup_type (rangenums
);
4246 if (index_type
== NULL
)
4248 /* Does this actually ever happen? Is that why we are worrying
4249 about dealing with it rather than just calling error_type? */
4251 static struct type
*range_type_index
;
4253 complaint (&symfile_complaints
,
4254 "base type %d of range type is not defined", rangenums
[1]);
4255 if (range_type_index
== NULL
)
4257 init_type (TYPE_CODE_INT
, TARGET_INT_BIT
/ TARGET_CHAR_BIT
,
4258 0, "range type index type", NULL
);
4259 index_type
= range_type_index
;
4262 result_type
= create_range_type ((struct type
*) NULL
, index_type
, n2
, n3
);
4263 return (result_type
);
4266 /* Read in an argument list. This is a list of types, separated by commas
4267 and terminated with END. Return the list of types read in, or (struct type
4268 **)-1 if there is an error. */
4270 static struct field
*
4271 read_args (char **pp
, int end
, struct objfile
*objfile
, int *nargsp
,
4274 /* FIXME! Remove this arbitrary limit! */
4275 struct type
*types
[1024]; /* allow for fns of 1023 parameters */
4282 /* Invalid argument list: no ','. */
4283 return (struct field
*) -1;
4285 STABS_CONTINUE (pp
, objfile
);
4286 types
[n
++] = read_type (pp
, objfile
);
4288 (*pp
)++; /* get past `end' (the ':' character) */
4290 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
->symbol_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
->symbol_obstack
, sizeof (struct symbol
));
4363 memset (sym
, 0, sizeof (struct symbol
));
4364 /* Note: common_block_name already saved on symbol_obstack */
4365 DEPRECATED_SYMBOL_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 (DEPRECATED_SYMBOL_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
);
4406 for (; next
; next
= next
->next
)
4409 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
4410 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
4416 /* What about types defined as forward references inside of a small lexical
4418 /* Add a type to the list of undefined types to be checked through
4419 once this file has been read in. */
4422 add_undefined_type (struct type
*type
)
4424 if (undef_types_length
== undef_types_allocated
)
4426 undef_types_allocated
*= 2;
4427 undef_types
= (struct type
**)
4428 xrealloc ((char *) undef_types
,
4429 undef_types_allocated
* sizeof (struct type
*));
4431 undef_types
[undef_types_length
++] = type
;
4434 /* Go through each undefined type, see if it's still undefined, and fix it
4435 up if possible. We have two kinds of undefined types:
4437 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4438 Fix: update array length using the element bounds
4439 and the target type's length.
4440 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4441 yet defined at the time a pointer to it was made.
4442 Fix: Do a full lookup on the struct/union tag. */
4444 cleanup_undefined_types (void)
4448 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
4450 switch (TYPE_CODE (*type
))
4453 case TYPE_CODE_STRUCT
:
4454 case TYPE_CODE_UNION
:
4455 case TYPE_CODE_ENUM
:
4457 /* Check if it has been defined since. Need to do this here
4458 as well as in check_typedef to deal with the (legitimate in
4459 C though not C++) case of several types with the same name
4460 in different source files. */
4461 if (TYPE_STUB (*type
))
4463 struct pending
*ppt
;
4465 /* Name of the type, without "struct" or "union" */
4466 char *typename
= TYPE_TAG_NAME (*type
);
4468 if (typename
== NULL
)
4470 complaint (&symfile_complaints
, "need a type name");
4473 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
4475 for (i
= 0; i
< ppt
->nsyms
; i
++)
4477 struct symbol
*sym
= ppt
->symbol
[i
];
4479 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
4480 && SYMBOL_DOMAIN (sym
) == STRUCT_DOMAIN
4481 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
4483 && STREQ (DEPRECATED_SYMBOL_NAME (sym
), typename
))
4484 replace_type (*type
, SYMBOL_TYPE (sym
));
4493 complaint (&symfile_complaints
,
4494 "GDB internal error. cleanup_undefined_types with bad type %d.",
4501 undef_types_length
= 0;
4504 /* Scan through all of the global symbols defined in the object file,
4505 assigning values to the debugging symbols that need to be assigned
4506 to. Get these symbols from the minimal symbol table. */
4509 scan_file_globals (struct objfile
*objfile
)
4512 struct minimal_symbol
*msymbol
;
4513 struct symbol
*sym
, *prev
, *rsym
;
4514 struct objfile
*resolve_objfile
;
4516 /* SVR4 based linkers copy referenced global symbols from shared
4517 libraries to the main executable.
4518 If we are scanning the symbols for a shared library, try to resolve
4519 them from the minimal symbols of the main executable first. */
4521 if (symfile_objfile
&& objfile
!= symfile_objfile
)
4522 resolve_objfile
= symfile_objfile
;
4524 resolve_objfile
= objfile
;
4528 /* Avoid expensive loop through all minimal symbols if there are
4529 no unresolved symbols. */
4530 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4532 if (global_sym_chain
[hash
])
4535 if (hash
>= HASHSIZE
)
4538 for (msymbol
= resolve_objfile
->msymbols
;
4539 msymbol
&& DEPRECATED_SYMBOL_NAME (msymbol
) != NULL
;
4544 /* Skip static symbols. */
4545 switch (MSYMBOL_TYPE (msymbol
))
4557 /* Get the hash index and check all the symbols
4558 under that hash index. */
4560 hash
= hashname (DEPRECATED_SYMBOL_NAME (msymbol
));
4562 for (sym
= global_sym_chain
[hash
]; sym
;)
4564 if (DEPRECATED_SYMBOL_NAME (msymbol
)[0] == DEPRECATED_SYMBOL_NAME (sym
)[0] &&
4565 STREQ (DEPRECATED_SYMBOL_NAME (msymbol
) + 1, DEPRECATED_SYMBOL_NAME (sym
) + 1))
4568 struct alias_list
*aliases
;
4570 /* Splice this symbol out of the hash chain and
4571 assign the value we have to it. */
4574 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
4578 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
4581 /* Check to see whether we need to fix up a common block. */
4582 /* Note: this code might be executed several times for
4583 the same symbol if there are multiple references. */
4585 /* If symbol has aliases, do minimal symbol fixups for each.
4586 These live aliases/references weren't added to
4587 global_sym_chain hash but may also need to be fixed up. */
4588 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
4589 symbols? Still, we wouldn't want to add_to_list. */
4590 /* Now do the same for each alias of this symbol */
4592 aliases
= SYMBOL_ALIASES (sym
);
4595 if (SYMBOL_CLASS (rsym
) == LOC_BLOCK
)
4597 fix_common_block (rsym
,
4598 SYMBOL_VALUE_ADDRESS (msymbol
));
4602 SYMBOL_VALUE_ADDRESS (rsym
)
4603 = SYMBOL_VALUE_ADDRESS (msymbol
);
4605 SYMBOL_SECTION (rsym
) = SYMBOL_SECTION (msymbol
);
4608 rsym
= aliases
->sym
;
4609 aliases
= aliases
->next
;
4618 sym
= SYMBOL_VALUE_CHAIN (prev
);
4622 sym
= global_sym_chain
[hash
];
4628 sym
= SYMBOL_VALUE_CHAIN (sym
);
4632 if (resolve_objfile
== objfile
)
4634 resolve_objfile
= objfile
;
4637 /* Change the storage class of any remaining unresolved globals to
4638 LOC_UNRESOLVED and remove them from the chain. */
4639 for (hash
= 0; hash
< HASHSIZE
; hash
++)
4641 sym
= global_sym_chain
[hash
];
4645 sym
= SYMBOL_VALUE_CHAIN (sym
);
4647 /* Change the symbol address from the misleading chain value
4649 SYMBOL_VALUE_ADDRESS (prev
) = 0;
4651 /* Complain about unresolved common block symbols. */
4652 if (SYMBOL_CLASS (prev
) == LOC_STATIC
)
4653 SYMBOL_CLASS (prev
) = LOC_UNRESOLVED
;
4655 complaint (&symfile_complaints
,
4656 "%s: common block `%s' from global_sym_chain unresolved",
4657 objfile
->name
, DEPRECATED_SYMBOL_NAME (prev
));
4660 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4663 /* Initialize anything that needs initializing when starting to read
4664 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4668 stabsread_init (void)
4672 /* Initialize anything that needs initializing when a completely new
4673 symbol file is specified (not just adding some symbols from another
4674 file, e.g. a shared library). */
4677 stabsread_new_init (void)
4679 /* Empty the hash table of global syms looking for values. */
4680 memset (global_sym_chain
, 0, sizeof (global_sym_chain
));
4683 /* Initialize anything that needs initializing at the same time as
4684 start_symtab() is called. */
4689 global_stabs
= NULL
; /* AIX COFF */
4690 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4691 n_this_object_header_files
= 1;
4692 type_vector_length
= 0;
4693 type_vector
= (struct type
**) 0;
4695 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4696 common_block_name
= NULL
;
4699 /* Call after end_symtab() */
4706 xfree (type_vector
);
4709 type_vector_length
= 0;
4710 previous_stab_code
= 0;
4714 finish_global_stabs (struct objfile
*objfile
)
4718 patch_block_stabs (global_symbols
, global_stabs
, objfile
);
4719 xfree (global_stabs
);
4720 global_stabs
= NULL
;
4724 /* Find the end of the name, delimited by a ':', but don't match
4725 ObjC symbols which look like -[Foo bar::]:bla. */
4727 find_name_end (char *name
)
4730 if (s
[0] == '-' || *s
== '+')
4732 /* Must be an ObjC method symbol. */
4735 error ("invalid symbol name \"%s\"", name
);
4737 s
= strchr (s
, ']');
4740 error ("invalid symbol name \"%s\"", name
);
4742 return strchr (s
, ':');
4746 return strchr (s
, ':');
4750 /* Initializer for this module */
4753 _initialize_stabsread (void)
4755 undef_types_allocated
= 20;
4756 undef_types_length
= 0;
4757 undef_types
= (struct type
**)
4758 xmalloc (undef_types_allocated
* sizeof (struct type
*));