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