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