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