Use struct bfd_seclet * rather than bfd_seclet_type in prototypes to
[deliverable/binutils-gdb.git] / gdb / stabsread.c
1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
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. */
26
27 #include "defs.h"
28 #include "bfd.h"
29 #include "obstack.h"
30 #include "symtab.h"
31 #include "gdbtypes.h"
32 #include "symfile.h"
33 #include "objfiles.h"
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
35 #include "buildsym.h"
36 #include "complaints.h"
37 #include "demangle.h"
38
39 /* Ask stabsread.h to define the vars it normally declares `extern'. */
40 #define EXTERN /**/
41 #include "stabsread.h" /* Our own declarations */
42 #undef EXTERN
43
44 /* The routines that read and process a complete stabs for a C struct or
45 C++ class pass lists of data member fields and lists of member function
46 fields in an instance of a field_info structure, as defined below.
47 This is part of some reorganization of low level C++ support and is
48 expected to eventually go away... (FIXME) */
49
50 struct field_info
51 {
52 struct nextfield
53 {
54 struct nextfield *next;
55 int visibility;
56 struct field field;
57 } *list;
58 struct next_fnfieldlist
59 {
60 struct next_fnfieldlist *next;
61 struct fn_fieldlist fn_fieldlist;
62 } *fnlist;
63 };
64
65 static struct type *
66 dbx_alloc_type PARAMS ((int [2], struct objfile *));
67
68 static void
69 read_huge_number PARAMS ((char **, int, long *, int *));
70
71 static void
72 patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
73 struct objfile *));
74
75 static void
76 fix_common_block PARAMS ((struct symbol *, int));
77
78 static struct type *
79 read_range_type PARAMS ((char **, int [2], struct objfile *));
80
81 static struct type *
82 read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *));
83
84 static struct type *
85 read_sun_floating_type PARAMS ((char **, int [2], struct objfile *));
86
87 static struct type *
88 read_enum_type PARAMS ((char **, struct type *, struct objfile *));
89
90 static int
91 read_member_functions PARAMS ((struct field_info *, char **, struct type *,
92 struct objfile *));
93
94 static int
95 read_struct_fields PARAMS ((struct field_info *, char **, struct type *,
96 struct objfile *));
97
98 static int
99 read_baseclasses PARAMS ((struct field_info *, char **, struct type *,
100 struct objfile *));
101
102 static int
103 read_tilde_fields PARAMS ((struct field_info *, char **, struct type *,
104 struct objfile *));
105
106 static int
107 attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *));
108
109 static int
110 attach_fields_to_type PARAMS ((struct field_info *, struct type *,
111 struct objfile *));
112
113 static struct type *
114 read_struct_type PARAMS ((char **, struct type *, struct objfile *));
115
116 static struct type *
117 read_array_type PARAMS ((char **, struct type *, struct objfile *));
118
119 static struct type **
120 read_args PARAMS ((char **, int, struct objfile *));
121
122 static void
123 read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *,
124 struct objfile *));
125
126 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
127 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
128
129 /* Define this as 1 if a pcc declaration of a char or short argument
130 gives the correct address. Otherwise assume pcc gives the
131 address of the corresponding int, which is not the same on a
132 big-endian machine. */
133
134 #ifndef BELIEVE_PCC_PROMOTION
135 #define BELIEVE_PCC_PROMOTION 0
136 #endif
137
138 /* During some calls to read_type (and thus to read_range_type), this
139 contains the name of the type being defined. Range types are only
140 used in C as basic types. We use the name to distinguish the otherwise
141 identical basic types "int" and "long" and their unsigned versions.
142 FIXME, this should disappear with better type management. */
143
144 static char *long_kludge_name;
145
146 #if 0
147 struct complaint dbx_class_complaint =
148 {
149 "encountered DBX-style class variable debugging information.\n\
150 You seem to have compiled your program with \
151 \"g++ -g0\" instead of \"g++ -g\".\n\
152 Therefore GDB will not know about your class variables", 0, 0
153 };
154 #endif
155
156 struct complaint invalid_cpp_abbrev_complaint =
157 {"invalid C++ abbreviation `%s'", 0, 0};
158
159 struct complaint invalid_cpp_type_complaint =
160 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
161
162 struct complaint member_fn_complaint =
163 {"member function type missing, got '%c'", 0, 0};
164
165 struct complaint const_vol_complaint =
166 {"const/volatile indicator missing, got '%c'", 0, 0};
167
168 struct complaint error_type_complaint =
169 {"debug info mismatch between compiler and debugger", 0, 0};
170
171 struct complaint invalid_member_complaint =
172 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
173
174 struct complaint range_type_base_complaint =
175 {"base type %d of range type is not defined", 0, 0};
176
177 struct complaint reg_value_complaint =
178 {"register number too large in symbol %s", 0, 0};
179
180 struct complaint stabs_general_complaint =
181 {"%s", 0, 0};
182
183 /* Make a list of forward references which haven't been defined. */
184
185 static struct type **undef_types;
186 static int undef_types_allocated;
187 static int undef_types_length;
188
189 /* Check for and handle cretinous stabs symbol name continuation! */
190 #define STABS_CONTINUE(pp) \
191 do { \
192 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
193 } while (0)
194
195 \f
196 int
197 hashname (name)
198 char *name;
199 {
200 register char *p = name;
201 register int total = p[0];
202 register int c;
203
204 c = p[1];
205 total += c << 2;
206 if (c)
207 {
208 c = p[2];
209 total += c << 4;
210 if (c)
211 {
212 total += p[3] << 6;
213 }
214 }
215
216 /* Ensure result is positive. */
217 if (total < 0)
218 {
219 total += (1000 << 6);
220 }
221 return (total % HASHSIZE);
222 }
223
224 \f
225 /* Look up a dbx type-number pair. Return the address of the slot
226 where the type for that number-pair is stored.
227 The number-pair is in TYPENUMS.
228
229 This can be used for finding the type associated with that pair
230 or for associating a new type with the pair. */
231
232 struct type **
233 dbx_lookup_type (typenums)
234 int typenums[2];
235 {
236 register int filenum = typenums[0];
237 register int index = typenums[1];
238 unsigned old_len;
239 register int real_filenum;
240 register struct header_file *f;
241 int f_orig_length;
242
243 if (filenum == -1) /* -1,-1 is for temporary types. */
244 return 0;
245
246 if (filenum < 0 || filenum >= n_this_object_header_files)
247 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
248 filenum, index, symnum);
249
250 if (filenum == 0)
251 {
252 /* Type is defined outside of header files.
253 Find it in this object file's type vector. */
254 if (index >= type_vector_length)
255 {
256 old_len = type_vector_length;
257 if (old_len == 0)
258 {
259 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
260 type_vector = (struct type **)
261 malloc (type_vector_length * sizeof (struct type *));
262 }
263 while (index >= type_vector_length)
264 {
265 type_vector_length *= 2;
266 }
267 type_vector = (struct type **)
268 xrealloc ((char *) type_vector,
269 (type_vector_length * sizeof (struct type *)));
270 memset (&type_vector[old_len], 0,
271 (type_vector_length - old_len) * sizeof (struct type *));
272 }
273 return (&type_vector[index]);
274 }
275 else
276 {
277 real_filenum = this_object_header_files[filenum];
278
279 if (real_filenum >= n_header_files)
280 {
281 abort ();
282 }
283
284 f = &header_files[real_filenum];
285
286 f_orig_length = f->length;
287 if (index >= f_orig_length)
288 {
289 while (index >= f->length)
290 {
291 f->length *= 2;
292 }
293 f->vector = (struct type **)
294 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
295 memset (&f->vector[f_orig_length], 0,
296 (f->length - f_orig_length) * sizeof (struct type *));
297 }
298 return (&f->vector[index]);
299 }
300 }
301
302 /* Make sure there is a type allocated for type numbers TYPENUMS
303 and return the type object.
304 This can create an empty (zeroed) type object.
305 TYPENUMS may be (-1, -1) to return a new type object that is not
306 put into the type vector, and so may not be referred to by number. */
307
308 static struct type *
309 dbx_alloc_type (typenums, objfile)
310 int typenums[2];
311 struct objfile *objfile;
312 {
313 register struct type **type_addr;
314
315 if (typenums[0] == -1)
316 {
317 return (alloc_type (objfile));
318 }
319
320 type_addr = dbx_lookup_type (typenums);
321
322 /* If we are referring to a type not known at all yet,
323 allocate an empty type for it.
324 We will fill it in later if we find out how. */
325 if (*type_addr == 0)
326 {
327 *type_addr = alloc_type (objfile);
328 }
329
330 return (*type_addr);
331 }
332
333 /* for all the stabs in a given stab vector, build appropriate types
334 and fix their symbols in given symbol vector. */
335
336 static void
337 patch_block_stabs (symbols, stabs, objfile)
338 struct pending *symbols;
339 struct pending_stabs *stabs;
340 struct objfile *objfile;
341 {
342 int ii;
343 char *name;
344 char *pp;
345 struct symbol *sym;
346
347 if (stabs)
348 {
349
350 /* for all the stab entries, find their corresponding symbols and
351 patch their types! */
352
353 for (ii = 0; ii < stabs->count; ++ii)
354 {
355 name = stabs->stab[ii];
356 pp = (char*) strchr (name, ':');
357 sym = find_symbol_in_list (symbols, name, pp-name);
358 if (!sym)
359 {
360 #ifndef IBM6000_TARGET
361 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
362 #endif
363 }
364 else
365 {
366 pp += 2;
367 if (*(pp-1) == 'F' || *(pp-1) == 'f')
368 {
369 SYMBOL_TYPE (sym) =
370 lookup_function_type (read_type (&pp, objfile));
371 }
372 else
373 {
374 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
375 }
376 }
377 }
378 }
379 }
380
381 \f
382 /* Read a number by which a type is referred to in dbx data,
383 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
384 Just a single number N is equivalent to (0,N).
385 Return the two numbers by storing them in the vector TYPENUMS.
386 TYPENUMS will then be used as an argument to dbx_lookup_type. */
387
388 void
389 read_type_number (pp, typenums)
390 register char **pp;
391 register int *typenums;
392 {
393 if (**pp == '(')
394 {
395 (*pp)++;
396 typenums[0] = read_number (pp, ',');
397 typenums[1] = read_number (pp, ')');
398 }
399 else
400 {
401 typenums[0] = 0;
402 typenums[1] = read_number (pp, 0);
403 }
404 }
405
406 \f
407 /* To handle GNU C++ typename abbreviation, we need to be able to
408 fill in a type's name as soon as space for that type is allocated.
409 `type_synonym_name' is the name of the type being allocated.
410 It is cleared as soon as it is used (lest all allocated types
411 get this name). */
412
413 static char *type_synonym_name;
414
415 /* ARGSUSED */
416 struct symbol *
417 define_symbol (valu, string, desc, type, objfile)
418 unsigned int valu;
419 char *string;
420 int desc;
421 int type;
422 struct objfile *objfile;
423 {
424 register struct symbol *sym;
425 char *p = (char *) strchr (string, ':');
426 int deftype;
427 int synonym = 0;
428 register int i;
429 struct type *temptype;
430
431 /* We would like to eliminate nameless symbols, but keep their types.
432 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
433 to type 2, but, should not create a symbol to address that type. Since
434 the symbol will be nameless, there is no way any user can refer to it. */
435
436 int nameless;
437
438 /* Ignore syms with empty names. */
439 if (string[0] == 0)
440 return 0;
441
442 /* Ignore old-style symbols from cc -go */
443 if (p == 0)
444 return 0;
445
446 /* If a nameless stab entry, all we need is the type, not the symbol.
447 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
448 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
449
450 sym = (struct symbol *)
451 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
452 memset (sym, 0, sizeof (struct symbol));
453
454 if (processing_gcc_compilation)
455 {
456 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
457 number of bytes occupied by a type or object, which we ignore. */
458 SYMBOL_LINE(sym) = desc;
459 }
460 else
461 {
462 SYMBOL_LINE(sym) = 0; /* unknown */
463 }
464
465 if (string[0] == CPLUS_MARKER)
466 {
467 /* Special GNU C++ names. */
468 switch (string[1])
469 {
470 case 't':
471 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
472 &objfile -> symbol_obstack);
473 break;
474
475 case 'v': /* $vtbl_ptr_type */
476 /* Was: SYMBOL_NAME (sym) = "vptr"; */
477 goto normal;
478
479 case 'e':
480 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
481 &objfile -> symbol_obstack);
482 break;
483
484 case '_':
485 /* This was an anonymous type that was never fixed up. */
486 goto normal;
487
488 default:
489 abort ();
490 }
491 }
492 else
493 {
494 normal:
495 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
496 SYMBOL_NAME (sym) = (char *)
497 obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
498 /* Open-coded bcopy--saves function call time. */
499 /* FIXME: Does it really? Try replacing with simple strcpy and
500 try it on an executable with a large symbol table. */
501 {
502 register char *p1 = string;
503 register char *p2 = SYMBOL_NAME (sym);
504 while (p1 != p)
505 {
506 *p2++ = *p1++;
507 }
508 *p2++ = '\0';
509 }
510
511 /* If this symbol is from a C++ compilation, then attempt to cache the
512 demangled form for future reference. This is a typical time versus
513 space tradeoff, that was decided in favor of time because it sped up
514 C++ symbol lookups by a factor of about 20. */
515
516 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
517 }
518 p++;
519
520 /* Determine the type of name being defined. */
521 /* The Acorn RISC machine's compiler can put out locals that don't
522 start with "234=" or "(3,4)=", so assume anything other than the
523 deftypes we know how to handle is a local. */
524 if (!strchr ("cfFGpPrStTvVXCR", *p))
525 deftype = 'l';
526 else
527 deftype = *p++;
528
529 /* c is a special case, not followed by a type-number.
530 SYMBOL:c=iVALUE for an integer constant symbol.
531 SYMBOL:c=rVALUE for a floating constant symbol.
532 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
533 e.g. "b:c=e6,0" for "const b = blob1"
534 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
535 if (deftype == 'c')
536 {
537 if (*p++ != '=')
538 error ("Invalid symbol data at symtab pos %d.", symnum);
539 switch (*p++)
540 {
541 case 'r':
542 {
543 double d = atof (p);
544 char *dbl_valu;
545
546 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
547 FT_DBL_PREC_FLOAT);
548 dbl_valu = (char *)
549 obstack_alloc (&objfile -> symbol_obstack, sizeof (double));
550 memcpy (dbl_valu, &d, sizeof (double));
551 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
552 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
553 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
554 }
555 break;
556 case 'i':
557 {
558 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
559 FT_INTEGER);
560 SYMBOL_VALUE (sym) = atoi (p);
561 SYMBOL_CLASS (sym) = LOC_CONST;
562 }
563 break;
564 case 'e':
565 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
566 e.g. "b:c=e6,0" for "const b = blob1"
567 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
568 {
569 int typenums[2];
570
571 read_type_number (&p, typenums);
572 if (*p++ != ',')
573 error ("Invalid symbol data: no comma in enum const symbol");
574
575 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
576 SYMBOL_VALUE (sym) = atoi (p);
577 SYMBOL_CLASS (sym) = LOC_CONST;
578 }
579 break;
580 default:
581 error ("Invalid symbol data at symtab pos %d.", symnum);
582 }
583 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
584 add_symbol_to_list (sym, &file_symbols);
585 return sym;
586 }
587
588 /* Now usually comes a number that says which data type,
589 and possibly more stuff to define the type
590 (all of which is handled by read_type) */
591
592 if (deftype == 'p' && *p == 'F')
593 /* pF is a two-letter code that means a function parameter in Fortran.
594 The type-number specifies the type of the return value.
595 Translate it into a pointer-to-function type. */
596 {
597 p++;
598 SYMBOL_TYPE (sym)
599 = lookup_pointer_type (lookup_function_type (read_type (&p, objfile)));
600 }
601 else
602 {
603 /* The symbol class letter is followed by a type (typically the
604 type of the symbol, or its return-type, or etc). Read it. */
605
606 synonym = *p == 't';
607
608 if (synonym)
609 {
610 p++;
611 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
612 strlen (SYMBOL_NAME (sym)),
613 &objfile -> symbol_obstack);
614 }
615
616 /* Here we save the name of the symbol for read_range_type, which
617 ends up reading in the basic types. In stabs, unfortunately there
618 is no distinction between "int" and "long" types except their
619 names. Until we work out a saner type policy (eliminating most
620 builtin types and using the names specified in the files), we
621 save away the name so that far away from here in read_range_type,
622 we can examine it to decide between "int" and "long". FIXME. */
623 long_kludge_name = SYMBOL_NAME (sym);
624
625 SYMBOL_TYPE (sym) = read_type (&p, objfile);
626 }
627
628 switch (deftype)
629 {
630 case 'C':
631 /* The name of a caught exception. */
632 SYMBOL_CLASS (sym) = LOC_LABEL;
633 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
634 SYMBOL_VALUE_ADDRESS (sym) = valu;
635 add_symbol_to_list (sym, &local_symbols);
636 break;
637
638 case 'f':
639 /* A static function definition. */
640 SYMBOL_CLASS (sym) = LOC_BLOCK;
641 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
642 add_symbol_to_list (sym, &file_symbols);
643 /* fall into process_function_types. */
644
645 process_function_types:
646 /* Function result types are described as the result type in stabs.
647 We need to convert this to the function-returning-type-X type
648 in GDB. E.g. "int" is converted to "function returning int". */
649 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
650 {
651 #if 0
652 /* This code doesn't work -- it needs to realloc and can't. */
653 /* Attempt to set up to record a function prototype... */
654 struct type *new = alloc_type (objfile);
655
656 /* Generate a template for the type of this function. The
657 types of the arguments will be added as we read the symbol
658 table. */
659 *new = *lookup_function_type (SYMBOL_TYPE(sym));
660 SYMBOL_TYPE(sym) = new;
661 TYPE_OBJFILE (new) = objfile;
662 in_function_type = new;
663 #else
664 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
665 #endif
666 }
667 /* fall into process_prototype_types */
668
669 process_prototype_types:
670 /* Sun acc puts declared types of arguments here. We don't care
671 about their actual types (FIXME -- we should remember the whole
672 function prototype), but the list may define some new types
673 that we have to remember, so we must scan it now. */
674 while (*p == ';') {
675 p++;
676 read_type (&p, objfile);
677 }
678 break;
679
680 case 'F':
681 /* A global function definition. */
682 SYMBOL_CLASS (sym) = LOC_BLOCK;
683 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
684 add_symbol_to_list (sym, &global_symbols);
685 goto process_function_types;
686
687 case 'G':
688 /* For a class G (global) symbol, it appears that the
689 value is not correct. It is necessary to search for the
690 corresponding linker definition to find the value.
691 These definitions appear at the end of the namelist. */
692 i = hashname (SYMBOL_NAME (sym));
693 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
694 global_sym_chain[i] = sym;
695 SYMBOL_CLASS (sym) = LOC_STATIC;
696 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
697 add_symbol_to_list (sym, &global_symbols);
698 break;
699
700 /* This case is faked by a conditional above,
701 when there is no code letter in the dbx data.
702 Dbx data never actually contains 'l'. */
703 case 'l':
704 SYMBOL_CLASS (sym) = LOC_LOCAL;
705 SYMBOL_VALUE (sym) = valu;
706 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
707 add_symbol_to_list (sym, &local_symbols);
708 break;
709
710 case 'p':
711 /* Normally this is a parameter, a LOC_ARG. On the i960, it
712 can also be a LOC_LOCAL_ARG depending on symbol type. */
713 #ifndef DBX_PARM_SYMBOL_CLASS
714 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
715 #endif
716 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
717 SYMBOL_VALUE (sym) = valu;
718 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
719 #if 0
720 /* This doesn't work yet. */
721 add_param_to_type (&in_function_type, sym);
722 #endif
723 add_symbol_to_list (sym, &local_symbols);
724
725 /* If it's gcc-compiled, if it says `short', believe it. */
726 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
727 break;
728
729 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
730 /* This macro is defined on machines (e.g. sparc) where
731 we should believe the type of a PCC 'short' argument,
732 but shouldn't believe the address (the address is
733 the address of the corresponding int). Note that
734 this is only different from the BELIEVE_PCC_PROMOTION
735 case on big-endian machines.
736
737 My guess is that this correction, as opposed to changing
738 the parameter to an 'int' (as done below, for PCC
739 on most machines), is the right thing to do
740 on all machines, but I don't want to risk breaking
741 something that already works. On most PCC machines,
742 the sparc problem doesn't come up because the calling
743 function has to zero the top bytes (not knowing whether
744 the called function wants an int or a short), so there
745 is no practical difference between an int and a short
746 (except perhaps what happens when the GDB user types
747 "print short_arg = 0x10000;").
748
749 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
750 actually produces the correct address (we don't need to fix it
751 up). I made this code adapt so that it will offset the symbol
752 if it was pointing at an int-aligned location and not
753 otherwise. This way you can use the same gdb for 4.0.x and
754 4.1 systems.
755
756 If the parameter is shorter than an int, and is integral
757 (e.g. char, short, or unsigned equivalent), and is claimed to
758 be passed on an integer boundary, don't believe it! Offset the
759 parameter's address to the tail-end of that integer. */
760
761 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
762 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
763 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
764 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
765 {
766 SYMBOL_VALUE (sym) += TYPE_LENGTH (temptype)
767 - TYPE_LENGTH (SYMBOL_TYPE (sym));
768 }
769 break;
770
771 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
772
773 /* If PCC says a parameter is a short or a char,
774 it is really an int. */
775 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
776 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
777 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
778 {
779 SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym))
780 ? lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER)
781 : temptype;
782 }
783 break;
784
785 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
786
787 case 'P':
788 /* acc seems to use P to delare the prototypes of functions that
789 are referenced by this file. gdb is not prepared to deal
790 with this extra information. FIXME, it ought to. */
791 if (type == N_FUN)
792 goto process_prototype_types;
793
794 /* Parameter which is in a register. */
795 SYMBOL_CLASS (sym) = LOC_REGPARM;
796 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
797 if (SYMBOL_VALUE (sym) >= NUM_REGS)
798 {
799 complain (&reg_value_complaint, SYMBOL_SOURCE_NAME (sym));
800 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
801 }
802 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
803 add_symbol_to_list (sym, &local_symbols);
804 break;
805
806 case 'R':
807 case 'r':
808 /* Register variable (either global or local). */
809 SYMBOL_CLASS (sym) = LOC_REGISTER;
810 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
811 if (SYMBOL_VALUE (sym) >= NUM_REGS)
812 {
813 complain (&reg_value_complaint, SYMBOL_SOURCE_NAME (sym));
814 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
815 }
816 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
817 if (within_function)
818 add_symbol_to_list (sym, &local_symbols);
819 else
820 add_symbol_to_list (sym, &file_symbols);
821 break;
822
823 case 'S':
824 /* Static symbol at top level of file */
825 SYMBOL_CLASS (sym) = LOC_STATIC;
826 SYMBOL_VALUE_ADDRESS (sym) = valu;
827 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
828 add_symbol_to_list (sym, &file_symbols);
829 break;
830
831 case 't':
832 /* For a nameless type, we don't want a create a symbol, thus we
833 did not use `sym'. Return without further processing. */
834 if (nameless) return NULL;
835
836 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
837 SYMBOL_VALUE (sym) = valu;
838 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
839 /* C++ vagaries: we may have a type which is derived from
840 a base type which did not have its name defined when the
841 derived class was output. We fill in the derived class's
842 base part member's name here in that case. */
843 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
844 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
845 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
846 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
847 {
848 int j;
849 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
850 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
851 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
852 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
853 }
854
855 add_symbol_to_list (sym, &file_symbols);
856 break;
857
858 case 'T':
859 /* For a nameless type, we don't want a create a symbol, thus we
860 did not use `sym'. Return without further processing. */
861 if (nameless) return NULL;
862
863 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
864 SYMBOL_VALUE (sym) = valu;
865 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
866 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
867 TYPE_NAME (SYMBOL_TYPE (sym))
868 = obconcat (&objfile -> type_obstack, "",
869 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
870 ? "enum "
871 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
872 ? "struct " : "union ")),
873 SYMBOL_NAME (sym));
874 add_symbol_to_list (sym, &file_symbols);
875
876 if (synonym)
877 {
878 /* Clone the sym and then modify it. */
879 register struct symbol *typedef_sym = (struct symbol *)
880 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
881 *typedef_sym = *sym;
882 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
883 SYMBOL_VALUE (typedef_sym) = valu;
884 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
885 add_symbol_to_list (typedef_sym, &file_symbols);
886 }
887 break;
888
889 case 'V':
890 /* Static symbol of local scope */
891 SYMBOL_CLASS (sym) = LOC_STATIC;
892 SYMBOL_VALUE_ADDRESS (sym) = valu;
893 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
894 add_symbol_to_list (sym, &local_symbols);
895 break;
896
897 case 'v':
898 /* Reference parameter */
899 SYMBOL_CLASS (sym) = LOC_REF_ARG;
900 SYMBOL_VALUE (sym) = valu;
901 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
902 add_symbol_to_list (sym, &local_symbols);
903 break;
904
905 case 'X':
906 /* This is used by Sun FORTRAN for "function result value".
907 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
908 that Pascal uses it too, but when I tried it Pascal used
909 "x:3" (local symbol) instead. */
910 SYMBOL_CLASS (sym) = LOC_LOCAL;
911 SYMBOL_VALUE (sym) = valu;
912 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
913 add_symbol_to_list (sym, &local_symbols);
914 break;
915
916 default:
917 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
918 }
919 return sym;
920 }
921
922 \f
923 /* Skip rest of this symbol and return an error type.
924
925 General notes on error recovery: error_type always skips to the
926 end of the symbol (modulo cretinous dbx symbol name continuation).
927 Thus code like this:
928
929 if (*(*pp)++ != ';')
930 return error_type (pp);
931
932 is wrong because if *pp starts out pointing at '\0' (typically as the
933 result of an earlier error), it will be incremented to point to the
934 start of the next symbol, which might produce strange results, at least
935 if you run off the end of the string table. Instead use
936
937 if (**pp != ';')
938 return error_type (pp);
939 ++*pp;
940
941 or
942
943 if (**pp != ';')
944 foo = error_type (pp);
945 else
946 ++*pp;
947
948 And in case it isn't obvious, the point of all this hair is so the compiler
949 can define new types and new syntaxes, and old versions of the
950 debugger will be able to read the new symbol tables. */
951
952 struct type *
953 error_type (pp)
954 char **pp;
955 {
956 complain (&error_type_complaint);
957 while (1)
958 {
959 /* Skip to end of symbol. */
960 while (**pp != '\0')
961 {
962 (*pp)++;
963 }
964
965 /* Check for and handle cretinous dbx symbol name continuation! */
966 if ((*pp)[-1] == '\\')
967 {
968 *pp = next_symbol_text ();
969 }
970 else
971 {
972 break;
973 }
974 }
975 return (builtin_type_error);
976 }
977
978 \f
979 /* Read a dbx type reference or definition;
980 return the type that is meant.
981 This can be just a number, in which case it references
982 a type already defined and placed in type_vector.
983 Or the number can be followed by an =, in which case
984 it means to define a new type according to the text that
985 follows the =. */
986
987 struct type *
988 read_type (pp, objfile)
989 register char **pp;
990 struct objfile *objfile;
991 {
992 register struct type *type = 0;
993 struct type *type1;
994 int typenums[2];
995 int xtypenums[2];
996 char type_descriptor;
997
998 /* Read type number if present. The type number may be omitted.
999 for instance in a two-dimensional array declared with type
1000 "ar1;1;10;ar1;1;10;4". */
1001 if ((**pp >= '0' && **pp <= '9')
1002 || **pp == '(')
1003 {
1004 read_type_number (pp, typenums);
1005
1006 /* Type is not being defined here. Either it already exists,
1007 or this is a forward reference to it. dbx_alloc_type handles
1008 both cases. */
1009 if (**pp != '=')
1010 return dbx_alloc_type (typenums, objfile);
1011
1012 /* Type is being defined here. */
1013 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1014 {
1015 struct type *tt;
1016
1017 /* if such a type already exists, this is an unnecessary duplication
1018 of the stab string, which is common in (RS/6000) xlc generated
1019 objects. In that case, simply return NULL and let the caller take
1020 care of it. */
1021
1022 tt = *dbx_lookup_type (typenums);
1023 if (tt && tt->length && tt->code)
1024 return NULL;
1025 }
1026 #endif
1027
1028 *pp += 2;
1029 }
1030 else
1031 {
1032 /* 'typenums=' not present, type is anonymous. Read and return
1033 the definition, but don't put it in the type vector. */
1034 typenums[0] = typenums[1] = -1;
1035 (*pp)++;
1036 }
1037
1038 type_descriptor = (*pp)[-1];
1039 switch (type_descriptor)
1040 {
1041 case 'x':
1042 {
1043 enum type_code code;
1044
1045 /* Used to index through file_symbols. */
1046 struct pending *ppt;
1047 int i;
1048
1049 /* Name including "struct", etc. */
1050 char *type_name;
1051
1052 /* Name without "struct", etc. */
1053 char *type_name_only;
1054
1055 {
1056 char *prefix;
1057 char *from, *to;
1058
1059 /* Set the type code according to the following letter. */
1060 switch ((*pp)[0])
1061 {
1062 case 's':
1063 code = TYPE_CODE_STRUCT;
1064 prefix = "struct ";
1065 break;
1066 case 'u':
1067 code = TYPE_CODE_UNION;
1068 prefix = "union ";
1069 break;
1070 case 'e':
1071 code = TYPE_CODE_ENUM;
1072 prefix = "enum ";
1073 break;
1074 default:
1075 return error_type (pp);
1076 }
1077
1078 to = type_name = (char *)
1079 obstack_alloc (&objfile -> type_obstack,
1080 (strlen (prefix) +
1081 ((char *) strchr (*pp, ':') - (*pp)) + 1));
1082
1083 /* Copy the prefix. */
1084 from = prefix;
1085 while ((*to++ = *from++) != '\0')
1086 ;
1087 to--;
1088
1089 type_name_only = to;
1090
1091 /* Copy the name. */
1092 from = *pp + 1;
1093 while ((*to++ = *from++) != ':')
1094 ;
1095 *--to = '\0';
1096
1097 /* Set the pointer ahead of the name which we just read. */
1098 *pp = from;
1099
1100 #if 0
1101 /* The following hack is clearly wrong, because it doesn't
1102 check whether we are in a baseclass. I tried to reproduce
1103 the case that it is trying to fix, but I couldn't get
1104 g++ to put out a cross reference to a basetype. Perhaps
1105 it doesn't do it anymore. */
1106 /* Note: for C++, the cross reference may be to a base type which
1107 has not yet been seen. In this case, we skip to the comma,
1108 which will mark the end of the base class name. (The ':'
1109 at the end of the base class name will be skipped as well.)
1110 But sometimes (ie. when the cross ref is the last thing on
1111 the line) there will be no ','. */
1112 from = (char *) strchr (*pp, ',');
1113 if (from)
1114 *pp = from;
1115 #endif /* 0 */
1116 }
1117
1118 /* Now check to see whether the type has already been declared. */
1119 /* This is necessary at least in the case where the
1120 program says something like
1121 struct foo bar[5];
1122 The compiler puts out a cross-reference; we better find
1123 set the length of the structure correctly so we can
1124 set the length of the array. */
1125 for (ppt = file_symbols; ppt; ppt = ppt->next)
1126 for (i = 0; i < ppt->nsyms; i++)
1127 {
1128 struct symbol *sym = ppt->symbol[i];
1129
1130 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1131 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1132 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1133 && STREQ (SYMBOL_NAME (sym), type_name_only))
1134 {
1135 obstack_free (&objfile -> type_obstack, type_name);
1136 type = SYMBOL_TYPE (sym);
1137 return type;
1138 }
1139 }
1140
1141 /* Didn't find the type to which this refers, so we must
1142 be dealing with a forward reference. Allocate a type
1143 structure for it, and keep track of it so we can
1144 fill in the rest of the fields when we get the full
1145 type. */
1146 type = dbx_alloc_type (typenums, objfile);
1147 TYPE_CODE (type) = code;
1148 TYPE_NAME (type) = type_name;
1149 INIT_CPLUS_SPECIFIC(type);
1150 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1151
1152 add_undefined_type (type);
1153 return type;
1154 }
1155
1156 case '-': /* RS/6000 built-in type */
1157 (*pp)--;
1158 type = builtin_type (pp); /* (in xcoffread.c) */
1159 goto after_digits;
1160
1161 case '0':
1162 case '1':
1163 case '2':
1164 case '3':
1165 case '4':
1166 case '5':
1167 case '6':
1168 case '7':
1169 case '8':
1170 case '9':
1171 case '(':
1172 (*pp)--;
1173 read_type_number (pp, xtypenums);
1174 type = *dbx_lookup_type (xtypenums);
1175 /* fall through */
1176
1177 after_digits:
1178 if (type == 0)
1179 type = lookup_fundamental_type (objfile, FT_VOID);
1180 if (typenums[0] != -1)
1181 *dbx_lookup_type (typenums) = type;
1182 break;
1183
1184 /* In the following types, we must be sure to overwrite any existing
1185 type that the typenums refer to, rather than allocating a new one
1186 and making the typenums point to the new one. This is because there
1187 may already be pointers to the existing type (if it had been
1188 forward-referenced), and we must change it to a pointer, function,
1189 reference, or whatever, *in-place*. */
1190
1191 case '*':
1192 type1 = read_type (pp, objfile);
1193 type = make_pointer_type (type1, dbx_lookup_type (typenums));
1194 break;
1195
1196 case '&': /* Reference to another type */
1197 type1 = read_type (pp, objfile);
1198 type = make_reference_type (type1, dbx_lookup_type (typenums));
1199 break;
1200
1201 case 'f': /* Function returning another type */
1202 type1 = read_type (pp, objfile);
1203 type = make_function_type (type1, dbx_lookup_type (typenums));
1204 break;
1205
1206 case 'k': /* Const qualifier on some type (Sun) */
1207 type = read_type (pp, objfile);
1208 /* FIXME! For now, we ignore const and volatile qualifiers. */
1209 break;
1210
1211 case 'B': /* Volatile qual on some type (Sun) */
1212 type = read_type (pp, objfile);
1213 /* FIXME! For now, we ignore const and volatile qualifiers. */
1214 break;
1215
1216 /* FIXME -- we should be doing smash_to_XXX types here. */
1217 case '@': /* Member (class & variable) type */
1218 {
1219 struct type *domain = read_type (pp, objfile);
1220 struct type *memtype;
1221
1222 if (**pp != ',')
1223 /* Invalid member type data format. */
1224 return error_type (pp);
1225 ++*pp;
1226
1227 memtype = read_type (pp, objfile);
1228 type = dbx_alloc_type (typenums, objfile);
1229 smash_to_member_type (type, domain, memtype);
1230 }
1231 break;
1232
1233 case '#': /* Method (class & fn) type */
1234 if ((*pp)[0] == '#')
1235 {
1236 /* We'll get the parameter types from the name. */
1237 struct type *return_type;
1238
1239 (*pp)++;
1240 return_type = read_type (pp, objfile);
1241 if (*(*pp)++ != ';')
1242 complain (&invalid_member_complaint, symnum);
1243 type = allocate_stub_method (return_type);
1244 if (typenums[0] != -1)
1245 *dbx_lookup_type (typenums) = type;
1246 }
1247 else
1248 {
1249 struct type *domain = read_type (pp, objfile);
1250 struct type *return_type;
1251 struct type **args;
1252
1253 if (*(*pp)++ != ',')
1254 error ("invalid member type data format, at symtab pos %d.",
1255 symnum);
1256
1257 return_type = read_type (pp, objfile);
1258 args = read_args (pp, ';', objfile);
1259 type = dbx_alloc_type (typenums, objfile);
1260 smash_to_method_type (type, domain, return_type, args);
1261 }
1262 break;
1263
1264 case 'r': /* Range type */
1265 type = read_range_type (pp, typenums, objfile);
1266 if (typenums[0] != -1)
1267 *dbx_lookup_type (typenums) = type;
1268 break;
1269
1270 case 'b': /* Sun ACC builtin int type */
1271 type = read_sun_builtin_type (pp, typenums, objfile);
1272 if (typenums[0] != -1)
1273 *dbx_lookup_type (typenums) = type;
1274 break;
1275
1276 case 'R': /* Sun ACC builtin float type */
1277 type = read_sun_floating_type (pp, typenums, objfile);
1278 if (typenums[0] != -1)
1279 *dbx_lookup_type (typenums) = type;
1280 break;
1281
1282 case 'e': /* Enumeration type */
1283 type = dbx_alloc_type (typenums, objfile);
1284 type = read_enum_type (pp, type, objfile);
1285 *dbx_lookup_type (typenums) = type;
1286 break;
1287
1288 case 's': /* Struct type */
1289 case 'u': /* Union type */
1290 type = dbx_alloc_type (typenums, objfile);
1291 if (!TYPE_NAME (type))
1292 {
1293 TYPE_NAME (type) = type_synonym_name;
1294 }
1295 type_synonym_name = NULL;
1296 switch (type_descriptor)
1297 {
1298 case 's':
1299 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1300 break;
1301 case 'u':
1302 TYPE_CODE (type) = TYPE_CODE_UNION;
1303 break;
1304 }
1305 type = read_struct_type (pp, type, objfile);
1306 break;
1307
1308 case 'a': /* Array type */
1309 if (**pp != 'r')
1310 return error_type (pp);
1311 ++*pp;
1312
1313 type = dbx_alloc_type (typenums, objfile);
1314 type = read_array_type (pp, type, objfile);
1315 break;
1316
1317 default:
1318 --*pp; /* Go back to the symbol in error */
1319 /* Particularly important if it was \0! */
1320 return error_type (pp);
1321 }
1322
1323 if (type == 0)
1324 abort ();
1325
1326 return type;
1327 }
1328 \f
1329 /* This page contains subroutines of read_type. */
1330
1331 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1332 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1333 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1334
1335 /* Read member function stabs info for C++ classes. The form of each member
1336 function data is:
1337
1338 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1339
1340 An example with two member functions is:
1341
1342 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1343
1344 For the case of overloaded operators, the format is op$::*.funcs, where
1345 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1346 name (such as `+=') and `.' marks the end of the operator name. */
1347
1348 static int
1349 read_member_functions (fip, pp, type, objfile)
1350 struct field_info *fip;
1351 char **pp;
1352 struct type *type;
1353 struct objfile *objfile;
1354 {
1355 int nfn_fields = 0;
1356 int length = 0;
1357 /* Total number of member functions defined in this class. If the class
1358 defines two `f' functions, and one `g' function, then this will have
1359 the value 3. */
1360 int total_length = 0;
1361 int i;
1362 struct next_fnfield
1363 {
1364 struct next_fnfield *next;
1365 struct fn_field fn_field;
1366 } *sublist;
1367 struct type *look_ahead_type;
1368 struct next_fnfieldlist *new_fnlist;
1369 struct next_fnfield *new_sublist;
1370 char *main_fn_name;
1371 register char *p;
1372
1373 /* Process each list until we find something that is not a member function
1374 or find the end of the functions. */
1375
1376 while (**pp != ';')
1377 {
1378 /* We should be positioned at the start of the function name.
1379 Scan forward to find the first ':' and if it is not the
1380 first of a "::" delimiter, then this is not a member function. */
1381 p = *pp;
1382 while (*p != ':')
1383 {
1384 p++;
1385 }
1386 if (p[1] != ':')
1387 {
1388 break;
1389 }
1390
1391 sublist = NULL;
1392 look_ahead_type = NULL;
1393 length = 0;
1394
1395 new_fnlist = (struct next_fnfieldlist *)
1396 xmalloc (sizeof (struct next_fnfieldlist));
1397 make_cleanup (free, new_fnlist);
1398 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
1399
1400 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
1401 {
1402 /* This is a completely wierd case. In order to stuff in the
1403 names that might contain colons (the usual name delimiter),
1404 Mike Tiemann defined a different name format which is
1405 signalled if the identifier is "op$". In that case, the
1406 format is "op$::XXXX." where XXXX is the name. This is
1407 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1408 /* This lets the user type "break operator+".
1409 We could just put in "+" as the name, but that wouldn't
1410 work for "*". */
1411 static char opname[32] = {'o', 'p', CPLUS_MARKER};
1412 char *o = opname + 3;
1413
1414 /* Skip past '::'. */
1415 *pp = p + 2;
1416
1417 STABS_CONTINUE (pp);
1418 p = *pp;
1419 while (*p != '.')
1420 {
1421 *o++ = *p++;
1422 }
1423 main_fn_name = savestring (opname, o - opname);
1424 /* Skip past '.' */
1425 *pp = p + 1;
1426 }
1427 else
1428 {
1429 main_fn_name = savestring (*pp, p - *pp);
1430 /* Skip past '::'. */
1431 *pp = p + 2;
1432 }
1433 new_fnlist -> fn_fieldlist.name = main_fn_name;
1434
1435 do
1436 {
1437 new_sublist =
1438 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
1439 make_cleanup (free, new_sublist);
1440 memset (new_sublist, 0, sizeof (struct next_fnfield));
1441
1442 /* Check for and handle cretinous dbx symbol name continuation! */
1443 if (look_ahead_type == NULL)
1444 {
1445 /* Normal case. */
1446 STABS_CONTINUE (pp);
1447
1448 new_sublist -> fn_field.type = read_type (pp, objfile);
1449 if (**pp != ':')
1450 {
1451 /* Invalid symtab info for member function. */
1452 return (0);
1453 }
1454 }
1455 else
1456 {
1457 /* g++ version 1 kludge */
1458 new_sublist -> fn_field.type = look_ahead_type;
1459 look_ahead_type = NULL;
1460 }
1461
1462 (*pp)++;
1463 p = *pp;
1464 while (*p != ';')
1465 {
1466 p++;
1467 }
1468
1469 /* If this is just a stub, then we don't have the real name here. */
1470
1471 if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB)
1472 {
1473 new_sublist -> fn_field.is_stub = 1;
1474 }
1475 new_sublist -> fn_field.physname = savestring (*pp, p - *pp);
1476 *pp = p + 1;
1477
1478 /* Set this member function's visibility fields. */
1479 switch (*(*pp)++)
1480 {
1481 case VISIBILITY_PRIVATE:
1482 new_sublist -> fn_field.is_private = 1;
1483 break;
1484 case VISIBILITY_PROTECTED:
1485 new_sublist -> fn_field.is_protected = 1;
1486 break;
1487 }
1488
1489 STABS_CONTINUE (pp);
1490 switch (**pp)
1491 {
1492 case 'A': /* Normal functions. */
1493 new_sublist -> fn_field.is_const = 0;
1494 new_sublist -> fn_field.is_volatile = 0;
1495 (*pp)++;
1496 break;
1497 case 'B': /* `const' member functions. */
1498 new_sublist -> fn_field.is_const = 1;
1499 new_sublist -> fn_field.is_volatile = 0;
1500 (*pp)++;
1501 break;
1502 case 'C': /* `volatile' member function. */
1503 new_sublist -> fn_field.is_const = 0;
1504 new_sublist -> fn_field.is_volatile = 1;
1505 (*pp)++;
1506 break;
1507 case 'D': /* `const volatile' member function. */
1508 new_sublist -> fn_field.is_const = 1;
1509 new_sublist -> fn_field.is_volatile = 1;
1510 (*pp)++;
1511 break;
1512 case '*': /* File compiled with g++ version 1 -- no info */
1513 case '?':
1514 case '.':
1515 break;
1516 default:
1517 complain (&const_vol_complaint, **pp);
1518 break;
1519 }
1520
1521 switch (*(*pp)++)
1522 {
1523 case '*':
1524 /* virtual member function, followed by index.
1525 The sign bit is set to distinguish pointers-to-methods
1526 from virtual function indicies. Since the array is
1527 in words, the quantity must be shifted left by 1
1528 on 16 bit machine, and by 2 on 32 bit machine, forcing
1529 the sign bit out, and usable as a valid index into
1530 the array. Remove the sign bit here. */
1531 new_sublist -> fn_field.voffset =
1532 (0x7fffffff & read_number (pp, ';')) + 2;
1533
1534 STABS_CONTINUE (pp);
1535 if (**pp == ';' || **pp == '\0')
1536 {
1537 /* Must be g++ version 1. */
1538 new_sublist -> fn_field.fcontext = 0;
1539 }
1540 else
1541 {
1542 /* Figure out from whence this virtual function came.
1543 It may belong to virtual function table of
1544 one of its baseclasses. */
1545 look_ahead_type = read_type (pp, objfile);
1546 if (**pp == ':')
1547 {
1548 /* g++ version 1 overloaded methods. */
1549 }
1550 else
1551 {
1552 new_sublist -> fn_field.fcontext = look_ahead_type;
1553 if (**pp != ';')
1554 {
1555 return (0);
1556 }
1557 else
1558 {
1559 ++*pp;
1560 }
1561 look_ahead_type = NULL;
1562 }
1563 }
1564 break;
1565
1566 case '?':
1567 /* static member function. */
1568 new_sublist -> fn_field.voffset = VOFFSET_STATIC;
1569 if (strncmp (new_sublist -> fn_field.physname,
1570 main_fn_name, strlen (main_fn_name)))
1571 {
1572 new_sublist -> fn_field.is_stub = 1;
1573 }
1574 break;
1575
1576 default:
1577 /* error */
1578 complain (&member_fn_complaint, (*pp)[-1]);
1579 /* Fall through into normal member function. */
1580
1581 case '.':
1582 /* normal member function. */
1583 new_sublist -> fn_field.voffset = 0;
1584 new_sublist -> fn_field.fcontext = 0;
1585 break;
1586 }
1587
1588 new_sublist -> next = sublist;
1589 sublist = new_sublist;
1590 length++;
1591 STABS_CONTINUE (pp);
1592 }
1593 while (**pp != ';' && **pp != '\0');
1594
1595 (*pp)++;
1596
1597 new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *)
1598 obstack_alloc (&objfile -> type_obstack,
1599 sizeof (struct fn_field) * length);
1600 memset (new_fnlist -> fn_fieldlist.fn_fields, 0,
1601 sizeof (struct fn_field) * length);
1602 for (i = length; (i--, sublist); sublist = sublist -> next)
1603 {
1604 new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field;
1605 }
1606
1607 new_fnlist -> fn_fieldlist.length = length;
1608 new_fnlist -> next = fip -> fnlist;
1609 fip -> fnlist = new_fnlist;
1610 nfn_fields++;
1611 total_length += length;
1612 STABS_CONTINUE (pp);
1613 }
1614
1615 if (nfn_fields)
1616 {
1617 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1618 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
1619 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
1620 memset (TYPE_FN_FIELDLISTS (type), 0,
1621 sizeof (struct fn_fieldlist) * nfn_fields);
1622 TYPE_NFN_FIELDS (type) = nfn_fields;
1623 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
1624 }
1625
1626 return (1);
1627 }
1628
1629 /* Special GNU C++ name.
1630 FIXME: Still need to properly handle parse error conditions. */
1631
1632 static void
1633 read_cpp_abbrev (fip, pp, type, objfile)
1634 struct field_info *fip;
1635 char **pp;
1636 struct type *type;
1637 struct objfile *objfile;
1638 {
1639 register char *p;
1640 const char *prefix;
1641 char *name;
1642 struct type *context;
1643
1644 p = *pp;
1645 if (*++p == 'v')
1646 {
1647 name = NULL;
1648 switch (*++p)
1649 {
1650 case 'f':
1651 prefix = vptr_name;
1652 break;
1653 case 'b':
1654 prefix = vb_name;
1655 break;
1656 default:
1657 complain (&invalid_cpp_abbrev_complaint, *pp);
1658 prefix = "INVALID_C++_ABBREV";
1659 break;
1660 }
1661 *pp = p + 1;
1662
1663 /* At this point, *pp points to something like "22:23=*22...",
1664 where the type number before the ':' is the "context" and
1665 everything after is a regular type definition. Lookup the
1666 type, find it's name, and construct the field name. */
1667
1668 context = read_type (pp, objfile);
1669 name = type_name_no_tag (context);
1670 if (name == NULL)
1671 {
1672 complain (&invalid_cpp_type_complaint, symnum);
1673 name = "FOO";
1674 }
1675 fip -> list -> field.name =
1676 obconcat (&objfile -> type_obstack, prefix, name, "");
1677
1678 /* At this point, *pp points to the ':'. Skip it and read the
1679 field type. */
1680
1681 p = ++(*pp);
1682 if (p[-1] != ':')
1683 {
1684 complain (&invalid_cpp_abbrev_complaint, *pp);
1685 }
1686 fip -> list -> field.type = read_type (pp, objfile);
1687 (*pp)++; /* Skip the comma. */
1688 fip -> list -> field.bitpos = read_number (pp, ';');
1689 /* This field is unpacked. */
1690 fip -> list -> field.bitsize = 0;
1691 fip -> list -> visibility = VISIBILITY_PRIVATE;
1692 }
1693 else if (*p == '_')
1694 {
1695 /* GNU C++ anonymous type. */
1696 complain (&stabs_general_complaint, "g++ anonymous type $_ not handled");
1697 }
1698 else
1699 {
1700 complain (&invalid_cpp_abbrev_complaint, *pp);
1701 }
1702 }
1703
1704 static void
1705 read_one_struct_field (fip, pp, p, type, objfile)
1706 struct field_info *fip;
1707 char **pp;
1708 char *p;
1709 struct type *type;
1710 struct objfile *objfile;
1711 {
1712 fip -> list -> field.name =
1713 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
1714 *pp = p + 1;
1715
1716 /* This means we have a visibility for a field coming. */
1717 if (**pp == '/')
1718 {
1719 (*pp)++;
1720 fip -> list -> visibility = *(*pp)++;
1721 switch (fip -> list -> visibility)
1722 {
1723 case VISIBILITY_PRIVATE:
1724 case VISIBILITY_PROTECTED:
1725 break;
1726
1727 case VISIBILITY_PUBLIC:
1728 /* Nothing to do */
1729 break;
1730
1731 default:
1732 /* Unknown visibility specifier. */
1733 complain (&stabs_general_complaint,
1734 "unknown visibility specifier");
1735 return;
1736 break;
1737 }
1738 }
1739 else
1740 {
1741 /* normal dbx-style format, no explicit visibility */
1742 fip -> list -> visibility = VISIBILITY_PUBLIC;
1743 }
1744
1745 fip -> list -> field.type = read_type (pp, objfile);
1746 if (**pp == ':')
1747 {
1748 p = ++(*pp);
1749 #if 0
1750 /* Possible future hook for nested types. */
1751 if (**pp == '!')
1752 {
1753 fip -> list -> field.bitpos = (long)-2; /* nested type */
1754 p = ++(*pp);
1755 }
1756 else
1757 #endif
1758 {
1759 /* Static class member. */
1760 fip -> list -> field.bitpos = (long) -1;
1761 }
1762 while (*p != ';')
1763 {
1764 p++;
1765 }
1766 fip -> list -> field.bitsize = (long) savestring (*pp, p - *pp);
1767 *pp = p + 1;
1768 return;
1769 }
1770 else if (**pp != ',')
1771 {
1772 /* Bad structure-type format. */
1773 complain (&stabs_general_complaint, "bad structure-type format");
1774 return;
1775 }
1776
1777 (*pp)++; /* Skip the comma. */
1778 fip -> list -> field.bitpos = read_number (pp, ',');
1779 fip -> list -> field.bitsize = read_number (pp, ';');
1780
1781 #if 0
1782 /* FIXME-tiemann: Can't the compiler put out something which
1783 lets us distinguish these? (or maybe just not put out anything
1784 for the field). What is the story here? What does the compiler
1785 really do? Also, patch gdb.texinfo for this case; I document
1786 it as a possible problem there. Search for "DBX-style". */
1787
1788 /* This is wrong because this is identical to the symbols
1789 produced for GCC 0-size arrays. For example:
1790 typedef union {
1791 int num;
1792 char str[0];
1793 } foo;
1794 The code which dumped core in such circumstances should be
1795 fixed not to dump core. */
1796
1797 /* g++ -g0 can put out bitpos & bitsize zero for a static
1798 field. This does not give us any way of getting its
1799 class, so we can't know its name. But we can just
1800 ignore the field so we don't dump core and other nasty
1801 stuff. */
1802 if (fip -> list -> field.bitpos == 0 && fip -> list -> field.bitsize == 0)
1803 {
1804 complain (&dbx_class_complaint);
1805 /* Ignore this field. */
1806 fip -> list = fip -> list -> next;
1807 }
1808 else
1809 #endif /* 0 */
1810 {
1811 /* Detect an unpacked field and mark it as such.
1812 dbx gives a bit size for all fields.
1813 Note that forward refs cannot be packed,
1814 and treat enums as if they had the width of ints. */
1815
1816 if (TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_INT
1817 && TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_ENUM)
1818 {
1819 fip -> list -> field.bitsize = 0;
1820 }
1821 if ((fip -> list -> field.bitsize
1822 == 8 * TYPE_LENGTH (fip -> list -> field.type)
1823 || (TYPE_CODE (fip -> list -> field.type) == TYPE_CODE_ENUM
1824 && (fip -> list -> field.bitsize
1825 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile, FT_INTEGER)))
1826 )
1827 )
1828 &&
1829 fip -> list -> field.bitpos % 8 == 0)
1830 {
1831 fip -> list -> field.bitsize = 0;
1832 }
1833 }
1834 }
1835
1836
1837 /* Read struct or class data fields. They have the form:
1838
1839 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
1840
1841 At the end, we see a semicolon instead of a field.
1842
1843 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1844 a static field.
1845
1846 The optional VISIBILITY is one of:
1847
1848 '/0' (VISIBILITY_PRIVATE)
1849 '/1' (VISIBILITY_PROTECTED)
1850 '/2' (VISIBILITY_PUBLIC)
1851
1852 or nothing, for C style fields with public visibility. */
1853
1854 static int
1855 read_struct_fields (fip, pp, type, objfile)
1856 struct field_info *fip;
1857 char **pp;
1858 struct type *type;
1859 struct objfile *objfile;
1860 {
1861 register char *p;
1862 struct nextfield *new;
1863
1864 /* We better set p right now, in case there are no fields at all... */
1865
1866 p = *pp;
1867
1868 /* Read each data member type until we find the terminating ';' at the end of
1869 the data member list, or break for some other reason such as finding the
1870 start of the member function list. */
1871
1872 while (**pp != ';')
1873 {
1874 STABS_CONTINUE (pp);
1875 /* Get space to record the next field's data. */
1876 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
1877 make_cleanup (free, new);
1878 memset (new, 0, sizeof (struct nextfield));
1879 new -> next = fip -> list;
1880 fip -> list = new;
1881
1882 /* Get the field name. */
1883 p = *pp;
1884 if (*p == CPLUS_MARKER)
1885 {
1886 read_cpp_abbrev (fip, pp, type, objfile);
1887 continue;
1888 }
1889
1890 /* Look for the ':' that separates the field name from the field
1891 values. Data members are delimited by a single ':', while member
1892 functions are delimited by a pair of ':'s. When we hit the member
1893 functions (if any), terminate scan loop and return. */
1894
1895 while (*p != ':')
1896 {
1897 p++;
1898 }
1899
1900 /* Check to see if we have hit the member functions yet. */
1901 if (p[1] == ':')
1902 {
1903 break;
1904 }
1905 read_one_struct_field (fip, pp, p, type, objfile);
1906 }
1907 if (p[1] == ':')
1908 {
1909 /* chill the list of fields: the last entry (at the head) is a
1910 partially constructed entry which we now scrub. */
1911 fip -> list = fip -> list -> next;
1912 }
1913 return (1);
1914 }
1915
1916 /* The stabs for C++ derived classes contain baseclass information which
1917 is marked by a '!' character after the total size. This function is
1918 called when we encounter the baseclass marker, and slurps up all the
1919 baseclass information.
1920
1921 Immediately following the '!' marker is the number of base classes that
1922 the class is derived from, followed by information for each base class.
1923 For each base class, there are two visibility specifiers, a bit offset
1924 to the base class information within the derived class, a reference to
1925 the type for the base class, and a terminating semicolon.
1926
1927 A typical example, with two base classes, would be "!2,020,19;0264,21;".
1928 ^^ ^ ^ ^ ^ ^ ^
1929 Baseclass information marker __________________|| | | | | | |
1930 Number of baseclasses __________________________| | | | | | |
1931 Visibility specifiers (2) ________________________| | | | | |
1932 Offset in bits from start of class _________________| | | | |
1933 Type number for base class ___________________________| | | |
1934 Visibility specifiers (2) _______________________________| | |
1935 Offset in bits from start of class ________________________| |
1936 Type number of base class ____________________________________|
1937 */
1938
1939 static int
1940 read_baseclasses (fip, pp, type, objfile)
1941 struct field_info *fip;
1942 char **pp;
1943 struct type *type;
1944 struct objfile *objfile;
1945 {
1946 int i;
1947 struct nextfield *new;
1948
1949 if (**pp != '!')
1950 {
1951 return (1);
1952 }
1953 else
1954 {
1955 /* Skip the '!' baseclass information marker. */
1956 (*pp)++;
1957 }
1958
1959 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1960 TYPE_N_BASECLASSES (type) = read_number (pp, ',');
1961
1962 #if 0
1963 /* Some stupid compilers have trouble with the following, so break
1964 it up into simpler expressions. */
1965 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
1966 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
1967 #else
1968 {
1969 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
1970 char *pointer;
1971
1972 pointer = (char *) TYPE_ALLOC (type, num_bytes);
1973 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
1974 }
1975 #endif /* 0 */
1976
1977 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
1978
1979 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
1980 {
1981 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
1982 make_cleanup (free, new);
1983 memset (new, 0, sizeof (struct nextfield));
1984 new -> next = fip -> list;
1985 fip -> list = new;
1986 new -> field.bitsize = 0; /* this should be an unpacked field! */
1987
1988 STABS_CONTINUE (pp);
1989 switch (*(*pp)++)
1990 {
1991 case '0':
1992 /* Nothing to do. */
1993 break;
1994 case '1':
1995 SET_TYPE_FIELD_VIRTUAL (type, i);
1996 break;
1997 default:
1998 /* Bad visibility format. */
1999 return (0);
2000 }
2001
2002 new -> visibility = *(*pp)++;
2003 switch (new -> visibility)
2004 {
2005 case VISIBILITY_PRIVATE:
2006 case VISIBILITY_PROTECTED:
2007 case VISIBILITY_PUBLIC:
2008 break;
2009 default:
2010 /* Bad visibility format. */
2011 return (0);
2012 }
2013
2014 /* The remaining value is the bit offset of the portion of the object
2015 corresponding to this baseclass. Always zero in the absence of
2016 multiple inheritance. */
2017
2018 new -> field.bitpos = read_number (pp, ',');
2019
2020 /* The last piece of baseclass information is the type of the base
2021 class. Read it, and remember it's type name as this field's name. */
2022
2023 new -> field.type = read_type (pp, objfile);
2024 new -> field.name = type_name_no_tag (new -> field.type);
2025
2026 /* skip trailing ';' and bump count of number of fields seen */
2027 (*pp)++;
2028 }
2029 return (1);
2030 }
2031
2032 static int
2033 read_tilde_fields (fip, pp, type, objfile)
2034 struct field_info *fip;
2035 char **pp;
2036 struct type *type;
2037 struct objfile *objfile;
2038 {
2039 register char *p;
2040
2041 STABS_CONTINUE (pp);
2042
2043 /* If we are positioned at a ';', then skip it. */
2044 if (**pp == ';')
2045 {
2046 (*pp)++;
2047 }
2048
2049 if (**pp == '~')
2050 {
2051 (*pp)++;
2052
2053 if (**pp == '=' || **pp == '+' || **pp == '-')
2054 {
2055 /* Obsolete flags that used to indicate the presence
2056 of constructors and/or destructors. */
2057 (*pp)++;
2058 }
2059
2060 /* Read either a '%' or the final ';'. */
2061 if (*(*pp)++ == '%')
2062 {
2063 /* We'd like to be able to derive the vtable pointer field
2064 from the type information, but when it's inherited, that's
2065 hard. A reason it's hard is because we may read in the
2066 info about a derived class before we read in info about
2067 the base class that provides the vtable pointer field.
2068 Once the base info has been read, we could fill in the info
2069 for the derived classes, but for the fact that by then,
2070 we don't remember who needs what. */
2071
2072 #if 0
2073 int predicted_fieldno = -1;
2074 #endif
2075
2076 /* Now we must record the virtual function table pointer's
2077 field information. */
2078
2079 struct type *t;
2080 int i;
2081
2082 #if 0
2083 {
2084 /* In version 2, we derive the vfield ourselves. */
2085 for (n = 0; n < TYPE_NFIELDS (type); n++)
2086 {
2087 if (! strncmp (TYPE_FIELD_NAME (type, n), vptr_name,
2088 sizeof (vptr_name) - 1))
2089 {
2090 predicted_fieldno = n;
2091 break;
2092 }
2093 }
2094 if (predicted_fieldno < 0)
2095 {
2096 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2097 {
2098 if (! TYPE_FIELD_VIRTUAL (type, n)
2099 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n)) >= 0)
2100 {
2101 predicted_fieldno =
2102 TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n));
2103 break;
2104 }
2105 }
2106 }
2107 }
2108 #endif
2109
2110 t = read_type (pp, objfile);
2111 p = (*pp)++;
2112 while (*p != '\0' && *p != ';')
2113 {
2114 p++;
2115 }
2116 if (*p == '\0')
2117 {
2118 /* Premature end of symbol. */
2119 return (0);
2120 }
2121
2122 TYPE_VPTR_BASETYPE (type) = t;
2123 if (type == t)
2124 {
2125 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
2126 {
2127 /* FIXME-tiemann: what's this? */
2128 #if 0
2129 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
2130 #else
2131 error_type (pp);
2132 #endif
2133 }
2134 else
2135 {
2136 for (i = TYPE_NFIELDS (t) - 1;
2137 i >= TYPE_N_BASECLASSES (t);
2138 --i)
2139 {
2140 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2141 sizeof (vptr_name) - 1))
2142 {
2143 TYPE_VPTR_FIELDNO (type) = i;
2144 break;
2145 }
2146 }
2147 }
2148 if (i < 0)
2149 {
2150 /* Virtual function table field not found. */
2151 return (0);
2152 }
2153 }
2154 else
2155 {
2156 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2157 }
2158
2159 #if 0
2160 if (TYPE_VPTR_FIELDNO (type) != predicted_fieldno)
2161 {
2162 error ("TYPE_VPTR_FIELDNO miscalculated");
2163 }
2164 #endif
2165
2166 *pp = p + 1;
2167 }
2168 }
2169 return (1);
2170 }
2171
2172 static int
2173 attach_fn_fields_to_type (fip, type)
2174 struct field_info *fip;
2175 register struct type *type;
2176 {
2177 register int n;
2178
2179 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2180 {
2181 if (TYPE_CODE (TYPE_BASECLASS (type, n)) == TYPE_CODE_UNDEF)
2182 {
2183 /* @@ Memory leak on objfile -> type_obstack? */
2184 return (0);
2185 }
2186 TYPE_NFN_FIELDS_TOTAL (type) +=
2187 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, n));
2188 }
2189
2190 for (n = TYPE_NFN_FIELDS (type);
2191 fip -> fnlist != NULL;
2192 fip -> fnlist = fip -> fnlist -> next)
2193 {
2194 --n; /* Circumvent Sun3 compiler bug */
2195 TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist;
2196 }
2197 return (1);
2198 }
2199
2200 /* Create the vector of fields, and record how big it is.
2201 We need this info to record proper virtual function table information
2202 for this class's virtual functions. */
2203
2204 static int
2205 attach_fields_to_type (fip, type, objfile)
2206 struct field_info *fip;
2207 register struct type *type;
2208 struct objfile *objfile;
2209 {
2210 register int nfields = 0;
2211 register int non_public_fields = 0;
2212 register struct nextfield *scan;
2213
2214 /* Count up the number of fields that we have, as well as taking note of
2215 whether or not there are any non-public fields, which requires us to
2216 allocate and build the private_field_bits and protected_field_bits
2217 bitfields. */
2218
2219 for (scan = fip -> list; scan != NULL; scan = scan -> next)
2220 {
2221 nfields++;
2222 if (scan -> visibility != VISIBILITY_PUBLIC)
2223 {
2224 non_public_fields++;
2225 }
2226 }
2227
2228 /* Now we know how many fields there are, and whether or not there are any
2229 non-public fields. Record the field count, allocate space for the
2230 array of fields, and create blank visibility bitfields if necessary. */
2231
2232 TYPE_NFIELDS (type) = nfields;
2233 TYPE_FIELDS (type) = (struct field *)
2234 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2235 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2236
2237 if (non_public_fields)
2238 {
2239 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2240
2241 TYPE_FIELD_PRIVATE_BITS (type) =
2242 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2243 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2244
2245 TYPE_FIELD_PROTECTED_BITS (type) =
2246 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2247 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2248 }
2249
2250 /* Copy the saved-up fields into the field vector. Start from the head
2251 of the list, adding to the tail of the field array, so that they end
2252 up in the same order in the array in which they were added to the list. */
2253
2254 while (nfields-- > 0)
2255 {
2256 TYPE_FIELD (type, nfields) = fip -> list -> field;
2257 switch (fip -> list -> visibility)
2258 {
2259 case VISIBILITY_PRIVATE:
2260 SET_TYPE_FIELD_PRIVATE (type, nfields);
2261 break;
2262
2263 case VISIBILITY_PROTECTED:
2264 SET_TYPE_FIELD_PROTECTED (type, nfields);
2265 break;
2266
2267 case VISIBILITY_PUBLIC:
2268 break;
2269
2270 default:
2271 /* Should warn about this unknown visibility? */
2272 break;
2273 }
2274 fip -> list = fip -> list -> next;
2275 }
2276 return (1);
2277 }
2278
2279 /* Read the description of a structure (or union type) and return an object
2280 describing the type.
2281
2282 PP points to a character pointer that points to the next unconsumed token
2283 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2284 *PP will point to "4a:1,0,32;;".
2285
2286 TYPE points to an incomplete type that needs to be filled in.
2287
2288 OBJFILE points to the current objfile from which the stabs information is
2289 being read. (Note that it is redundant in that TYPE also contains a pointer
2290 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2291 */
2292
2293 static struct type *
2294 read_struct_type (pp, type, objfile)
2295 char **pp;
2296 struct type *type;
2297 struct objfile *objfile;
2298 {
2299 struct cleanup *back_to;
2300 struct field_info fi;
2301
2302 fi.list = NULL;
2303 fi.fnlist = NULL;
2304
2305 back_to = make_cleanup (null_cleanup, 0);
2306
2307 INIT_CPLUS_SPECIFIC (type);
2308 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2309
2310 /* First comes the total size in bytes. */
2311
2312 TYPE_LENGTH (type) = read_number (pp, 0);
2313
2314 /* Now read the baseclasses, if any, read the regular C struct or C++
2315 class member fields, attach the fields to the type, read the C++
2316 member functions, attach them to the type, and then read any tilde
2317 fields. */
2318
2319 if (!read_baseclasses (&fi, pp, type, objfile)
2320 || !read_struct_fields (&fi, pp, type, objfile)
2321 || !attach_fields_to_type (&fi, type, objfile)
2322 || !read_member_functions (&fi, pp, type, objfile)
2323 || !attach_fn_fields_to_type (&fi, type)
2324 || !read_tilde_fields (&fi, pp, type, objfile))
2325 {
2326 do_cleanups (back_to);
2327 return (error_type (pp));
2328 }
2329
2330 do_cleanups (back_to);
2331 return (type);
2332 }
2333
2334 /* Read a definition of an array type,
2335 and create and return a suitable type object.
2336 Also creates a range type which represents the bounds of that
2337 array. */
2338
2339 static struct type *
2340 read_array_type (pp, type, objfile)
2341 register char **pp;
2342 register struct type *type;
2343 struct objfile *objfile;
2344 {
2345 struct type *index_type, *element_type, *range_type;
2346 int lower, upper;
2347 int adjustable = 0;
2348
2349 /* Format of an array type:
2350 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2351 to handle this.
2352
2353 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2354 for these, produce a type like float[][]. */
2355
2356 index_type = read_type (pp, objfile);
2357 if (**pp != ';')
2358 /* Improper format of array type decl. */
2359 return error_type (pp);
2360 ++*pp;
2361
2362 if (!(**pp >= '0' && **pp <= '9'))
2363 {
2364 (*pp)++;
2365 adjustable = 1;
2366 }
2367 lower = read_number (pp, ';');
2368
2369 if (!(**pp >= '0' && **pp <= '9'))
2370 {
2371 (*pp)++;
2372 adjustable = 1;
2373 }
2374 upper = read_number (pp, ';');
2375
2376 element_type = read_type (pp, objfile);
2377
2378 if (adjustable)
2379 {
2380 lower = 0;
2381 upper = -1;
2382 }
2383
2384 range_type =
2385 create_range_type ((struct type *) NULL, index_type, lower, upper);
2386 type = create_array_type (type, element_type, range_type);
2387
2388 /* If we have an array whose element type is not yet known, but whose
2389 bounds *are* known, record it to be adjusted at the end of the file. */
2390
2391 if (TYPE_LENGTH (element_type) == 0 && !adjustable)
2392 {
2393 add_undefined_type (type);
2394 }
2395
2396 return type;
2397 }
2398
2399
2400 /* Read a definition of an enumeration type,
2401 and create and return a suitable type object.
2402 Also defines the symbols that represent the values of the type. */
2403
2404 static struct type *
2405 read_enum_type (pp, type, objfile)
2406 register char **pp;
2407 register struct type *type;
2408 struct objfile *objfile;
2409 {
2410 register char *p;
2411 char *name;
2412 register long n;
2413 register struct symbol *sym;
2414 int nsyms = 0;
2415 struct pending **symlist;
2416 struct pending *osyms, *syms;
2417 int o_nsyms;
2418
2419 #if 0
2420 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2421 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2422 to do? For now, force all enum values to file scope. */
2423 if (within_function)
2424 symlist = &local_symbols;
2425 else
2426 #endif
2427 symlist = &file_symbols;
2428 osyms = *symlist;
2429 o_nsyms = osyms ? osyms->nsyms : 0;
2430
2431 /* Read the value-names and their values.
2432 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2433 A semicolon or comma instead of a NAME means the end. */
2434 while (**pp && **pp != ';' && **pp != ',')
2435 {
2436 STABS_CONTINUE (pp);
2437 p = *pp;
2438 while (*p != ':') p++;
2439 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
2440 *pp = p + 1;
2441 n = read_number (pp, ',');
2442
2443 sym = (struct symbol *)
2444 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
2445 memset (sym, 0, sizeof (struct symbol));
2446 SYMBOL_NAME (sym) = name;
2447 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
2448 SYMBOL_CLASS (sym) = LOC_CONST;
2449 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2450 SYMBOL_VALUE (sym) = n;
2451 add_symbol_to_list (sym, symlist);
2452 nsyms++;
2453 }
2454
2455 if (**pp == ';')
2456 (*pp)++; /* Skip the semicolon. */
2457
2458 /* Now fill in the fields of the type-structure. */
2459
2460 TYPE_LENGTH (type) = sizeof (int);
2461 TYPE_CODE (type) = TYPE_CODE_ENUM;
2462 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2463 TYPE_NFIELDS (type) = nsyms;
2464 TYPE_FIELDS (type) = (struct field *)
2465 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
2466 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
2467
2468 /* Find the symbols for the values and put them into the type.
2469 The symbols can be found in the symlist that we put them on
2470 to cause them to be defined. osyms contains the old value
2471 of that symlist; everything up to there was defined by us. */
2472 /* Note that we preserve the order of the enum constants, so
2473 that in something like "enum {FOO, LAST_THING=FOO}" we print
2474 FOO, not LAST_THING. */
2475
2476 for (syms = *symlist, n = 0; syms; syms = syms->next)
2477 {
2478 int j = 0;
2479 if (syms == osyms)
2480 j = o_nsyms;
2481 for (; j < syms->nsyms; j++,n++)
2482 {
2483 struct symbol *xsym = syms->symbol[j];
2484 SYMBOL_TYPE (xsym) = type;
2485 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2486 TYPE_FIELD_VALUE (type, n) = 0;
2487 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2488 TYPE_FIELD_BITSIZE (type, n) = 0;
2489 }
2490 if (syms == osyms)
2491 break;
2492 }
2493
2494 #if 0
2495 /* This screws up perfectly good C programs with enums. FIXME. */
2496 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2497 if(TYPE_NFIELDS(type) == 2 &&
2498 ((STREQ(TYPE_FIELD_NAME(type,0),"TRUE") &&
2499 STREQ(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2500 (STREQ(TYPE_FIELD_NAME(type,1),"TRUE") &&
2501 STREQ(TYPE_FIELD_NAME(type,0),"FALSE"))))
2502 TYPE_CODE(type) = TYPE_CODE_BOOL;
2503 #endif
2504
2505 return type;
2506 }
2507
2508 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2509 typedefs in every file (for int, long, etc):
2510
2511 type = b <signed> <width>; <offset>; <nbits>
2512 signed = u or s. Possible c in addition to u or s (for char?).
2513 offset = offset from high order bit to start bit of type.
2514 width is # bytes in object of this type, nbits is # bits in type.
2515
2516 The width/offset stuff appears to be for small objects stored in
2517 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2518 FIXME. */
2519
2520 static struct type *
2521 read_sun_builtin_type (pp, typenums, objfile)
2522 char **pp;
2523 int typenums[2];
2524 struct objfile *objfile;
2525 {
2526 int nbits;
2527 int signed_type;
2528
2529 switch (**pp)
2530 {
2531 case 's':
2532 signed_type = 1;
2533 break;
2534 case 'u':
2535 signed_type = 0;
2536 break;
2537 default:
2538 return error_type (pp);
2539 }
2540 (*pp)++;
2541
2542 /* For some odd reason, all forms of char put a c here. This is strange
2543 because no other type has this honor. We can safely ignore this because
2544 we actually determine 'char'acterness by the number of bits specified in
2545 the descriptor. */
2546
2547 if (**pp == 'c')
2548 (*pp)++;
2549
2550 /* The first number appears to be the number of bytes occupied
2551 by this type, except that unsigned short is 4 instead of 2.
2552 Since this information is redundant with the third number,
2553 we will ignore it. */
2554 read_number (pp, ';');
2555
2556 /* The second number is always 0, so ignore it too. */
2557 read_number (pp, ';');
2558
2559 /* The third number is the number of bits for this type. */
2560 nbits = read_number (pp, 0);
2561
2562 /* FIXME. Here we should just be able to make a type of the right
2563 number of bits and signedness. FIXME. */
2564
2565 if (nbits == TARGET_LONG_LONG_BIT)
2566 return (lookup_fundamental_type (objfile,
2567 signed_type? FT_LONG_LONG: FT_UNSIGNED_LONG_LONG));
2568
2569 if (nbits == TARGET_INT_BIT)
2570 {
2571 /* FIXME -- the only way to distinguish `int' from `long'
2572 is to look at its name! */
2573 if (signed_type)
2574 {
2575 if (long_kludge_name && long_kludge_name[0] == 'l' /* long */)
2576 return lookup_fundamental_type (objfile, FT_LONG);
2577 else
2578 return lookup_fundamental_type (objfile, FT_INTEGER);
2579 }
2580 else
2581 {
2582 if (long_kludge_name
2583 && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2584 long_kludge_name[9] == 'l' /* long */)
2585 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2586 return lookup_fundamental_type (objfile, FT_UNSIGNED_LONG);
2587 else
2588 return lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
2589 }
2590 }
2591
2592 if (nbits == TARGET_SHORT_BIT)
2593 return (lookup_fundamental_type (objfile,
2594 signed_type? FT_SHORT: FT_UNSIGNED_SHORT));
2595
2596 if (nbits == TARGET_CHAR_BIT)
2597 return (lookup_fundamental_type (objfile,
2598 signed_type? FT_CHAR: FT_UNSIGNED_CHAR));
2599
2600 if (nbits == 0)
2601 return lookup_fundamental_type (objfile, FT_VOID);
2602
2603 return error_type (pp);
2604 }
2605
2606 static struct type *
2607 read_sun_floating_type (pp, typenums, objfile)
2608 char **pp;
2609 int typenums[2];
2610 struct objfile *objfile;
2611 {
2612 int nbytes;
2613
2614 /* The first number has more details about the type, for example
2615 FN_COMPLEX. See the sun stab.h. */
2616 read_number (pp, ';');
2617
2618 /* The second number is the number of bytes occupied by this type */
2619 nbytes = read_number (pp, ';');
2620
2621 if (**pp != 0)
2622 return error_type (pp);
2623
2624 if (nbytes == TARGET_FLOAT_BIT / TARGET_CHAR_BIT)
2625 return lookup_fundamental_type (objfile, FT_FLOAT);
2626
2627 if (nbytes == TARGET_DOUBLE_BIT / TARGET_CHAR_BIT)
2628 return lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
2629
2630 if (nbytes == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT)
2631 return lookup_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
2632
2633 return error_type (pp);
2634 }
2635
2636 /* Read a number from the string pointed to by *PP.
2637 The value of *PP is advanced over the number.
2638 If END is nonzero, the character that ends the
2639 number must match END, or an error happens;
2640 and that character is skipped if it does match.
2641 If END is zero, *PP is left pointing to that character.
2642
2643 If the number fits in a long, set *VALUE and set *BITS to 0.
2644 If not, set *BITS to be the number of bits in the number.
2645
2646 If encounter garbage, set *BITS to -1. */
2647
2648 static void
2649 read_huge_number (pp, end, valu, bits)
2650 char **pp;
2651 int end;
2652 long *valu;
2653 int *bits;
2654 {
2655 char *p = *pp;
2656 int sign = 1;
2657 long n = 0;
2658 int radix = 10;
2659 char overflow = 0;
2660 int nbits = 0;
2661 int c;
2662 long upper_limit;
2663
2664 if (*p == '-')
2665 {
2666 sign = -1;
2667 p++;
2668 }
2669
2670 /* Leading zero means octal. GCC uses this to output values larger
2671 than an int (because that would be hard in decimal). */
2672 if (*p == '0')
2673 {
2674 radix = 8;
2675 p++;
2676 }
2677
2678 upper_limit = LONG_MAX / radix;
2679 while ((c = *p++) >= '0' && c <= ('0' + radix))
2680 {
2681 if (n <= upper_limit)
2682 {
2683 n *= radix;
2684 n += c - '0'; /* FIXME this overflows anyway */
2685 }
2686 else
2687 overflow = 1;
2688
2689 /* This depends on large values being output in octal, which is
2690 what GCC does. */
2691 if (radix == 8)
2692 {
2693 if (nbits == 0)
2694 {
2695 if (c == '0')
2696 /* Ignore leading zeroes. */
2697 ;
2698 else if (c == '1')
2699 nbits = 1;
2700 else if (c == '2' || c == '3')
2701 nbits = 2;
2702 else
2703 nbits = 3;
2704 }
2705 else
2706 nbits += 3;
2707 }
2708 }
2709 if (end)
2710 {
2711 if (c && c != end)
2712 {
2713 if (bits != NULL)
2714 *bits = -1;
2715 return;
2716 }
2717 }
2718 else
2719 --p;
2720
2721 *pp = p;
2722 if (overflow)
2723 {
2724 if (nbits == 0)
2725 {
2726 /* Large decimal constants are an error (because it is hard to
2727 count how many bits are in them). */
2728 if (bits != NULL)
2729 *bits = -1;
2730 return;
2731 }
2732
2733 /* -0x7f is the same as 0x80. So deal with it by adding one to
2734 the number of bits. */
2735 if (sign == -1)
2736 ++nbits;
2737 if (bits)
2738 *bits = nbits;
2739 }
2740 else
2741 {
2742 if (valu)
2743 *valu = n * sign;
2744 if (bits)
2745 *bits = 0;
2746 }
2747 }
2748
2749 static struct type *
2750 read_range_type (pp, typenums, objfile)
2751 char **pp;
2752 int typenums[2];
2753 struct objfile *objfile;
2754 {
2755 int rangenums[2];
2756 long n2, n3;
2757 int n2bits, n3bits;
2758 int self_subrange;
2759 struct type *result_type;
2760 struct type *index_type;
2761
2762 /* First comes a type we are a subrange of.
2763 In C it is usually 0, 1 or the type being defined. */
2764 read_type_number (pp, rangenums);
2765 self_subrange = (rangenums[0] == typenums[0] &&
2766 rangenums[1] == typenums[1]);
2767
2768 /* A semicolon should now follow; skip it. */
2769 if (**pp == ';')
2770 (*pp)++;
2771
2772 /* The remaining two operands are usually lower and upper bounds
2773 of the range. But in some special cases they mean something else. */
2774 read_huge_number (pp, ';', &n2, &n2bits);
2775 read_huge_number (pp, ';', &n3, &n3bits);
2776
2777 if (n2bits == -1 || n3bits == -1)
2778 return error_type (pp);
2779
2780 /* If limits are huge, must be large integral type. */
2781 if (n2bits != 0 || n3bits != 0)
2782 {
2783 char got_signed = 0;
2784 char got_unsigned = 0;
2785 /* Number of bits in the type. */
2786 int nbits;
2787
2788 /* Range from 0 to <large number> is an unsigned large integral type. */
2789 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
2790 {
2791 got_unsigned = 1;
2792 nbits = n3bits;
2793 }
2794 /* Range from <large number> to <large number>-1 is a large signed
2795 integral type. */
2796 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
2797 {
2798 got_signed = 1;
2799 nbits = n2bits;
2800 }
2801
2802 /* Check for "long long". */
2803 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
2804 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
2805 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
2806 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
2807
2808 if (got_signed || got_unsigned)
2809 {
2810 result_type = alloc_type (objfile);
2811 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
2812 TYPE_CODE (result_type) = TYPE_CODE_INT;
2813 if (got_unsigned)
2814 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
2815 return result_type;
2816 }
2817 else
2818 return error_type (pp);
2819 }
2820
2821 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2822 if (self_subrange && n2 == 0 && n3 == 0)
2823 return (lookup_fundamental_type (objfile, FT_VOID));
2824
2825 /* If n3 is zero and n2 is not, we want a floating type,
2826 and n2 is the width in bytes.
2827
2828 Fortran programs appear to use this for complex types also,
2829 and they give no way to distinguish between double and single-complex!
2830 We don't have complex types, so we would lose on all fortran files!
2831 So return type `double' for all of those. It won't work right
2832 for the complex values, but at least it makes the file loadable.
2833
2834 FIXME, we may be able to distinguish these by their names. FIXME. */
2835
2836 if (n3 == 0 && n2 > 0)
2837 {
2838 if (n2 == sizeof (float))
2839 return (lookup_fundamental_type (objfile, FT_FLOAT));
2840 return (lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT));
2841 }
2842
2843 /* If the upper bound is -1, it must really be an unsigned int. */
2844
2845 else if (n2 == 0 && n3 == -1)
2846 {
2847 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2848 long' is to look at its name! */
2849 if (
2850 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2851 long_kludge_name[9] == 'l' /* long */)
2852 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2853 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
2854 else
2855 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
2856 }
2857
2858 /* Special case: char is defined (Who knows why) as a subrange of
2859 itself with range 0-127. */
2860 else if (self_subrange && n2 == 0 && n3 == 127)
2861 return (lookup_fundamental_type (objfile, FT_CHAR));
2862
2863 /* Assumptions made here: Subrange of self is equivalent to subrange
2864 of int. FIXME: Host and target type-sizes assumed the same. */
2865 /* FIXME: This is the *only* place in GDB that depends on comparing
2866 some type to a builtin type with ==. Fix it! */
2867 else if (n2 == 0
2868 && (self_subrange ||
2869 *dbx_lookup_type (rangenums) == lookup_fundamental_type (objfile, FT_INTEGER)))
2870 {
2871 /* an unsigned type */
2872 #ifdef LONG_LONG
2873 if (n3 == - sizeof (long long))
2874 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
2875 #endif
2876 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2877 long' is to look at its name! */
2878 if (n3 == (unsigned long)~0L &&
2879 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2880 long_kludge_name[9] == 'l' /* long */)
2881 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2882 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
2883 if (n3 == (unsigned int)~0L)
2884 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
2885 if (n3 == (unsigned short)~0L)
2886 return (lookup_fundamental_type (objfile, FT_UNSIGNED_SHORT));
2887 if (n3 == (unsigned char)~0L)
2888 return (lookup_fundamental_type (objfile, FT_UNSIGNED_CHAR));
2889 }
2890 #ifdef LONG_LONG
2891 else if (n3 == 0 && n2 == -sizeof (long long))
2892 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
2893 #endif
2894 else if (n2 == -n3 -1)
2895 {
2896 /* a signed type */
2897 /* FIXME -- the only way to distinguish `int' from `long' is to look
2898 at its name! */
2899 if ((n3 ==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2900 long_kludge_name && long_kludge_name[0] == 'l' /* long */)
2901 return (lookup_fundamental_type (objfile, FT_LONG));
2902 if (n3 == (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2903 return (lookup_fundamental_type (objfile, FT_INTEGER));
2904 if (n3 == ( 1 << (8 * sizeof (short) - 1)) - 1)
2905 return (lookup_fundamental_type (objfile, FT_SHORT));
2906 if (n3 == ( 1 << (8 * sizeof (char) - 1)) - 1)
2907 return (lookup_fundamental_type (objfile, FT_SIGNED_CHAR));
2908 }
2909
2910 /* We have a real range type on our hands. Allocate space and
2911 return a real pointer. */
2912
2913 /* At this point I don't have the faintest idea how to deal with
2914 a self_subrange type; I'm going to assume that this is used
2915 as an idiom, and that all of them are special cases. So . . . */
2916 if (self_subrange)
2917 return error_type (pp);
2918
2919 index_type = *dbx_lookup_type (rangenums);
2920 if (index_type == NULL)
2921 {
2922 complain (&range_type_base_complaint, rangenums[1]);
2923 index_type = lookup_fundamental_type (objfile, FT_INTEGER);
2924 }
2925
2926 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
2927 return (result_type);
2928 }
2929
2930 /* Read a number from the string pointed to by *PP.
2931 The value of *PP is advanced over the number.
2932 If END is nonzero, the character that ends the
2933 number must match END, or an error happens;
2934 and that character is skipped if it does match.
2935 If END is zero, *PP is left pointing to that character. */
2936
2937 long
2938 read_number (pp, end)
2939 char **pp;
2940 int end;
2941 {
2942 register char *p = *pp;
2943 register long n = 0;
2944 register int c;
2945 int sign = 1;
2946
2947 /* Handle an optional leading minus sign. */
2948
2949 if (*p == '-')
2950 {
2951 sign = -1;
2952 p++;
2953 }
2954
2955 /* Read the digits, as far as they go. */
2956
2957 while ((c = *p++) >= '0' && c <= '9')
2958 {
2959 n *= 10;
2960 n += c - '0';
2961 }
2962 if (end)
2963 {
2964 if (c && c != end)
2965 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
2966 }
2967 else
2968 --p;
2969
2970 *pp = p;
2971 return n * sign;
2972 }
2973
2974 /* Read in an argument list. This is a list of types, separated by commas
2975 and terminated with END. Return the list of types read in, or (struct type
2976 **)-1 if there is an error. */
2977
2978 static struct type **
2979 read_args (pp, end, objfile)
2980 char **pp;
2981 int end;
2982 struct objfile *objfile;
2983 {
2984 /* FIXME! Remove this arbitrary limit! */
2985 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
2986 int n = 0;
2987
2988 while (**pp != end)
2989 {
2990 if (**pp != ',')
2991 /* Invalid argument list: no ','. */
2992 return (struct type **)-1;
2993 (*pp)++;
2994 STABS_CONTINUE (pp);
2995 types[n++] = read_type (pp, objfile);
2996 }
2997 (*pp)++; /* get past `end' (the ':' character) */
2998
2999 if (n == 1)
3000 {
3001 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3002 }
3003 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3004 {
3005 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3006 memset (rval + n, 0, sizeof (struct type *));
3007 }
3008 else
3009 {
3010 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3011 }
3012 memcpy (rval, types, n * sizeof (struct type *));
3013 return rval;
3014 }
3015
3016 /* Add a common block's start address to the offset of each symbol
3017 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3018 the common block name). */
3019
3020 static void
3021 fix_common_block (sym, valu)
3022 struct symbol *sym;
3023 int valu;
3024 {
3025 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
3026 for ( ; next; next = next->next)
3027 {
3028 register int j;
3029 for (j = next->nsyms - 1; j >= 0; j--)
3030 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3031 }
3032 }
3033
3034
3035 \f
3036 /* What about types defined as forward references inside of a small lexical
3037 scope? */
3038 /* Add a type to the list of undefined types to be checked through
3039 once this file has been read in. */
3040
3041 void
3042 add_undefined_type (type)
3043 struct type *type;
3044 {
3045 if (undef_types_length == undef_types_allocated)
3046 {
3047 undef_types_allocated *= 2;
3048 undef_types = (struct type **)
3049 xrealloc ((char *) undef_types,
3050 undef_types_allocated * sizeof (struct type *));
3051 }
3052 undef_types[undef_types_length++] = type;
3053 }
3054
3055 /* Go through each undefined type, see if it's still undefined, and fix it
3056 up if possible. We have two kinds of undefined types:
3057
3058 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3059 Fix: update array length using the element bounds
3060 and the target type's length.
3061 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3062 yet defined at the time a pointer to it was made.
3063 Fix: Do a full lookup on the struct/union tag. */
3064 void
3065 cleanup_undefined_types ()
3066 {
3067 struct type **type;
3068
3069 for (type = undef_types; type < undef_types + undef_types_length; type++)
3070 {
3071 switch (TYPE_CODE (*type))
3072 {
3073
3074 case TYPE_CODE_STRUCT:
3075 case TYPE_CODE_UNION:
3076 case TYPE_CODE_ENUM:
3077 {
3078 /* Check if it has been defined since. */
3079 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
3080 {
3081 struct pending *ppt;
3082 int i;
3083 /* Name of the type, without "struct" or "union" */
3084 char *typename = TYPE_NAME (*type);
3085
3086 if (!strncmp (typename, "struct ", 7))
3087 typename += 7;
3088 if (!strncmp (typename, "union ", 6))
3089 typename += 6;
3090 if (!strncmp (typename, "enum ", 5))
3091 typename += 5;
3092
3093 for (ppt = file_symbols; ppt; ppt = ppt->next)
3094 {
3095 for (i = 0; i < ppt->nsyms; i++)
3096 {
3097 struct symbol *sym = ppt->symbol[i];
3098
3099 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3100 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
3101 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
3102 TYPE_CODE (*type))
3103 && STREQ (SYMBOL_NAME (sym), typename))
3104 {
3105 memcpy (*type, SYMBOL_TYPE (sym),
3106 sizeof (struct type));
3107 }
3108 }
3109 }
3110 }
3111 }
3112 break;
3113
3114 case TYPE_CODE_ARRAY:
3115 {
3116 struct type *range_type;
3117 int lower, upper;
3118
3119 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
3120 goto badtype;
3121 if (TYPE_NFIELDS (*type) != 1)
3122 goto badtype;
3123 range_type = TYPE_FIELD_TYPE (*type, 0);
3124 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
3125 goto badtype;
3126
3127 /* Now recompute the length of the array type, based on its
3128 number of elements and the target type's length. */
3129 lower = TYPE_FIELD_BITPOS (range_type, 0);
3130 upper = TYPE_FIELD_BITPOS (range_type, 1);
3131 TYPE_LENGTH (*type) = (upper - lower + 1)
3132 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
3133 }
3134 break;
3135
3136 default:
3137 badtype:
3138 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type));
3139 break;
3140 }
3141 }
3142 undef_types_length = 0;
3143 }
3144
3145 /* Scan through all of the global symbols defined in the object file,
3146 assigning values to the debugging symbols that need to be assigned
3147 to. Get these symbols from the minimal symbol table. */
3148
3149 void
3150 scan_file_globals (objfile)
3151 struct objfile *objfile;
3152 {
3153 int hash;
3154 struct minimal_symbol *msymbol;
3155 struct symbol *sym, *prev;
3156
3157 if (objfile->msymbols == 0) /* Beware the null file. */
3158 return;
3159
3160 for (msymbol = objfile -> msymbols; SYMBOL_NAME (msymbol) != NULL; msymbol++)
3161 {
3162 QUIT;
3163
3164 prev = NULL;
3165
3166 /* Get the hash index and check all the symbols
3167 under that hash index. */
3168
3169 hash = hashname (SYMBOL_NAME (msymbol));
3170
3171 for (sym = global_sym_chain[hash]; sym;)
3172 {
3173 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
3174 STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
3175 {
3176 /* Splice this symbol out of the hash chain and
3177 assign the value we have to it. */
3178 if (prev)
3179 {
3180 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
3181 }
3182 else
3183 {
3184 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
3185 }
3186
3187 /* Check to see whether we need to fix up a common block. */
3188 /* Note: this code might be executed several times for
3189 the same symbol if there are multiple references. */
3190
3191 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3192 {
3193 fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol));
3194 }
3195 else
3196 {
3197 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol);
3198 }
3199
3200 if (prev)
3201 {
3202 sym = SYMBOL_VALUE_CHAIN (prev);
3203 }
3204 else
3205 {
3206 sym = global_sym_chain[hash];
3207 }
3208 }
3209 else
3210 {
3211 prev = sym;
3212 sym = SYMBOL_VALUE_CHAIN (sym);
3213 }
3214 }
3215 }
3216 }
3217
3218 /* Initialize anything that needs initializing when starting to read
3219 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3220 to a psymtab. */
3221
3222 void
3223 stabsread_init ()
3224 {
3225 }
3226
3227 /* Initialize anything that needs initializing when a completely new
3228 symbol file is specified (not just adding some symbols from another
3229 file, e.g. a shared library). */
3230
3231 void
3232 stabsread_new_init ()
3233 {
3234 /* Empty the hash table of global syms looking for values. */
3235 memset (global_sym_chain, 0, sizeof (global_sym_chain));
3236 }
3237
3238 /* Initialize anything that needs initializing at the same time as
3239 start_symtab() is called. */
3240
3241 void start_stabs ()
3242 {
3243 global_stabs = NULL; /* AIX COFF */
3244 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3245 n_this_object_header_files = 1;
3246 type_vector_length = 0;
3247 type_vector = (struct type **) 0;
3248 }
3249
3250 /* Call after end_symtab() */
3251
3252 void end_stabs ()
3253 {
3254 if (type_vector)
3255 {
3256 free ((char *) type_vector);
3257 }
3258 type_vector = 0;
3259 type_vector_length = 0;
3260 previous_stab_code = 0;
3261 }
3262
3263 void
3264 finish_global_stabs (objfile)
3265 struct objfile *objfile;
3266 {
3267 if (global_stabs)
3268 {
3269 patch_block_stabs (global_symbols, global_stabs, objfile);
3270 free ((PTR) global_stabs);
3271 global_stabs = NULL;
3272 }
3273 }
3274
3275 /* Initializer for this module */
3276
3277 void
3278 _initialize_stabsread ()
3279 {
3280 undef_types_allocated = 20;
3281 undef_types_length = 0;
3282 undef_types = (struct type **)
3283 xmalloc (undef_types_allocated * sizeof (struct type *));
3284 }
This page took 0.130806 seconds and 4 git commands to generate.