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