1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996
3 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 /* Support routines for reading and decoding debugging information in
22 the "stabs" format. This format is used with many systems that use
23 the a.out object file format, as well as some systems that use
24 COFF or ELF where the stabs data is placed in a special section.
25 Avoid placing any object file format specific code in this file. */
28 #include "gdb_string.h"
33 #include "expression.h"
36 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
38 #include "aout/aout64.h"
39 #include "gdb-stabs.h"
41 #include "complaints.h"
47 /* Ask stabsread.h to define the vars it normally declares `extern'. */
49 #include "stabsread.h" /* Our own declarations */
52 /* The routines that read and process a complete stabs for a C struct or
53 C++ class pass lists of data member fields and lists of member function
54 fields in an instance of a field_info structure, as defined below.
55 This is part of some reorganization of low level C++ support and is
56 expected to eventually go away... (FIXME) */
62 struct nextfield *next;
64 /* This is the raw visibility from the stab. It is not checked
65 for being one of the visibilities we recognize, so code which
66 examines this field better be able to deal. */
71 struct next_fnfieldlist
73 struct next_fnfieldlist *next;
74 struct fn_fieldlist fn_fieldlist;
79 dbx_alloc_type PARAMS ((int [2], struct objfile *));
81 static long read_huge_number PARAMS ((char **, int, int *));
83 static struct type *error_type PARAMS ((char **, struct objfile *));
86 patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
90 fix_common_block PARAMS ((struct symbol *, int));
93 read_type_number PARAMS ((char **, int *));
96 read_range_type PARAMS ((char **, int [2], struct objfile *));
99 read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *));
102 read_sun_floating_type PARAMS ((char **, int [2], struct objfile *));
105 read_enum_type PARAMS ((char **, struct type *, struct objfile *));
108 rs6000_builtin_type PARAMS ((int));
111 read_member_functions PARAMS ((struct field_info *, char **, struct type *,
115 read_struct_fields PARAMS ((struct field_info *, char **, struct type *,
119 read_baseclasses PARAMS ((struct field_info *, char **, struct type *,
123 read_tilde_fields PARAMS ((struct field_info *, char **, struct type *,
127 attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *));
130 attach_fields_to_type PARAMS ((struct field_info *, struct type *,
134 read_struct_type PARAMS ((char **, struct type *, struct objfile *));
137 read_array_type PARAMS ((char **, struct type *, struct objfile *));
139 static struct type **
140 read_args PARAMS ((char **, int, struct objfile *));
143 read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *,
146 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
147 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
149 /* Define this as 1 if a pcc declaration of a char or short argument
150 gives the correct address. Otherwise assume pcc gives the
151 address of the corresponding int, which is not the same on a
152 big-endian machine. */
154 #ifndef BELIEVE_PCC_PROMOTION
155 #define BELIEVE_PCC_PROMOTION 0
158 struct complaint invalid_cpp_abbrev_complaint =
159 {"invalid C++ abbreviation `%s'", 0, 0};
161 struct complaint invalid_cpp_type_complaint =
162 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
164 struct complaint member_fn_complaint =
165 {"member function type missing, got '%c'", 0, 0};
167 struct complaint const_vol_complaint =
168 {"const/volatile indicator missing, got '%c'", 0, 0};
170 struct complaint error_type_complaint =
171 {"debug info mismatch between compiler and debugger", 0, 0};
173 struct complaint invalid_member_complaint =
174 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
176 struct complaint range_type_base_complaint =
177 {"base type %d of range type is not defined", 0, 0};
179 struct complaint reg_value_complaint =
180 {"register number %d too large (max %d) in symbol %s", 0, 0};
182 struct complaint vtbl_notfound_complaint =
183 {"virtual function table pointer not found when defining class `%s'", 0, 0};
185 struct complaint unrecognized_cplus_name_complaint =
186 {"Unknown C++ symbol name `%s'", 0, 0};
188 struct complaint rs6000_builtin_complaint =
189 {"Unknown builtin type %d", 0, 0};
191 struct complaint unresolved_sym_chain_complaint =
192 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
194 struct complaint stabs_general_complaint =
197 /* Make a list of forward references which haven't been defined. */
199 static struct type **undef_types;
200 static int undef_types_allocated;
201 static int undef_types_length;
202 static struct symbol *current_symbol = NULL;
204 /* Check for and handle cretinous stabs symbol name continuation! */
205 #define STABS_CONTINUE(pp,objfile) \
207 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
208 *(pp) = next_symbol_text (objfile); \
211 /* FIXME: These probably should be our own types (like rs6000_builtin_type
212 has its own types) rather than builtin_type_*. */
213 static struct type **os9k_type_vector[] = {
219 &builtin_type_unsigned_char,
220 &builtin_type_unsigned_short,
221 &builtin_type_unsigned_long,
222 &builtin_type_unsigned_int,
224 &builtin_type_double,
226 &builtin_type_long_double
229 static void os9k_init_type_vector PARAMS ((struct type **));
232 os9k_init_type_vector(tv)
236 for (i=0; i<sizeof(os9k_type_vector)/sizeof(struct type **); i++)
237 tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
240 /* Look up a dbx type-number pair. Return the address of the slot
241 where the type for that number-pair is stored.
242 The number-pair is in TYPENUMS.
244 This can be used for finding the type associated with that pair
245 or for associating a new type with the pair. */
248 dbx_lookup_type (typenums)
251 register int filenum = typenums[0];
252 register int index = typenums[1];
254 register int real_filenum;
255 register struct header_file *f;
258 if (filenum == -1) /* -1,-1 is for temporary types. */
261 if (filenum < 0 || filenum >= n_this_object_header_files)
263 static struct complaint msg = {"\
264 Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
266 complain (&msg, filenum, index, symnum);
274 /* Caller wants address of address of type. We think
275 that negative (rs6k builtin) types will never appear as
276 "lvalues", (nor should they), so we stuff the real type
277 pointer into a temp, and return its address. If referenced,
278 this will do the right thing. */
279 static struct type *temp_type;
281 temp_type = rs6000_builtin_type(index);
285 /* Type is defined outside of header files.
286 Find it in this object file's type vector. */
287 if (index >= type_vector_length)
289 old_len = type_vector_length;
292 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
293 type_vector = (struct type **)
294 xmalloc (type_vector_length * sizeof (struct type *));
296 while (index >= type_vector_length)
298 type_vector_length *= 2;
300 type_vector = (struct type **)
301 xrealloc ((char *) type_vector,
302 (type_vector_length * sizeof (struct type *)));
303 memset (&type_vector[old_len], 0,
304 (type_vector_length - old_len) * sizeof (struct type *));
307 /* Deal with OS9000 fundamental types. */
308 os9k_init_type_vector (type_vector);
310 return (&type_vector[index]);
314 real_filenum = this_object_header_files[filenum];
316 if (real_filenum >= n_header_files)
318 struct type *temp_type;
319 struct type **temp_type_p;
321 warning ("GDB internal error: bad real_filenum");
324 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
325 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
326 *temp_type_p = temp_type;
330 f = &header_files[real_filenum];
332 f_orig_length = f->length;
333 if (index >= f_orig_length)
335 while (index >= f->length)
339 f->vector = (struct type **)
340 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
341 memset (&f->vector[f_orig_length], 0,
342 (f->length - f_orig_length) * sizeof (struct type *));
344 return (&f->vector[index]);
348 /* Make sure there is a type allocated for type numbers TYPENUMS
349 and return the type object.
350 This can create an empty (zeroed) type object.
351 TYPENUMS may be (-1, -1) to return a new type object that is not
352 put into the type vector, and so may not be referred to by number. */
355 dbx_alloc_type (typenums, objfile)
357 struct objfile *objfile;
359 register struct type **type_addr;
361 if (typenums[0] == -1)
363 return (alloc_type (objfile));
366 type_addr = dbx_lookup_type (typenums);
368 /* If we are referring to a type not known at all yet,
369 allocate an empty type for it.
370 We will fill it in later if we find out how. */
373 *type_addr = alloc_type (objfile);
379 /* for all the stabs in a given stab vector, build appropriate types
380 and fix their symbols in given symbol vector. */
383 patch_block_stabs (symbols, stabs, objfile)
384 struct pending *symbols;
385 struct pending_stabs *stabs;
386 struct objfile *objfile;
396 /* for all the stab entries, find their corresponding symbols and
397 patch their types! */
399 for (ii = 0; ii < stabs->count; ++ii)
401 name = stabs->stab[ii];
402 pp = (char*) strchr (name, ':');
406 pp = (char *)strchr(pp, ':');
408 sym = find_symbol_in_list (symbols, name, pp-name);
411 /* FIXME-maybe: it would be nice if we noticed whether
412 the variable was defined *anywhere*, not just whether
413 it is defined in this compilation unit. But neither
414 xlc or GCC seem to need such a definition, and until
415 we do psymtabs (so that the minimal symbols from all
416 compilation units are available now), I'm not sure
417 how to get the information. */
419 /* On xcoff, if a global is defined and never referenced,
420 ld will remove it from the executable. There is then
421 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
422 sym = (struct symbol *)
423 obstack_alloc (&objfile->symbol_obstack,
424 sizeof (struct symbol));
426 memset (sym, 0, sizeof (struct symbol));
427 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
428 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
430 obstack_copy0 (&objfile->symbol_obstack, name, pp - name);
432 if (*(pp-1) == 'F' || *(pp-1) == 'f')
434 /* I don't think the linker does this with functions,
435 so as far as I know this is never executed.
436 But it doesn't hurt to check. */
438 lookup_function_type (read_type (&pp, objfile));
442 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
444 add_symbol_to_list (sym, &global_symbols);
449 if (*(pp-1) == 'F' || *(pp-1) == 'f')
452 lookup_function_type (read_type (&pp, objfile));
456 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
464 /* Read a number by which a type is referred to in dbx data,
465 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
466 Just a single number N is equivalent to (0,N).
467 Return the two numbers by storing them in the vector TYPENUMS.
468 TYPENUMS will then be used as an argument to dbx_lookup_type.
470 Returns 0 for success, -1 for error. */
473 read_type_number (pp, typenums)
475 register int *typenums;
481 typenums[0] = read_huge_number (pp, ',', &nbits);
482 if (nbits != 0) return -1;
483 typenums[1] = read_huge_number (pp, ')', &nbits);
484 if (nbits != 0) return -1;
489 typenums[1] = read_huge_number (pp, 0, &nbits);
490 if (nbits != 0) return -1;
496 #if !defined (REG_STRUCT_HAS_ADDR)
497 #define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
502 define_symbol (valu, string, desc, type, objfile)
507 struct objfile *objfile;
509 register struct symbol *sym;
510 char *p = (char *) strchr (string, ':');
515 /* We would like to eliminate nameless symbols, but keep their types.
516 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
517 to type 2, but, should not create a symbol to address that type. Since
518 the symbol will be nameless, there is no way any user can refer to it. */
522 /* Ignore syms with empty names. */
526 /* Ignore old-style symbols from cc -go */
536 /* If a nameless stab entry, all we need is the type, not the symbol.
537 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
538 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
540 current_symbol = sym = (struct symbol *)
541 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
542 memset (sym, 0, sizeof (struct symbol));
544 switch (type & N_TYPE)
547 SYMBOL_SECTION(sym) = SECT_OFF_TEXT;
550 SYMBOL_SECTION(sym) = SECT_OFF_DATA;
553 SYMBOL_SECTION(sym) = SECT_OFF_BSS;
557 if (processing_gcc_compilation)
559 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
560 number of bytes occupied by a type or object, which we ignore. */
561 SYMBOL_LINE(sym) = desc;
565 SYMBOL_LINE(sym) = 0; /* unknown */
568 if (is_cplus_marker (string[0]))
570 /* Special GNU C++ names. */
574 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
575 &objfile -> symbol_obstack);
578 case 'v': /* $vtbl_ptr_type */
579 /* Was: SYMBOL_NAME (sym) = "vptr"; */
583 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
584 &objfile -> symbol_obstack);
588 /* This was an anonymous type that was never fixed up. */
591 #ifdef STATIC_TRANSFORM_NAME
593 /* SunPRO (3.0 at least) static variable encoding. */
598 complain (&unrecognized_cplus_name_complaint, string);
599 goto normal; /* Do *something* with it */
605 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
606 SYMBOL_NAME (sym) = (char *)
607 obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
608 /* Open-coded memcpy--saves function call time. */
609 /* FIXME: Does it really? Try replacing with simple strcpy and
610 try it on an executable with a large symbol table. */
611 /* FIXME: considering that gcc can open code memcpy anyway, I
612 doubt it. xoxorich. */
614 register char *p1 = string;
615 register char *p2 = SYMBOL_NAME (sym);
623 /* If this symbol is from a C++ compilation, then attempt to cache the
624 demangled form for future reference. This is a typical time versus
625 space tradeoff, that was decided in favor of time because it sped up
626 C++ symbol lookups by a factor of about 20. */
628 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
632 /* Determine the type of name being defined. */
634 /* Getting GDB to correctly skip the symbol on an undefined symbol
635 descriptor and not ever dump core is a very dodgy proposition if
636 we do things this way. I say the acorn RISC machine can just
637 fix their compiler. */
638 /* The Acorn RISC machine's compiler can put out locals that don't
639 start with "234=" or "(3,4)=", so assume anything other than the
640 deftypes we know how to handle is a local. */
641 if (!strchr ("cfFGpPrStTvVXCR", *p))
643 if (isdigit (*p) || *p == '(' || *p == '-')
652 /* c is a special case, not followed by a type-number.
653 SYMBOL:c=iVALUE for an integer constant symbol.
654 SYMBOL:c=rVALUE for a floating constant symbol.
655 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
656 e.g. "b:c=e6,0" for "const b = blob1"
657 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
660 SYMBOL_CLASS (sym) = LOC_CONST;
661 SYMBOL_TYPE (sym) = error_type (&p, objfile);
662 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
663 add_symbol_to_list (sym, &file_symbols);
674 /* FIXME-if-picky-about-floating-accuracy: Should be using
675 target arithmetic to get the value. real.c in GCC
676 probably has the necessary code. */
678 /* FIXME: lookup_fundamental_type is a hack. We should be
679 creating a type especially for the type of float constants.
680 Problem is, what type should it be?
682 Also, what should the name of this type be? Should we
683 be using 'S' constants (see stabs.texinfo) instead? */
685 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
688 obstack_alloc (&objfile -> symbol_obstack,
689 TYPE_LENGTH (SYMBOL_TYPE (sym)));
690 store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d);
691 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
692 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
697 /* Defining integer constants this way is kind of silly,
698 since 'e' constants allows the compiler to give not
699 only the value, but the type as well. C has at least
700 int, long, unsigned int, and long long as constant
701 types; other languages probably should have at least
702 unsigned as well as signed constants. */
704 /* We just need one int constant type for all objfiles.
705 It doesn't depend on languages or anything (arguably its
706 name should be a language-specific name for a type of
707 that size, but I'm inclined to say that if the compiler
708 wants a nice name for the type, it can use 'e'). */
709 static struct type *int_const_type;
711 /* Yes, this is as long as a *host* int. That is because we
713 if (int_const_type == NULL)
715 init_type (TYPE_CODE_INT,
716 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
718 (struct objfile *)NULL);
719 SYMBOL_TYPE (sym) = int_const_type;
720 SYMBOL_VALUE (sym) = atoi (p);
721 SYMBOL_CLASS (sym) = LOC_CONST;
725 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
726 can be represented as integral.
727 e.g. "b:c=e6,0" for "const b = blob1"
728 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
730 SYMBOL_CLASS (sym) = LOC_CONST;
731 SYMBOL_TYPE (sym) = read_type (&p, objfile);
735 SYMBOL_TYPE (sym) = error_type (&p, objfile);
740 /* If the value is too big to fit in an int (perhaps because
741 it is unsigned), or something like that, we silently get
742 a bogus value. The type and everything else about it is
743 correct. Ideally, we should be using whatever we have
744 available for parsing unsigned and long long values,
746 SYMBOL_VALUE (sym) = atoi (p);
751 SYMBOL_CLASS (sym) = LOC_CONST;
752 SYMBOL_TYPE (sym) = error_type (&p, objfile);
755 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
756 add_symbol_to_list (sym, &file_symbols);
760 /* The name of a caught exception. */
761 SYMBOL_TYPE (sym) = read_type (&p, objfile);
762 SYMBOL_CLASS (sym) = LOC_LABEL;
763 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
764 SYMBOL_VALUE_ADDRESS (sym) = valu;
765 add_symbol_to_list (sym, &local_symbols);
769 /* A static function definition. */
770 SYMBOL_TYPE (sym) = read_type (&p, objfile);
771 SYMBOL_CLASS (sym) = LOC_BLOCK;
772 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
773 add_symbol_to_list (sym, &file_symbols);
774 /* fall into process_function_types. */
776 process_function_types:
777 /* Function result types are described as the result type in stabs.
778 We need to convert this to the function-returning-type-X type
779 in GDB. E.g. "int" is converted to "function returning int". */
780 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
781 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
782 /* fall into process_prototype_types */
784 process_prototype_types:
785 /* Sun acc puts declared types of arguments here. We don't care
786 about their actual types (FIXME -- we should remember the whole
787 function prototype), but the list may define some new types
788 that we have to remember, so we must scan it now. */
791 read_type (&p, objfile);
796 /* A global function definition. */
797 SYMBOL_TYPE (sym) = read_type (&p, objfile);
798 SYMBOL_CLASS (sym) = LOC_BLOCK;
799 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
800 add_symbol_to_list (sym, &global_symbols);
801 goto process_function_types;
804 /* For a class G (global) symbol, it appears that the
805 value is not correct. It is necessary to search for the
806 corresponding linker definition to find the value.
807 These definitions appear at the end of the namelist. */
808 SYMBOL_TYPE (sym) = read_type (&p, objfile);
809 i = hashname (SYMBOL_NAME (sym));
810 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
811 global_sym_chain[i] = sym;
812 SYMBOL_CLASS (sym) = LOC_STATIC;
813 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
814 add_symbol_to_list (sym, &global_symbols);
817 /* This case is faked by a conditional above,
818 when there is no code letter in the dbx data.
819 Dbx data never actually contains 'l'. */
822 SYMBOL_TYPE (sym) = read_type (&p, objfile);
823 SYMBOL_CLASS (sym) = LOC_LOCAL;
824 SYMBOL_VALUE (sym) = valu;
825 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
826 add_symbol_to_list (sym, &local_symbols);
831 /* pF is a two-letter code that means a function parameter in Fortran.
832 The type-number specifies the type of the return value.
833 Translate it into a pointer-to-function type. */
837 = lookup_pointer_type
838 (lookup_function_type (read_type (&p, objfile)));
841 SYMBOL_TYPE (sym) = read_type (&p, objfile);
843 /* Normally this is a parameter, a LOC_ARG. On the i960, it
844 can also be a LOC_LOCAL_ARG depending on symbol type. */
845 #ifndef DBX_PARM_SYMBOL_CLASS
846 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
849 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
850 SYMBOL_VALUE (sym) = valu;
851 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
852 add_symbol_to_list (sym, &local_symbols);
854 if (TARGET_BYTE_ORDER != BIG_ENDIAN)
856 /* On little-endian machines, this crud is never necessary,
857 and, if the extra bytes contain garbage, is harmful. */
861 /* If it's gcc-compiled, if it says `short', believe it. */
862 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
865 #if !BELIEVE_PCC_PROMOTION
867 /* This is the signed type which arguments get promoted to. */
868 static struct type *pcc_promotion_type;
869 /* This is the unsigned type which arguments get promoted to. */
870 static struct type *pcc_unsigned_promotion_type;
872 /* Call it "int" because this is mainly C lossage. */
873 if (pcc_promotion_type == NULL)
875 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
878 if (pcc_unsigned_promotion_type == NULL)
879 pcc_unsigned_promotion_type =
880 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
881 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
883 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
884 /* This macro is defined on machines (e.g. sparc) where
885 we should believe the type of a PCC 'short' argument,
886 but shouldn't believe the address (the address is
887 the address of the corresponding int).
889 My guess is that this correction, as opposed to changing
890 the parameter to an 'int' (as done below, for PCC
891 on most machines), is the right thing to do
892 on all machines, but I don't want to risk breaking
893 something that already works. On most PCC machines,
894 the sparc problem doesn't come up because the calling
895 function has to zero the top bytes (not knowing whether
896 the called function wants an int or a short), so there
897 is little practical difference between an int and a short
898 (except perhaps what happens when the GDB user types
899 "print short_arg = 0x10000;").
902 actually produces the correct address (we don't need to fix it
903 up). I made this code adapt so that it will offset the symbol
904 if it was pointing at an int-aligned location and not
905 otherwise. This way you can use the same gdb for 4.0.x and
908 If the parameter is shorter than an int, and is integral
909 (e.g. char, short, or unsigned equivalent), and is claimed to
910 be passed on an integer boundary, don't believe it! Offset the
911 parameter's address to the tail-end of that integer. */
913 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
914 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
915 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
917 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
918 - TYPE_LENGTH (SYMBOL_TYPE (sym));
922 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
924 /* If PCC says a parameter is a short or a char,
925 it is really an int. */
926 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
927 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
930 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
931 ? pcc_unsigned_promotion_type
932 : pcc_promotion_type;
936 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
938 #endif /* !BELIEVE_PCC_PROMOTION. */
941 /* acc seems to use P to declare the prototypes of functions that
942 are referenced by this file. gdb is not prepared to deal
943 with this extra information. FIXME, it ought to. */
946 SYMBOL_TYPE (sym) = read_type (&p, objfile);
947 goto process_prototype_types;
952 /* Parameter which is in a register. */
953 SYMBOL_TYPE (sym) = read_type (&p, objfile);
954 SYMBOL_CLASS (sym) = LOC_REGPARM;
955 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
956 if (SYMBOL_VALUE (sym) >= NUM_REGS)
958 complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
959 SYMBOL_SOURCE_NAME (sym));
960 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
962 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
963 add_symbol_to_list (sym, &local_symbols);
967 /* Register variable (either global or local). */
968 SYMBOL_TYPE (sym) = read_type (&p, objfile);
969 SYMBOL_CLASS (sym) = LOC_REGISTER;
970 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
971 if (SYMBOL_VALUE (sym) >= NUM_REGS)
973 complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
974 SYMBOL_SOURCE_NAME (sym));
975 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
977 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
980 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
981 name to represent an argument passed in a register.
982 GCC uses 'P' for the same case. So if we find such a symbol pair
983 we combine it into one 'P' symbol. For Sun cc we need to do this
984 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
985 the 'p' symbol even if it never saves the argument onto the stack.
987 On most machines, we want to preserve both symbols, so that
988 we can still get information about what is going on with the
989 stack (VAX for computing args_printed, using stack slots instead
990 of saved registers in backtraces, etc.).
992 Note that this code illegally combines
993 main(argc) struct foo argc; { register struct foo argc; }
994 but this case is considered pathological and causes a warning
995 from a decent compiler. */
998 && local_symbols->nsyms > 0
999 #ifndef USE_REGISTER_NOT_ARG
1000 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1002 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1003 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1004 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1005 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1009 struct symbol *prev_sym;
1010 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1011 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1012 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
1013 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym)))
1015 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1016 /* Use the type from the LOC_REGISTER; that is the type
1017 that is actually in that register. */
1018 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1019 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1024 add_symbol_to_list (sym, &local_symbols);
1027 add_symbol_to_list (sym, &file_symbols);
1031 /* Static symbol at top level of file */
1032 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1033 SYMBOL_CLASS (sym) = LOC_STATIC;
1034 SYMBOL_VALUE_ADDRESS (sym) = valu;
1035 #ifdef STATIC_TRANSFORM_NAME
1036 if (SYMBOL_NAME (sym)[0] == '$')
1038 struct minimal_symbol *msym;
1039 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1042 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1043 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1047 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1048 add_symbol_to_list (sym, &file_symbols);
1052 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1054 /* For a nameless type, we don't want a create a symbol, thus we
1055 did not use `sym'. Return without further processing. */
1056 if (nameless) return NULL;
1058 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1059 SYMBOL_VALUE (sym) = valu;
1060 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1061 /* C++ vagaries: we may have a type which is derived from
1062 a base type which did not have its name defined when the
1063 derived class was output. We fill in the derived class's
1064 base part member's name here in that case. */
1065 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1066 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1067 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1068 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1071 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1072 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1073 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1074 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1077 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1079 /* gcc-2.6 or later (when using -fvtable-thunks)
1080 emits a unique named type for a vtable entry.
1081 Some gdb code depends on that specific name. */
1082 extern const char vtbl_ptr_name[];
1084 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1085 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1086 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1088 /* If we are giving a name to a type such as "pointer to
1089 foo" or "function returning foo", we better not set
1090 the TYPE_NAME. If the program contains "typedef char
1091 *caddr_t;", we don't want all variables of type char
1092 * to print as caddr_t. This is not just a
1093 consequence of GDB's type management; PCC and GCC (at
1094 least through version 2.4) both output variables of
1095 either type char * or caddr_t with the type number
1096 defined in the 't' symbol for caddr_t. If a future
1097 compiler cleans this up it GDB is not ready for it
1098 yet, but if it becomes ready we somehow need to
1099 disable this check (without breaking the PCC/GCC2.4
1104 Fortunately, this check seems not to be necessary
1105 for anything except pointers or functions. */
1108 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1111 add_symbol_to_list (sym, &file_symbols);
1115 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1116 by 't' which means we are typedef'ing it as well. */
1117 synonym = *p == 't';
1121 /* The semantics of C++ state that "struct foo { ... }" also defines
1122 a typedef for "foo". Unfortunately, cfront never makes the typedef
1123 when translating C++ into C. We make the typedef here so that
1124 "ptype foo" works as expected for cfront translated code. */
1125 else if (current_subfile->language == language_cplus)
1128 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1130 /* For a nameless type, we don't want a create a symbol, thus we
1131 did not use `sym'. Return without further processing. */
1132 if (nameless) return NULL;
1134 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1135 SYMBOL_VALUE (sym) = valu;
1136 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1137 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1138 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1139 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
1140 add_symbol_to_list (sym, &file_symbols);
1144 /* Clone the sym and then modify it. */
1145 register struct symbol *typedef_sym = (struct symbol *)
1146 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
1147 *typedef_sym = *sym;
1148 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1149 SYMBOL_VALUE (typedef_sym) = valu;
1150 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1151 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1152 TYPE_NAME (SYMBOL_TYPE (sym))
1153 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
1154 add_symbol_to_list (typedef_sym, &file_symbols);
1159 /* Static symbol of local scope */
1160 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1161 SYMBOL_CLASS (sym) = LOC_STATIC;
1162 SYMBOL_VALUE_ADDRESS (sym) = valu;
1163 #ifdef STATIC_TRANSFORM_NAME
1164 if (SYMBOL_NAME (sym)[0] == '$')
1166 struct minimal_symbol *msym;
1167 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1170 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1171 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1175 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1177 add_symbol_to_list (sym, &global_symbols);
1179 add_symbol_to_list (sym, &local_symbols);
1183 /* Reference parameter */
1184 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1185 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1186 SYMBOL_VALUE (sym) = valu;
1187 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1188 add_symbol_to_list (sym, &local_symbols);
1192 /* Reference parameter which is in a register. */
1193 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1194 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1195 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1196 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1198 complain (®_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
1199 SYMBOL_SOURCE_NAME (sym));
1200 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1202 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1203 add_symbol_to_list (sym, &local_symbols);
1207 /* This is used by Sun FORTRAN for "function result value".
1208 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1209 that Pascal uses it too, but when I tried it Pascal used
1210 "x:3" (local symbol) instead. */
1211 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1212 SYMBOL_CLASS (sym) = LOC_LOCAL;
1213 SYMBOL_VALUE (sym) = valu;
1214 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1215 add_symbol_to_list (sym, &local_symbols);
1219 SYMBOL_TYPE (sym) = error_type (&p, objfile);
1220 SYMBOL_CLASS (sym) = LOC_CONST;
1221 SYMBOL_VALUE (sym) = 0;
1222 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1223 add_symbol_to_list (sym, &file_symbols);
1227 /* When passing structures to a function, some systems sometimes pass
1228 the address in a register, not the structure itself. */
1230 if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1232 && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
1233 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1234 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1235 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET)))
1237 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to
1238 convert LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
1239 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
1240 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1241 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1242 subsequent arguments on the sparc, for example). */
1243 else if (SYMBOL_CLASS (sym) == LOC_ARG)
1244 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1251 /* Skip rest of this symbol and return an error type.
1253 General notes on error recovery: error_type always skips to the
1254 end of the symbol (modulo cretinous dbx symbol name continuation).
1255 Thus code like this:
1257 if (*(*pp)++ != ';')
1258 return error_type (pp, objfile);
1260 is wrong because if *pp starts out pointing at '\0' (typically as the
1261 result of an earlier error), it will be incremented to point to the
1262 start of the next symbol, which might produce strange results, at least
1263 if you run off the end of the string table. Instead use
1266 return error_type (pp, objfile);
1272 foo = error_type (pp, objfile);
1276 And in case it isn't obvious, the point of all this hair is so the compiler
1277 can define new types and new syntaxes, and old versions of the
1278 debugger will be able to read the new symbol tables. */
1280 static struct type *
1281 error_type (pp, objfile)
1283 struct objfile *objfile;
1285 complain (&error_type_complaint);
1288 /* Skip to end of symbol. */
1289 while (**pp != '\0')
1294 /* Check for and handle cretinous dbx symbol name continuation! */
1295 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
1297 *pp = next_symbol_text (objfile);
1304 return (builtin_type_error);
1308 /* Read type information or a type definition; return the type. Even
1309 though this routine accepts either type information or a type
1310 definition, the distinction is relevant--some parts of stabsread.c
1311 assume that type information starts with a digit, '-', or '(' in
1312 deciding whether to call read_type. */
1315 read_type (pp, objfile)
1317 struct objfile *objfile;
1319 register struct type *type = 0;
1323 char type_descriptor;
1325 /* Size in bits of type if specified by a type attribute, or -1 if
1326 there is no size attribute. */
1329 /* Used to distinguish string and bitstring from char-array and set. */
1332 /* Read type number if present. The type number may be omitted.
1333 for instance in a two-dimensional array declared with type
1334 "ar1;1;10;ar1;1;10;4". */
1335 if ((**pp >= '0' && **pp <= '9')
1339 if (read_type_number (pp, typenums) != 0)
1340 return error_type (pp, objfile);
1342 /* Type is not being defined here. Either it already exists,
1343 or this is a forward reference to it. dbx_alloc_type handles
1346 return dbx_alloc_type (typenums, objfile);
1348 /* Type is being defined here. */
1355 /* It might be a type attribute or a member type. */
1356 if (isdigit (*p) || *p == '(' || *p == '-')
1361 /* Type attributes. */
1364 /* Skip to the semicolon. */
1365 while (*p != ';' && *p != '\0')
1369 return error_type (pp, objfile);
1371 /* Skip the semicolon. */
1377 type_size = atoi (attr + 1);
1387 /* Ignore unrecognized type attributes, so future compilers
1388 can invent new ones. */
1393 /* Skip the type descriptor, we get it below with (*pp)[-1]. */
1398 /* 'typenums=' not present, type is anonymous. Read and return
1399 the definition, but don't put it in the type vector. */
1400 typenums[0] = typenums[1] = -1;
1404 type_descriptor = (*pp)[-1];
1405 switch (type_descriptor)
1409 enum type_code code;
1411 /* Used to index through file_symbols. */
1412 struct pending *ppt;
1415 /* Name including "struct", etc. */
1419 char *from, *to, *p, *q1, *q2;
1421 /* Set the type code according to the following letter. */
1425 code = TYPE_CODE_STRUCT;
1428 code = TYPE_CODE_UNION;
1431 code = TYPE_CODE_ENUM;
1435 /* Complain and keep going, so compilers can invent new
1436 cross-reference types. */
1437 static struct complaint msg =
1438 {"Unrecognized cross-reference type `%c'", 0, 0};
1439 complain (&msg, (*pp)[0]);
1440 code = TYPE_CODE_STRUCT;
1445 q1 = strchr(*pp, '<');
1446 p = strchr(*pp, ':');
1448 return error_type (pp, objfile);
1449 while (q1 && p > q1 && p[1] == ':')
1451 q2 = strchr(q1, '>');
1457 return error_type (pp, objfile);
1460 (char *)obstack_alloc (&objfile->type_obstack, p - *pp + 1);
1462 /* Copy the name. */
1468 /* Set the pointer ahead of the name which we just read, and
1473 /* Now check to see whether the type has already been
1474 declared. This was written for arrays of cross-referenced
1475 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
1476 sure it is not necessary anymore. But it might be a good
1477 idea, to save a little memory. */
1479 for (ppt = file_symbols; ppt; ppt = ppt->next)
1480 for (i = 0; i < ppt->nsyms; i++)
1482 struct symbol *sym = ppt->symbol[i];
1484 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1485 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1486 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1487 && STREQ (SYMBOL_NAME (sym), type_name))
1489 obstack_free (&objfile -> type_obstack, type_name);
1490 type = SYMBOL_TYPE (sym);
1495 /* Didn't find the type to which this refers, so we must
1496 be dealing with a forward reference. Allocate a type
1497 structure for it, and keep track of it so we can
1498 fill in the rest of the fields when we get the full
1500 type = dbx_alloc_type (typenums, objfile);
1501 TYPE_CODE (type) = code;
1502 TYPE_TAG_NAME (type) = type_name;
1503 INIT_CPLUS_SPECIFIC(type);
1504 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1506 add_undefined_type (type);
1510 case '-': /* RS/6000 built-in type */
1529 /* Peek ahead at the number to detect void. */
1530 if (read_type_number (pp, xtypenums) != 0)
1531 return error_type (pp, objfile);
1533 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1534 /* It's being defined as itself. That means it is "void". */
1535 type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
1540 /* Go back to the number and have read_type get it. This means
1541 that we can deal with something like t(1,2)=(3,4)=... which
1542 the Lucid compiler uses. */
1544 xtype = read_type (pp, objfile);
1546 /* The type is being defined to another type. So we copy the type.
1547 This loses if we copy a C++ class and so we lose track of how
1548 the names are mangled (but g++ doesn't output stabs like this
1551 type = alloc_type (objfile);
1552 if (SYMBOL_LINE (current_symbol) == 0)
1555 /* The idea behind clearing the names is that the only purpose
1556 for defining a type to another type is so that the name of
1557 one can be different. So we probably don't need to worry
1558 much about the case where the compiler doesn't give a name
1560 TYPE_NAME (type) = NULL;
1561 TYPE_TAG_NAME (type) = NULL;
1565 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
1566 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
1567 TYPE_TARGET_TYPE (type) = xtype;
1570 if (typenums[0] != -1)
1571 *dbx_lookup_type (typenums) = type;
1575 /* In the following types, we must be sure to overwrite any existing
1576 type that the typenums refer to, rather than allocating a new one
1577 and making the typenums point to the new one. This is because there
1578 may already be pointers to the existing type (if it had been
1579 forward-referenced), and we must change it to a pointer, function,
1580 reference, or whatever, *in-place*. */
1583 type1 = read_type (pp, objfile);
1584 type = make_pointer_type (type1, dbx_lookup_type (typenums));
1587 case '&': /* Reference to another type */
1588 type1 = read_type (pp, objfile);
1589 type = make_reference_type (type1, dbx_lookup_type (typenums));
1592 case 'f': /* Function returning another type */
1593 if (os9k_stabs && **pp == '(')
1595 /* Function prototype; parse it.
1596 We must conditionalize this on os9k_stabs because otherwise
1597 it could be confused with a Sun-style (1,3) typenumber
1603 t = read_type(pp, objfile);
1604 if (**pp == ',') ++*pp;
1607 type1 = read_type (pp, objfile);
1608 type = make_function_type (type1, dbx_lookup_type (typenums));
1611 case 'k': /* Const qualifier on some type (Sun) */
1612 case 'c': /* Const qualifier on some type (OS9000) */
1613 /* Because 'c' means other things to AIX and 'k' is perfectly good,
1614 only accept 'c' in the os9k_stabs case. */
1615 if (type_descriptor == 'c' && !os9k_stabs)
1616 return error_type (pp, objfile);
1617 type = read_type (pp, objfile);
1618 /* FIXME! For now, we ignore const and volatile qualifiers. */
1621 case 'B': /* Volatile qual on some type (Sun) */
1622 case 'i': /* Volatile qual on some type (OS9000) */
1623 /* Because 'i' means other things to AIX and 'B' is perfectly good,
1624 only accept 'i' in the os9k_stabs case. */
1625 if (type_descriptor == 'i' && !os9k_stabs)
1626 return error_type (pp, objfile);
1627 type = read_type (pp, objfile);
1628 /* FIXME! For now, we ignore const and volatile qualifiers. */
1631 /* FIXME -- we should be doing smash_to_XXX types here. */
1632 case '@': /* Member (class & variable) type */
1634 struct type *domain = read_type (pp, objfile);
1635 struct type *memtype;
1638 /* Invalid member type data format. */
1639 return error_type (pp, objfile);
1642 memtype = read_type (pp, objfile);
1643 type = dbx_alloc_type (typenums, objfile);
1644 smash_to_member_type (type, domain, memtype);
1648 case '#': /* Method (class & fn) type */
1649 if ((*pp)[0] == '#')
1651 /* We'll get the parameter types from the name. */
1652 struct type *return_type;
1655 return_type = read_type (pp, objfile);
1656 if (*(*pp)++ != ';')
1657 complain (&invalid_member_complaint, symnum);
1658 type = allocate_stub_method (return_type);
1659 if (typenums[0] != -1)
1660 *dbx_lookup_type (typenums) = type;
1664 struct type *domain = read_type (pp, objfile);
1665 struct type *return_type;
1669 /* Invalid member type data format. */
1670 return error_type (pp, objfile);
1674 return_type = read_type (pp, objfile);
1675 args = read_args (pp, ';', objfile);
1676 type = dbx_alloc_type (typenums, objfile);
1677 smash_to_method_type (type, domain, return_type, args);
1681 case 'r': /* Range type */
1682 type = read_range_type (pp, typenums, objfile);
1683 if (typenums[0] != -1)
1684 *dbx_lookup_type (typenums) = type;
1689 /* Const and volatile qualified type. */
1690 type = read_type (pp, objfile);
1693 /* Sun ACC builtin int type */
1694 type = read_sun_builtin_type (pp, typenums, objfile);
1695 if (typenums[0] != -1)
1696 *dbx_lookup_type (typenums) = type;
1700 case 'R': /* Sun ACC builtin float type */
1701 type = read_sun_floating_type (pp, typenums, objfile);
1702 if (typenums[0] != -1)
1703 *dbx_lookup_type (typenums) = type;
1706 case 'e': /* Enumeration type */
1707 type = dbx_alloc_type (typenums, objfile);
1708 type = read_enum_type (pp, type, objfile);
1709 if (typenums[0] != -1)
1710 *dbx_lookup_type (typenums) = type;
1713 case 's': /* Struct type */
1714 case 'u': /* Union type */
1715 type = dbx_alloc_type (typenums, objfile);
1716 switch (type_descriptor)
1719 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1722 TYPE_CODE (type) = TYPE_CODE_UNION;
1725 type = read_struct_type (pp, type, objfile);
1728 case 'a': /* Array type */
1730 return error_type (pp, objfile);
1733 type = dbx_alloc_type (typenums, objfile);
1734 type = read_array_type (pp, type, objfile);
1736 TYPE_CODE (type) = TYPE_CODE_STRING;
1740 type1 = read_type (pp, objfile);
1741 type = create_set_type ((struct type*) NULL, type1);
1743 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
1744 if (typenums[0] != -1)
1745 *dbx_lookup_type (typenums) = type;
1749 --*pp; /* Go back to the symbol in error */
1750 /* Particularly important if it was \0! */
1751 return error_type (pp, objfile);
1756 warning ("GDB internal error, type is NULL in stabsread.c\n");
1757 return error_type (pp, objfile);
1760 /* Size specified in a type attribute overrides any other size. */
1761 if (type_size != -1)
1762 TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
1767 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1768 Return the proper type node for a given builtin type number. */
1770 static struct type *
1771 rs6000_builtin_type (typenum)
1774 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1775 #define NUMBER_RECOGNIZED 34
1776 /* This includes an empty slot for type number -0. */
1777 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
1778 struct type *rettype = NULL;
1780 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
1782 complain (&rs6000_builtin_complaint, typenum);
1783 return builtin_type_error;
1785 if (negative_types[-typenum] != NULL)
1786 return negative_types[-typenum];
1788 #if TARGET_CHAR_BIT != 8
1789 #error This code wrong for TARGET_CHAR_BIT not 8
1790 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1791 that if that ever becomes not true, the correct fix will be to
1792 make the size in the struct type to be in bits, not in units of
1799 /* The size of this and all the other types are fixed, defined
1800 by the debugging format. If there is a type called "int" which
1801 is other than 32 bits, then it should use a new negative type
1802 number (or avoid negative type numbers for that case).
1803 See stabs.texinfo. */
1804 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
1807 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
1810 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
1813 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
1816 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
1817 "unsigned char", NULL);
1820 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
1823 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
1824 "unsigned short", NULL);
1827 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1828 "unsigned int", NULL);
1831 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1834 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1835 "unsigned long", NULL);
1838 rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
1841 /* IEEE single precision (32 bit). */
1842 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
1845 /* IEEE double precision (64 bit). */
1846 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
1849 /* This is an IEEE double on the RS/6000, and different machines with
1850 different sizes for "long double" should use different negative
1851 type numbers. See stabs.texinfo. */
1852 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
1855 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
1858 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1862 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
1865 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
1868 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
1871 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
1875 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
1879 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
1883 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1887 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1891 /* Complex type consisting of two IEEE single precision values. */
1892 rettype = init_type (TYPE_CODE_ERROR, 8, 0, "complex", NULL);
1895 /* Complex type consisting of two IEEE double precision values. */
1896 rettype = init_type (TYPE_CODE_ERROR, 16, 0, "double complex", NULL);
1899 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
1902 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
1905 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
1908 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
1911 rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
1914 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
1915 "unsigned long long", NULL);
1918 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
1922 rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
1925 negative_types[-typenum] = rettype;
1929 /* This page contains subroutines of read_type. */
1931 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1932 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1933 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1934 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1936 /* Read member function stabs info for C++ classes. The form of each member
1939 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1941 An example with two member functions is:
1943 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1945 For the case of overloaded operators, the format is op$::*.funcs, where
1946 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1947 name (such as `+=') and `.' marks the end of the operator name.
1949 Returns 1 for success, 0 for failure. */
1952 read_member_functions (fip, pp, type, objfile)
1953 struct field_info *fip;
1956 struct objfile *objfile;
1960 /* Total number of member functions defined in this class. If the class
1961 defines two `f' functions, and one `g' function, then this will have
1963 int total_length = 0;
1967 struct next_fnfield *next;
1968 struct fn_field fn_field;
1970 struct type *look_ahead_type;
1971 struct next_fnfieldlist *new_fnlist;
1972 struct next_fnfield *new_sublist;
1976 /* Process each list until we find something that is not a member function
1977 or find the end of the functions. */
1981 /* We should be positioned at the start of the function name.
1982 Scan forward to find the first ':' and if it is not the
1983 first of a "::" delimiter, then this is not a member function. */
1995 look_ahead_type = NULL;
1998 new_fnlist = (struct next_fnfieldlist *)
1999 xmalloc (sizeof (struct next_fnfieldlist));
2000 make_cleanup (free, new_fnlist);
2001 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
2003 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
2005 /* This is a completely wierd case. In order to stuff in the
2006 names that might contain colons (the usual name delimiter),
2007 Mike Tiemann defined a different name format which is
2008 signalled if the identifier is "op$". In that case, the
2009 format is "op$::XXXX." where XXXX is the name. This is
2010 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2011 /* This lets the user type "break operator+".
2012 We could just put in "+" as the name, but that wouldn't
2014 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2015 char *o = opname + 3;
2017 /* Skip past '::'. */
2020 STABS_CONTINUE (pp, objfile);
2026 main_fn_name = savestring (opname, o - opname);
2032 main_fn_name = savestring (*pp, p - *pp);
2033 /* Skip past '::'. */
2036 new_fnlist -> fn_fieldlist.name = main_fn_name;
2041 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
2042 make_cleanup (free, new_sublist);
2043 memset (new_sublist, 0, sizeof (struct next_fnfield));
2045 /* Check for and handle cretinous dbx symbol name continuation! */
2046 if (look_ahead_type == NULL)
2049 STABS_CONTINUE (pp, objfile);
2051 new_sublist -> fn_field.type = read_type (pp, objfile);
2054 /* Invalid symtab info for member function. */
2060 /* g++ version 1 kludge */
2061 new_sublist -> fn_field.type = look_ahead_type;
2062 look_ahead_type = NULL;
2072 /* If this is just a stub, then we don't have the real name here. */
2074 if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB)
2076 if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type))
2077 TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type;
2078 new_sublist -> fn_field.is_stub = 1;
2080 new_sublist -> fn_field.physname = savestring (*pp, p - *pp);
2083 /* Set this member function's visibility fields. */
2086 case VISIBILITY_PRIVATE:
2087 new_sublist -> fn_field.is_private = 1;
2089 case VISIBILITY_PROTECTED:
2090 new_sublist -> fn_field.is_protected = 1;
2094 STABS_CONTINUE (pp, objfile);
2097 case 'A': /* Normal functions. */
2098 new_sublist -> fn_field.is_const = 0;
2099 new_sublist -> fn_field.is_volatile = 0;
2102 case 'B': /* `const' member functions. */
2103 new_sublist -> fn_field.is_const = 1;
2104 new_sublist -> fn_field.is_volatile = 0;
2107 case 'C': /* `volatile' member function. */
2108 new_sublist -> fn_field.is_const = 0;
2109 new_sublist -> fn_field.is_volatile = 1;
2112 case 'D': /* `const volatile' member function. */
2113 new_sublist -> fn_field.is_const = 1;
2114 new_sublist -> fn_field.is_volatile = 1;
2117 case '*': /* File compiled with g++ version 1 -- no info */
2122 complain (&const_vol_complaint, **pp);
2131 /* virtual member function, followed by index.
2132 The sign bit is set to distinguish pointers-to-methods
2133 from virtual function indicies. Since the array is
2134 in words, the quantity must be shifted left by 1
2135 on 16 bit machine, and by 2 on 32 bit machine, forcing
2136 the sign bit out, and usable as a valid index into
2137 the array. Remove the sign bit here. */
2138 new_sublist -> fn_field.voffset =
2139 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
2143 STABS_CONTINUE (pp, objfile);
2144 if (**pp == ';' || **pp == '\0')
2146 /* Must be g++ version 1. */
2147 new_sublist -> fn_field.fcontext = 0;
2151 /* Figure out from whence this virtual function came.
2152 It may belong to virtual function table of
2153 one of its baseclasses. */
2154 look_ahead_type = read_type (pp, objfile);
2157 /* g++ version 1 overloaded methods. */
2161 new_sublist -> fn_field.fcontext = look_ahead_type;
2170 look_ahead_type = NULL;
2176 /* static member function. */
2177 new_sublist -> fn_field.voffset = VOFFSET_STATIC;
2178 if (strncmp (new_sublist -> fn_field.physname,
2179 main_fn_name, strlen (main_fn_name)))
2181 new_sublist -> fn_field.is_stub = 1;
2187 complain (&member_fn_complaint, (*pp)[-1]);
2188 /* Fall through into normal member function. */
2191 /* normal member function. */
2192 new_sublist -> fn_field.voffset = 0;
2193 new_sublist -> fn_field.fcontext = 0;
2197 new_sublist -> next = sublist;
2198 sublist = new_sublist;
2200 STABS_CONTINUE (pp, objfile);
2202 while (**pp != ';' && **pp != '\0');
2206 new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *)
2207 obstack_alloc (&objfile -> type_obstack,
2208 sizeof (struct fn_field) * length);
2209 memset (new_fnlist -> fn_fieldlist.fn_fields, 0,
2210 sizeof (struct fn_field) * length);
2211 for (i = length; (i--, sublist); sublist = sublist -> next)
2213 new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field;
2216 new_fnlist -> fn_fieldlist.length = length;
2217 new_fnlist -> next = fip -> fnlist;
2218 fip -> fnlist = new_fnlist;
2220 total_length += length;
2221 STABS_CONTINUE (pp, objfile);
2226 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2227 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2228 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
2229 memset (TYPE_FN_FIELDLISTS (type), 0,
2230 sizeof (struct fn_fieldlist) * nfn_fields);
2231 TYPE_NFN_FIELDS (type) = nfn_fields;
2232 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2238 /* Special GNU C++ name.
2240 Returns 1 for success, 0 for failure. "failure" means that we can't
2241 keep parsing and it's time for error_type(). */
2244 read_cpp_abbrev (fip, pp, type, objfile)
2245 struct field_info *fip;
2248 struct objfile *objfile;
2253 struct type *context;
2263 /* At this point, *pp points to something like "22:23=*22...",
2264 where the type number before the ':' is the "context" and
2265 everything after is a regular type definition. Lookup the
2266 type, find it's name, and construct the field name. */
2268 context = read_type (pp, objfile);
2272 case 'f': /* $vf -- a virtual function table pointer */
2273 fip->list->field.name =
2274 obconcat (&objfile->type_obstack, vptr_name, "", "");
2277 case 'b': /* $vb -- a virtual bsomethingorother */
2278 name = type_name_no_tag (context);
2281 complain (&invalid_cpp_type_complaint, symnum);
2284 fip->list->field.name =
2285 obconcat (&objfile->type_obstack, vb_name, name, "");
2289 complain (&invalid_cpp_abbrev_complaint, *pp);
2290 fip->list->field.name =
2291 obconcat (&objfile->type_obstack,
2292 "INVALID_CPLUSPLUS_ABBREV", "", "");
2296 /* At this point, *pp points to the ':'. Skip it and read the
2302 complain (&invalid_cpp_abbrev_complaint, *pp);
2305 fip->list->field.type = read_type (pp, objfile);
2307 (*pp)++; /* Skip the comma. */
2313 fip->list->field.bitpos = read_huge_number (pp, ';', &nbits);
2317 /* This field is unpacked. */
2318 fip->list->field.bitsize = 0;
2319 fip->list->visibility = VISIBILITY_PRIVATE;
2323 complain (&invalid_cpp_abbrev_complaint, *pp);
2324 /* We have no idea what syntax an unrecognized abbrev would have, so
2325 better return 0. If we returned 1, we would need to at least advance
2326 *pp to avoid an infinite loop. */
2333 read_one_struct_field (fip, pp, p, type, objfile)
2334 struct field_info *fip;
2338 struct objfile *objfile;
2340 /* The following is code to work around cfront generated stabs.
2341 The stabs contains full mangled name for each field.
2342 We try to demangle the name and extract the field name out of it.
2344 if (ARM_DEMANGLING && current_subfile->language == language_cplus)
2350 dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
2353 dem_p = strrchr (dem, ':');
2354 if (dem_p != 0 && *(dem_p-1)==':')
2356 fip->list->field.name =
2357 obsavestring (dem_p, strlen(dem_p), &objfile -> type_obstack);
2361 fip->list->field.name =
2362 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
2366 /* end of code for cfront work around */
2369 fip -> list -> field.name =
2370 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
2373 /* This means we have a visibility for a field coming. */
2377 fip -> list -> visibility = *(*pp)++;
2381 /* normal dbx-style format, no explicit visibility */
2382 fip -> list -> visibility = VISIBILITY_PUBLIC;
2385 fip -> list -> field.type = read_type (pp, objfile);
2390 /* Possible future hook for nested types. */
2393 fip -> list -> field.bitpos = (long)-2; /* nested type */
2399 /* Static class member. */
2400 fip -> list -> field.bitpos = (long) -1;
2406 fip -> list -> field.bitsize = (long) savestring (*pp, p - *pp);
2410 else if (**pp != ',')
2412 /* Bad structure-type format. */
2413 complain (&stabs_general_complaint, "bad structure-type format");
2417 (*pp)++; /* Skip the comma. */
2421 fip -> list -> field.bitpos = read_huge_number (pp, ',', &nbits);
2424 complain (&stabs_general_complaint, "bad structure-type format");
2427 fip -> list -> field.bitsize = read_huge_number (pp, ';', &nbits);
2430 complain (&stabs_general_complaint, "bad structure-type format");
2435 if (fip -> list -> field.bitpos == 0 && fip -> list -> field.bitsize == 0)
2437 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2438 it is a field which has been optimized out. The correct stab for
2439 this case is to use VISIBILITY_IGNORE, but that is a recent
2440 invention. (2) It is a 0-size array. For example
2441 union { int num; char str[0]; } foo. Printing "<no value>" for
2442 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2443 will continue to work, and a 0-size array as a whole doesn't
2444 have any contents to print.
2446 I suspect this probably could also happen with gcc -gstabs (not
2447 -gstabs+) for static fields, and perhaps other C++ extensions.
2448 Hopefully few people use -gstabs with gdb, since it is intended
2449 for dbx compatibility. */
2451 /* Ignore this field. */
2452 fip -> list-> visibility = VISIBILITY_IGNORE;
2456 /* Detect an unpacked field and mark it as such.
2457 dbx gives a bit size for all fields.
2458 Note that forward refs cannot be packed,
2459 and treat enums as if they had the width of ints. */
2461 if (TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_INT
2462 && TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_BOOL
2463 && TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_ENUM)
2465 fip -> list -> field.bitsize = 0;
2467 if ((fip -> list -> field.bitsize
2468 == TARGET_CHAR_BIT * TYPE_LENGTH (fip -> list -> field.type)
2469 || (TYPE_CODE (fip -> list -> field.type) == TYPE_CODE_ENUM
2470 && (fip -> list -> field.bitsize
2475 fip -> list -> field.bitpos % 8 == 0)
2477 fip -> list -> field.bitsize = 0;
2483 /* Read struct or class data fields. They have the form:
2485 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2487 At the end, we see a semicolon instead of a field.
2489 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2492 The optional VISIBILITY is one of:
2494 '/0' (VISIBILITY_PRIVATE)
2495 '/1' (VISIBILITY_PROTECTED)
2496 '/2' (VISIBILITY_PUBLIC)
2497 '/9' (VISIBILITY_IGNORE)
2499 or nothing, for C style fields with public visibility.
2501 Returns 1 for success, 0 for failure. */
2504 read_struct_fields (fip, pp, type, objfile)
2505 struct field_info *fip;
2508 struct objfile *objfile;
2511 struct nextfield *new;
2513 /* We better set p right now, in case there are no fields at all... */
2517 /* Read each data member type until we find the terminating ';' at the end of
2518 the data member list, or break for some other reason such as finding the
2519 start of the member function list. */
2523 if (os9k_stabs && **pp == ',') break;
2524 STABS_CONTINUE (pp, objfile);
2525 /* Get space to record the next field's data. */
2526 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2527 make_cleanup (free, new);
2528 memset (new, 0, sizeof (struct nextfield));
2529 new -> next = fip -> list;
2532 /* Get the field name. */
2535 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2536 unless the CPLUS_MARKER is followed by an underscore, in
2537 which case it is just the name of an anonymous type, which we
2538 should handle like any other type name. */
2540 if (is_cplus_marker (p[0]) && p[1] != '_')
2542 if (!read_cpp_abbrev (fip, pp, type, objfile))
2547 /* Look for the ':' that separates the field name from the field
2548 values. Data members are delimited by a single ':', while member
2549 functions are delimited by a pair of ':'s. When we hit the member
2550 functions (if any), terminate scan loop and return. */
2552 while (*p != ':' && *p != '\0')
2559 /* Check to see if we have hit the member functions yet. */
2564 read_one_struct_field (fip, pp, p, type, objfile);
2566 if (p[0] == ':' && p[1] == ':')
2568 /* chill the list of fields: the last entry (at the head) is a
2569 partially constructed entry which we now scrub. */
2570 fip -> list = fip -> list -> next;
2575 /* The stabs for C++ derived classes contain baseclass information which
2576 is marked by a '!' character after the total size. This function is
2577 called when we encounter the baseclass marker, and slurps up all the
2578 baseclass information.
2580 Immediately following the '!' marker is the number of base classes that
2581 the class is derived from, followed by information for each base class.
2582 For each base class, there are two visibility specifiers, a bit offset
2583 to the base class information within the derived class, a reference to
2584 the type for the base class, and a terminating semicolon.
2586 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2588 Baseclass information marker __________________|| | | | | | |
2589 Number of baseclasses __________________________| | | | | | |
2590 Visibility specifiers (2) ________________________| | | | | |
2591 Offset in bits from start of class _________________| | | | |
2592 Type number for base class ___________________________| | | |
2593 Visibility specifiers (2) _______________________________| | |
2594 Offset in bits from start of class ________________________| |
2595 Type number of base class ____________________________________|
2597 Return 1 for success, 0 for (error-type-inducing) failure. */
2600 read_baseclasses (fip, pp, type, objfile)
2601 struct field_info *fip;
2604 struct objfile *objfile;
2607 struct nextfield *new;
2615 /* Skip the '!' baseclass information marker. */
2619 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2622 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
2628 /* Some stupid compilers have trouble with the following, so break
2629 it up into simpler expressions. */
2630 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
2631 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
2634 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
2637 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2638 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2642 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
2644 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
2646 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2647 make_cleanup (free, new);
2648 memset (new, 0, sizeof (struct nextfield));
2649 new -> next = fip -> list;
2651 new -> field.bitsize = 0; /* this should be an unpacked field! */
2653 STABS_CONTINUE (pp, objfile);
2657 /* Nothing to do. */
2660 SET_TYPE_FIELD_VIRTUAL (type, i);
2663 /* Unknown character. Complain and treat it as non-virtual. */
2665 static struct complaint msg = {
2666 "Unknown virtual character `%c' for baseclass", 0, 0};
2667 complain (&msg, **pp);
2672 new -> visibility = *(*pp)++;
2673 switch (new -> visibility)
2675 case VISIBILITY_PRIVATE:
2676 case VISIBILITY_PROTECTED:
2677 case VISIBILITY_PUBLIC:
2680 /* Bad visibility format. Complain and treat it as
2683 static struct complaint msg = {
2684 "Unknown visibility `%c' for baseclass", 0, 0};
2685 complain (&msg, new -> visibility);
2686 new -> visibility = VISIBILITY_PUBLIC;
2693 /* The remaining value is the bit offset of the portion of the object
2694 corresponding to this baseclass. Always zero in the absence of
2695 multiple inheritance. */
2697 new -> field.bitpos = read_huge_number (pp, ',', &nbits);
2702 /* The last piece of baseclass information is the type of the
2703 base class. Read it, and remember it's type name as this
2706 new -> field.type = read_type (pp, objfile);
2707 new -> field.name = type_name_no_tag (new -> field.type);
2709 /* skip trailing ';' and bump count of number of fields seen */
2718 /* The tail end of stabs for C++ classes that contain a virtual function
2719 pointer contains a tilde, a %, and a type number.
2720 The type number refers to the base class (possibly this class itself) which
2721 contains the vtable pointer for the current class.
2723 This function is called when we have parsed all the method declarations,
2724 so we can look for the vptr base class info. */
2727 read_tilde_fields (fip, pp, type, objfile)
2728 struct field_info *fip;
2731 struct objfile *objfile;
2735 STABS_CONTINUE (pp, objfile);
2737 /* If we are positioned at a ';', then skip it. */
2747 if (**pp == '=' || **pp == '+' || **pp == '-')
2749 /* Obsolete flags that used to indicate the presence
2750 of constructors and/or destructors. */
2754 /* Read either a '%' or the final ';'. */
2755 if (*(*pp)++ == '%')
2757 /* The next number is the type number of the base class
2758 (possibly our own class) which supplies the vtable for
2759 this class. Parse it out, and search that class to find
2760 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2761 and TYPE_VPTR_FIELDNO. */
2766 t = read_type (pp, objfile);
2768 while (*p != '\0' && *p != ';')
2774 /* Premature end of symbol. */
2778 TYPE_VPTR_BASETYPE (type) = t;
2779 if (type == t) /* Our own class provides vtbl ptr */
2781 for (i = TYPE_NFIELDS (t) - 1;
2782 i >= TYPE_N_BASECLASSES (t);
2785 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2786 sizeof (vptr_name) - 1))
2788 TYPE_VPTR_FIELDNO (type) = i;
2792 /* Virtual function table field not found. */
2793 complain (&vtbl_notfound_complaint, TYPE_NAME (type));
2798 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2809 attach_fn_fields_to_type (fip, type)
2810 struct field_info *fip;
2811 register struct type *type;
2815 for (n = TYPE_NFN_FIELDS (type);
2816 fip -> fnlist != NULL;
2817 fip -> fnlist = fip -> fnlist -> next)
2819 --n; /* Circumvent Sun3 compiler bug */
2820 TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist;
2825 /* Create the vector of fields, and record how big it is.
2826 We need this info to record proper virtual function table information
2827 for this class's virtual functions. */
2830 attach_fields_to_type (fip, type, objfile)
2831 struct field_info *fip;
2832 register struct type *type;
2833 struct objfile *objfile;
2835 register int nfields = 0;
2836 register int non_public_fields = 0;
2837 register struct nextfield *scan;
2839 /* Count up the number of fields that we have, as well as taking note of
2840 whether or not there are any non-public fields, which requires us to
2841 allocate and build the private_field_bits and protected_field_bits
2844 for (scan = fip -> list; scan != NULL; scan = scan -> next)
2847 if (scan -> visibility != VISIBILITY_PUBLIC)
2849 non_public_fields++;
2853 /* Now we know how many fields there are, and whether or not there are any
2854 non-public fields. Record the field count, allocate space for the
2855 array of fields, and create blank visibility bitfields if necessary. */
2857 TYPE_NFIELDS (type) = nfields;
2858 TYPE_FIELDS (type) = (struct field *)
2859 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2860 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2862 if (non_public_fields)
2864 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2866 TYPE_FIELD_PRIVATE_BITS (type) =
2867 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2868 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2870 TYPE_FIELD_PROTECTED_BITS (type) =
2871 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2872 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2874 TYPE_FIELD_IGNORE_BITS (type) =
2875 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2876 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2879 /* Copy the saved-up fields into the field vector. Start from the head
2880 of the list, adding to the tail of the field array, so that they end
2881 up in the same order in the array in which they were added to the list. */
2883 while (nfields-- > 0)
2885 TYPE_FIELD (type, nfields) = fip -> list -> field;
2886 switch (fip -> list -> visibility)
2888 case VISIBILITY_PRIVATE:
2889 SET_TYPE_FIELD_PRIVATE (type, nfields);
2892 case VISIBILITY_PROTECTED:
2893 SET_TYPE_FIELD_PROTECTED (type, nfields);
2896 case VISIBILITY_IGNORE:
2897 SET_TYPE_FIELD_IGNORE (type, nfields);
2900 case VISIBILITY_PUBLIC:
2904 /* Unknown visibility. Complain and treat it as public. */
2906 static struct complaint msg = {
2907 "Unknown visibility `%c' for field", 0, 0};
2908 complain (&msg, fip -> list -> visibility);
2912 fip -> list = fip -> list -> next;
2917 /* Read the description of a structure (or union type) and return an object
2918 describing the type.
2920 PP points to a character pointer that points to the next unconsumed token
2921 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2922 *PP will point to "4a:1,0,32;;".
2924 TYPE points to an incomplete type that needs to be filled in.
2926 OBJFILE points to the current objfile from which the stabs information is
2927 being read. (Note that it is redundant in that TYPE also contains a pointer
2928 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2931 static struct type *
2932 read_struct_type (pp, type, objfile)
2935 struct objfile *objfile;
2937 struct cleanup *back_to;
2938 struct field_info fi;
2943 back_to = make_cleanup (null_cleanup, 0);
2945 INIT_CPLUS_SPECIFIC (type);
2946 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2948 /* First comes the total size in bytes. */
2952 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
2954 return error_type (pp, objfile);
2957 /* Now read the baseclasses, if any, read the regular C struct or C++
2958 class member fields, attach the fields to the type, read the C++
2959 member functions, attach them to the type, and then read any tilde
2960 field (baseclass specifier for the class holding the main vtable). */
2962 if (!read_baseclasses (&fi, pp, type, objfile)
2963 || !read_struct_fields (&fi, pp, type, objfile)
2964 || !attach_fields_to_type (&fi, type, objfile)
2965 || !read_member_functions (&fi, pp, type, objfile)
2966 || !attach_fn_fields_to_type (&fi, type)
2967 || !read_tilde_fields (&fi, pp, type, objfile))
2969 type = error_type (pp, objfile);
2972 do_cleanups (back_to);
2976 /* Read a definition of an array type,
2977 and create and return a suitable type object.
2978 Also creates a range type which represents the bounds of that
2981 static struct type *
2982 read_array_type (pp, type, objfile)
2984 register struct type *type;
2985 struct objfile *objfile;
2987 struct type *index_type, *element_type, *range_type;
2992 /* Format of an array type:
2993 "ar<index type>;lower;upper;<array_contents_type>".
2994 OS9000: "arlower,upper;<array_contents_type>".
2996 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2997 for these, produce a type like float[][]. */
3000 index_type = builtin_type_int;
3003 index_type = read_type (pp, objfile);
3005 /* Improper format of array type decl. */
3006 return error_type (pp, objfile);
3010 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
3015 lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
3017 return error_type (pp, objfile);
3019 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
3024 upper = read_huge_number (pp, ';', &nbits);
3026 return error_type (pp, objfile);
3028 element_type = read_type (pp, objfile);
3037 create_range_type ((struct type *) NULL, index_type, lower, upper);
3038 type = create_array_type (type, element_type, range_type);
3044 /* Read a definition of an enumeration type,
3045 and create and return a suitable type object.
3046 Also defines the symbols that represent the values of the type. */
3048 static struct type *
3049 read_enum_type (pp, type, objfile)
3051 register struct type *type;
3052 struct objfile *objfile;
3057 register struct symbol *sym;
3059 struct pending **symlist;
3060 struct pending *osyms, *syms;
3063 int unsigned_enum = 1;
3066 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3067 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3068 to do? For now, force all enum values to file scope. */
3069 if (within_function)
3070 symlist = &local_symbols;
3073 symlist = &file_symbols;
3075 o_nsyms = osyms ? osyms->nsyms : 0;
3079 /* Size. Perhaps this does not have to be conditionalized on
3080 os9k_stabs (assuming the name of an enum constant can't start
3082 read_huge_number (pp, 0, &nbits);
3084 return error_type (pp, objfile);
3087 /* The aix4 compiler emits an extra field before the enum members;
3088 my guess is it's a type of some sort. Just ignore it. */
3091 /* Skip over the type. */
3095 /* Skip over the colon. */
3099 /* Read the value-names and their values.
3100 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3101 A semicolon or comma instead of a NAME means the end. */
3102 while (**pp && **pp != ';' && **pp != ',')
3104 STABS_CONTINUE (pp, objfile);
3106 while (*p != ':') p++;
3107 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
3109 n = read_huge_number (pp, ',', &nbits);
3111 return error_type (pp, objfile);
3113 sym = (struct symbol *)
3114 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
3115 memset (sym, 0, sizeof (struct symbol));
3116 SYMBOL_NAME (sym) = name;
3117 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
3118 SYMBOL_CLASS (sym) = LOC_CONST;
3119 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3120 SYMBOL_VALUE (sym) = n;
3123 add_symbol_to_list (sym, symlist);
3128 (*pp)++; /* Skip the semicolon. */
3130 /* Now fill in the fields of the type-structure. */
3132 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
3133 TYPE_CODE (type) = TYPE_CODE_ENUM;
3134 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3136 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
3137 TYPE_NFIELDS (type) = nsyms;
3138 TYPE_FIELDS (type) = (struct field *)
3139 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
3140 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
3142 /* Find the symbols for the values and put them into the type.
3143 The symbols can be found in the symlist that we put them on
3144 to cause them to be defined. osyms contains the old value
3145 of that symlist; everything up to there was defined by us. */
3146 /* Note that we preserve the order of the enum constants, so
3147 that in something like "enum {FOO, LAST_THING=FOO}" we print
3148 FOO, not LAST_THING. */
3150 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
3152 int last = syms == osyms ? o_nsyms : 0;
3153 int j = syms->nsyms;
3154 for (; --j >= last; --n)
3156 struct symbol *xsym = syms->symbol[j];
3157 SYMBOL_TYPE (xsym) = type;
3158 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
3159 TYPE_FIELD_VALUE (type, n) = 0;
3160 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
3161 TYPE_FIELD_BITSIZE (type, n) = 0;
3170 /* Sun's ACC uses a somewhat saner method for specifying the builtin
3171 typedefs in every file (for int, long, etc):
3173 type = b <signed> <width>; <offset>; <nbits>
3174 signed = u or s. Possible c in addition to u or s (for char?).
3175 offset = offset from high order bit to start bit of type.
3176 width is # bytes in object of this type, nbits is # bits in type.
3178 The width/offset stuff appears to be for small objects stored in
3179 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3182 static struct type *
3183 read_sun_builtin_type (pp, typenums, objfile)
3186 struct objfile *objfile;
3201 return error_type (pp, objfile);
3205 /* For some odd reason, all forms of char put a c here. This is strange
3206 because no other type has this honor. We can safely ignore this because
3207 we actually determine 'char'acterness by the number of bits specified in
3213 /* The first number appears to be the number of bytes occupied
3214 by this type, except that unsigned short is 4 instead of 2.
3215 Since this information is redundant with the third number,
3216 we will ignore it. */
3217 read_huge_number (pp, ';', &nbits);
3219 return error_type (pp, objfile);
3221 /* The second number is always 0, so ignore it too. */
3222 read_huge_number (pp, ';', &nbits);
3224 return error_type (pp, objfile);
3226 /* The third number is the number of bits for this type. */
3227 type_bits = read_huge_number (pp, 0, &nbits);
3229 return error_type (pp, objfile);
3230 /* The type *should* end with a semicolon. If it are embedded
3231 in a larger type the semicolon may be the only way to know where
3232 the type ends. If this type is at the end of the stabstring we
3233 can deal with the omitted semicolon (but we don't have to like
3234 it). Don't bother to complain(), Sun's compiler omits the semicolon
3240 return init_type (TYPE_CODE_VOID, 1,
3241 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
3244 return init_type (TYPE_CODE_INT,
3245 type_bits / TARGET_CHAR_BIT,
3246 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
3250 static struct type *
3251 read_sun_floating_type (pp, typenums, objfile)
3254 struct objfile *objfile;
3260 /* The first number has more details about the type, for example
3262 details = read_huge_number (pp, ';', &nbits);
3264 return error_type (pp, objfile);
3266 /* The second number is the number of bytes occupied by this type */
3267 nbytes = read_huge_number (pp, ';', &nbits);
3269 return error_type (pp, objfile);
3271 if (details == NF_COMPLEX || details == NF_COMPLEX16
3272 || details == NF_COMPLEX32)
3273 /* This is a type we can't handle, but we do know the size.
3274 We also will be able to give it a name. */
3275 return init_type (TYPE_CODE_ERROR, nbytes, 0, NULL, objfile);
3277 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
3280 /* Read a number from the string pointed to by *PP.
3281 The value of *PP is advanced over the number.
3282 If END is nonzero, the character that ends the
3283 number must match END, or an error happens;
3284 and that character is skipped if it does match.
3285 If END is zero, *PP is left pointing to that character.
3287 If the number fits in a long, set *BITS to 0 and return the value.
3288 If not, set *BITS to be the number of bits in the number and return 0.
3290 If encounter garbage, set *BITS to -1 and return 0. */
3293 read_huge_number (pp, end, bits)
3313 /* Leading zero means octal. GCC uses this to output values larger
3314 than an int (because that would be hard in decimal). */
3322 upper_limit = ULONG_MAX / radix;
3324 upper_limit = LONG_MAX / radix;
3326 while ((c = *p++) >= '0' && c < ('0' + radix))
3328 if (n <= upper_limit)
3331 n += c - '0'; /* FIXME this overflows anyway */
3336 /* This depends on large values being output in octal, which is
3343 /* Ignore leading zeroes. */
3347 else if (c == '2' || c == '3')
3373 /* Large decimal constants are an error (because it is hard to
3374 count how many bits are in them). */
3380 /* -0x7f is the same as 0x80. So deal with it by adding one to
3381 the number of bits. */
3393 /* It's *BITS which has the interesting information. */
3397 static struct type *
3398 read_range_type (pp, typenums, objfile)
3401 struct objfile *objfile;
3403 char *orig_pp = *pp;
3408 struct type *result_type;
3409 struct type *index_type = NULL;
3411 /* First comes a type we are a subrange of.
3412 In C it is usually 0, 1 or the type being defined. */
3413 if (read_type_number (pp, rangenums) != 0)
3414 return error_type (pp, objfile);
3415 self_subrange = (rangenums[0] == typenums[0] &&
3416 rangenums[1] == typenums[1]);
3421 index_type = read_type (pp, objfile);
3424 /* A semicolon should now follow; skip it. */
3428 /* The remaining two operands are usually lower and upper bounds
3429 of the range. But in some special cases they mean something else. */
3430 n2 = read_huge_number (pp, ';', &n2bits);
3431 n3 = read_huge_number (pp, ';', &n3bits);
3433 if (n2bits == -1 || n3bits == -1)
3434 return error_type (pp, objfile);
3437 goto handle_true_range;
3439 /* If limits are huge, must be large integral type. */
3440 if (n2bits != 0 || n3bits != 0)
3442 char got_signed = 0;
3443 char got_unsigned = 0;
3444 /* Number of bits in the type. */
3447 /* Range from 0 to <large number> is an unsigned large integral type. */
3448 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
3453 /* Range from <large number> to <large number>-1 is a large signed
3454 integral type. Take care of the case where <large number> doesn't
3455 fit in a long but <large number>-1 does. */
3456 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
3457 || (n2bits != 0 && n3bits == 0
3458 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
3465 if (got_signed || got_unsigned)
3467 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
3468 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
3472 return error_type (pp, objfile);
3475 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3476 if (self_subrange && n2 == 0 && n3 == 0)
3477 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
3479 /* If n3 is zero and n2 is positive, we want a floating type,
3480 and n2 is the width in bytes.
3482 Fortran programs appear to use this for complex types also,
3483 and they give no way to distinguish between double and single-complex!
3485 GDB does not have complex types.
3487 Just return the complex as a float of that size. It won't work right
3488 for the complex values, but at least it makes the file loadable. */
3490 if (n3 == 0 && n2 > 0)
3492 return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
3495 /* If the upper bound is -1, it must really be an unsigned int. */
3497 else if (n2 == 0 && n3 == -1)
3499 /* It is unsigned int or unsigned long. */
3500 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3501 compatibility hack. */
3502 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3503 TYPE_FLAG_UNSIGNED, NULL, objfile);
3506 /* Special case: char is defined (Who knows why) as a subrange of
3507 itself with range 0-127. */
3508 else if (self_subrange && n2 == 0 && n3 == 127)
3509 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
3511 else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill
3513 goto handle_true_range;
3515 /* We used to do this only for subrange of self or subrange of int. */
3519 /* n3 actually gives the size. */
3520 return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED,
3523 return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile);
3525 return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile);
3527 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3528 "unsigned long", and we already checked for that,
3529 so don't need to test for it here. */
3531 /* I think this is for Convex "long long". Since I don't know whether
3532 Convex sets self_subrange, I also accept that particular size regardless
3533 of self_subrange. */
3534 else if (n3 == 0 && n2 < 0
3536 || n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
3537 return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile);
3538 else if (n2 == -n3 -1)
3541 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
3543 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
3544 if (n3 == 0x7fffffff)
3545 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
3548 /* We have a real range type on our hands. Allocate space and
3549 return a real pointer. */
3553 index_type = builtin_type_int;
3555 index_type = *dbx_lookup_type (rangenums);
3556 if (index_type == NULL)
3558 /* Does this actually ever happen? Is that why we are worrying
3559 about dealing with it rather than just calling error_type? */
3561 static struct type *range_type_index;
3563 complain (&range_type_base_complaint, rangenums[1]);
3564 if (range_type_index == NULL)
3566 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3567 0, "range type index type", NULL);
3568 index_type = range_type_index;
3571 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
3572 return (result_type);
3575 /* Read in an argument list. This is a list of types, separated by commas
3576 and terminated with END. Return the list of types read in, or (struct type
3577 **)-1 if there is an error. */
3579 static struct type **
3580 read_args (pp, end, objfile)
3583 struct objfile *objfile;
3585 /* FIXME! Remove this arbitrary limit! */
3586 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
3592 /* Invalid argument list: no ','. */
3593 return (struct type **)-1;
3595 STABS_CONTINUE (pp, objfile);
3596 types[n++] = read_type (pp, objfile);
3598 (*pp)++; /* get past `end' (the ':' character) */
3602 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3604 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3606 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3607 memset (rval + n, 0, sizeof (struct type *));
3611 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3613 memcpy (rval, types, n * sizeof (struct type *));
3617 /* Common block handling. */
3619 /* List of symbols declared since the last BCOMM. This list is a tail
3620 of local_symbols. When ECOMM is seen, the symbols on the list
3621 are noted so their proper addresses can be filled in later,
3622 using the common block base address gotten from the assembler
3625 static struct pending *common_block;
3626 static int common_block_i;
3628 /* Name of the current common block. We get it from the BCOMM instead of the
3629 ECOMM to match IBM documentation (even though IBM puts the name both places
3630 like everyone else). */
3631 static char *common_block_name;
3633 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3634 to remain after this function returns. */
3637 common_block_start (name, objfile)
3639 struct objfile *objfile;
3641 if (common_block_name != NULL)
3643 static struct complaint msg = {
3644 "Invalid symbol data: common block within common block",
3648 common_block = local_symbols;
3649 common_block_i = local_symbols ? local_symbols->nsyms : 0;
3650 common_block_name = obsavestring (name, strlen (name),
3651 &objfile -> symbol_obstack);
3654 /* Process a N_ECOMM symbol. */
3657 common_block_end (objfile)
3658 struct objfile *objfile;
3660 /* Symbols declared since the BCOMM are to have the common block
3661 start address added in when we know it. common_block and
3662 common_block_i point to the first symbol after the BCOMM in
3663 the local_symbols list; copy the list and hang it off the
3664 symbol for the common block name for later fixup. */
3667 struct pending *new = 0;
3668 struct pending *next;
3671 if (common_block_name == NULL)
3673 static struct complaint msg = {"ECOMM symbol unmatched by BCOMM", 0, 0};
3678 sym = (struct symbol *)
3679 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
3680 memset (sym, 0, sizeof (struct symbol));
3681 SYMBOL_NAME (sym) = common_block_name;
3682 SYMBOL_CLASS (sym) = LOC_BLOCK;
3684 /* Now we copy all the symbols which have been defined since the BCOMM. */
3686 /* Copy all the struct pendings before common_block. */
3687 for (next = local_symbols;
3688 next != NULL && next != common_block;
3691 for (j = 0; j < next->nsyms; j++)
3692 add_symbol_to_list (next->symbol[j], &new);
3695 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3696 NULL, it means copy all the local symbols (which we already did
3699 if (common_block != NULL)
3700 for (j = common_block_i; j < common_block->nsyms; j++)
3701 add_symbol_to_list (common_block->symbol[j], &new);
3703 SYMBOL_TYPE (sym) = (struct type *) new;
3705 /* Should we be putting local_symbols back to what it was?
3708 i = hashname (SYMBOL_NAME (sym));
3709 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
3710 global_sym_chain[i] = sym;
3711 common_block_name = NULL;
3714 /* Add a common block's start address to the offset of each symbol
3715 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3716 the common block name). */
3719 fix_common_block (sym, valu)
3723 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
3724 for ( ; next; next = next->next)
3727 for (j = next->nsyms - 1; j >= 0; j--)
3728 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3734 /* What about types defined as forward references inside of a small lexical
3736 /* Add a type to the list of undefined types to be checked through
3737 once this file has been read in. */
3740 add_undefined_type (type)
3743 if (undef_types_length == undef_types_allocated)
3745 undef_types_allocated *= 2;
3746 undef_types = (struct type **)
3747 xrealloc ((char *) undef_types,
3748 undef_types_allocated * sizeof (struct type *));
3750 undef_types[undef_types_length++] = type;
3753 /* Go through each undefined type, see if it's still undefined, and fix it
3754 up if possible. We have two kinds of undefined types:
3756 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3757 Fix: update array length using the element bounds
3758 and the target type's length.
3759 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3760 yet defined at the time a pointer to it was made.
3761 Fix: Do a full lookup on the struct/union tag. */
3763 cleanup_undefined_types ()
3767 for (type = undef_types; type < undef_types + undef_types_length; type++)
3769 switch (TYPE_CODE (*type))
3772 case TYPE_CODE_STRUCT:
3773 case TYPE_CODE_UNION:
3774 case TYPE_CODE_ENUM:
3776 /* Check if it has been defined since. Need to do this here
3777 as well as in check_typedef to deal with the (legitimate in
3778 C though not C++) case of several types with the same name
3779 in different source files. */
3780 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
3782 struct pending *ppt;
3784 /* Name of the type, without "struct" or "union" */
3785 char *typename = TYPE_TAG_NAME (*type);
3787 if (typename == NULL)
3789 static struct complaint msg = {"need a type name", 0, 0};
3793 for (ppt = file_symbols; ppt; ppt = ppt->next)
3795 for (i = 0; i < ppt->nsyms; i++)
3797 struct symbol *sym = ppt->symbol[i];
3799 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3800 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
3801 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
3803 && STREQ (SYMBOL_NAME (sym), typename))
3805 memcpy (*type, SYMBOL_TYPE (sym),
3806 sizeof (struct type));
3817 static struct complaint msg = {"\
3818 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3819 complain (&msg, TYPE_CODE (*type));
3825 undef_types_length = 0;
3828 /* Scan through all of the global symbols defined in the object file,
3829 assigning values to the debugging symbols that need to be assigned
3830 to. Get these symbols from the minimal symbol table. */
3833 scan_file_globals (objfile)
3834 struct objfile *objfile;
3837 struct minimal_symbol *msymbol;
3838 struct symbol *sym, *prev;
3840 /* Avoid expensive loop through all minimal symbols if there are
3841 no unresolved symbols. */
3842 for (hash = 0; hash < HASHSIZE; hash++)
3844 if (global_sym_chain[hash])
3847 if (hash >= HASHSIZE)
3850 for (msymbol = objfile -> msymbols;
3851 msymbol && SYMBOL_NAME (msymbol) != NULL;
3856 /* Skip static symbols. */
3857 switch (MSYMBOL_TYPE (msymbol))
3869 /* Get the hash index and check all the symbols
3870 under that hash index. */
3872 hash = hashname (SYMBOL_NAME (msymbol));
3874 for (sym = global_sym_chain[hash]; sym;)
3876 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
3877 STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
3879 /* Splice this symbol out of the hash chain and
3880 assign the value we have to it. */
3883 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
3887 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
3890 /* Check to see whether we need to fix up a common block. */
3891 /* Note: this code might be executed several times for
3892 the same symbol if there are multiple references. */
3894 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3896 fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol));
3900 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol);
3903 SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol);
3907 sym = SYMBOL_VALUE_CHAIN (prev);
3911 sym = global_sym_chain[hash];
3917 sym = SYMBOL_VALUE_CHAIN (sym);
3922 /* Change the storage class of any remaining unresolved globals to
3923 LOC_UNRESOLVED and remove them from the chain. */
3924 for (hash = 0; hash < HASHSIZE; hash++)
3926 sym = global_sym_chain[hash];
3930 sym = SYMBOL_VALUE_CHAIN (sym);
3932 /* Change the symbol address from the misleading chain value
3934 SYMBOL_VALUE_ADDRESS (prev) = 0;
3936 /* Complain about unresolved common block symbols. */
3937 if (SYMBOL_CLASS (prev) == LOC_STATIC)
3938 SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
3940 complain (&unresolved_sym_chain_complaint,
3941 objfile->name, SYMBOL_NAME (prev));
3944 memset (global_sym_chain, 0, sizeof (global_sym_chain));
3947 /* Initialize anything that needs initializing when starting to read
3948 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3956 /* Initialize anything that needs initializing when a completely new
3957 symbol file is specified (not just adding some symbols from another
3958 file, e.g. a shared library). */
3961 stabsread_new_init ()
3963 /* Empty the hash table of global syms looking for values. */
3964 memset (global_sym_chain, 0, sizeof (global_sym_chain));
3967 /* Initialize anything that needs initializing at the same time as
3968 start_symtab() is called. */
3972 global_stabs = NULL; /* AIX COFF */
3973 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3974 n_this_object_header_files = 1;
3975 type_vector_length = 0;
3976 type_vector = (struct type **) 0;
3978 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3979 common_block_name = NULL;
3984 /* Call after end_symtab() */
3990 free ((char *) type_vector);
3993 type_vector_length = 0;
3994 previous_stab_code = 0;
3998 finish_global_stabs (objfile)
3999 struct objfile *objfile;
4003 patch_block_stabs (global_symbols, global_stabs, objfile);
4004 free ((PTR) global_stabs);
4005 global_stabs = NULL;
4009 /* Initializer for this module */
4012 _initialize_stabsread ()
4014 undef_types_allocated = 20;
4015 undef_types_length = 0;
4016 undef_types = (struct type **)
4017 xmalloc (undef_types_allocated * sizeof (struct type *));