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