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