* complaints.c: New file, code moved from utils.c.
[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;
1076 while (*to++ = *from++)
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
85f0a848 2375 type = create_array_type (type, element_type, index_type, lower, upper);
d07734e3
FF
2376
2377 /* If we have an array whose element type is not yet known, but whose
2378 bounds *are* known, record it to be adjusted at the end of the file. */
85f0a848 2379
d07734e3 2380 if (TYPE_LENGTH (element_type) == 0 && !adjustable)
85f0a848
FF
2381 {
2382 add_undefined_type (type);
2383 }
d07734e3
FF
2384
2385 return type;
2386}
2387
2388
2389/* Read a definition of an enumeration type,
2390 and create and return a suitable type object.
2391 Also defines the symbols that represent the values of the type. */
2392
2393static struct type *
2394read_enum_type (pp, type, objfile)
2395 register char **pp;
2396 register struct type *type;
2397 struct objfile *objfile;
2398{
2399 register char *p;
2400 char *name;
2401 register long n;
2402 register struct symbol *sym;
2403 int nsyms = 0;
2404 struct pending **symlist;
2405 struct pending *osyms, *syms;
2406 int o_nsyms;
2407
2408#if 0
2409 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2410 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2411 to do? For now, force all enum values to file scope. */
2412 if (within_function)
2413 symlist = &local_symbols;
2414 else
2415#endif
2416 symlist = &file_symbols;
2417 osyms = *symlist;
2418 o_nsyms = osyms ? osyms->nsyms : 0;
2419
2420 /* Read the value-names and their values.
2421 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2422 A semicolon or comma instead of a NAME means the end. */
2423 while (**pp && **pp != ';' && **pp != ',')
2424 {
e7177cc2 2425 STABS_CONTINUE (pp);
d07734e3
FF
2426 p = *pp;
2427 while (*p != ':') p++;
2428 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
2429 *pp = p + 1;
2430 n = read_number (pp, ',');
2431
c02a37ea
FF
2432 sym = (struct symbol *)
2433 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
d07734e3
FF
2434 memset (sym, 0, sizeof (struct symbol));
2435 SYMBOL_NAME (sym) = name;
2436 SYMBOL_CLASS (sym) = LOC_CONST;
2437 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2438 SYMBOL_VALUE (sym) = n;
2439 add_symbol_to_list (sym, symlist);
2440 nsyms++;
2441 }
2442
2443 if (**pp == ';')
2444 (*pp)++; /* Skip the semicolon. */
2445
2446 /* Now fill in the fields of the type-structure. */
2447
2448 TYPE_LENGTH (type) = sizeof (int);
2449 TYPE_CODE (type) = TYPE_CODE_ENUM;
2450 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2451 TYPE_NFIELDS (type) = nsyms;
2452 TYPE_FIELDS (type) = (struct field *)
dac9734e 2453 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
c02a37ea 2454 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
d07734e3
FF
2455
2456 /* Find the symbols for the values and put them into the type.
2457 The symbols can be found in the symlist that we put them on
2458 to cause them to be defined. osyms contains the old value
2459 of that symlist; everything up to there was defined by us. */
2460 /* Note that we preserve the order of the enum constants, so
2461 that in something like "enum {FOO, LAST_THING=FOO}" we print
2462 FOO, not LAST_THING. */
2463
2464 for (syms = *symlist, n = 0; syms; syms = syms->next)
2465 {
2466 int j = 0;
2467 if (syms == osyms)
2468 j = o_nsyms;
2469 for (; j < syms->nsyms; j++,n++)
2470 {
2471 struct symbol *xsym = syms->symbol[j];
2472 SYMBOL_TYPE (xsym) = type;
2473 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2474 TYPE_FIELD_VALUE (type, n) = 0;
2475 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2476 TYPE_FIELD_BITSIZE (type, n) = 0;
2477 }
2478 if (syms == osyms)
2479 break;
2480 }
2481
2482#if 0
2483 /* This screws up perfectly good C programs with enums. FIXME. */
2484 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2485 if(TYPE_NFIELDS(type) == 2 &&
2486 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2487 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2488 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2489 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2490 TYPE_CODE(type) = TYPE_CODE_BOOL;
2491#endif
2492
2493 return type;
2494}
2495
2496/* Sun's ACC uses a somewhat saner method for specifying the builtin
2497 typedefs in every file (for int, long, etc):
2498
2499 type = b <signed> <width>; <offset>; <nbits>
2500 signed = u or s. Possible c in addition to u or s (for char?).
2501 offset = offset from high order bit to start bit of type.
2502 width is # bytes in object of this type, nbits is # bits in type.
2503
2504 The width/offset stuff appears to be for small objects stored in
2505 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2506 FIXME. */
2507
2508static struct type *
2509read_sun_builtin_type (pp, typenums, objfile)
2510 char **pp;
2511 int typenums[2];
2512 struct objfile *objfile;
2513{
2514 int nbits;
2515 int signed_type;
2516
2517 switch (**pp)
2518 {
2519 case 's':
2520 signed_type = 1;
2521 break;
2522 case 'u':
2523 signed_type = 0;
2524 break;
2525 default:
2526 return error_type (pp);
2527 }
2528 (*pp)++;
2529
2530 /* For some odd reason, all forms of char put a c here. This is strange
2531 because no other type has this honor. We can safely ignore this because
2532 we actually determine 'char'acterness by the number of bits specified in
2533 the descriptor. */
2534
2535 if (**pp == 'c')
2536 (*pp)++;
2537
2538 /* The first number appears to be the number of bytes occupied
2539 by this type, except that unsigned short is 4 instead of 2.
2540 Since this information is redundant with the third number,
2541 we will ignore it. */
2542 read_number (pp, ';');
2543
2544 /* The second number is always 0, so ignore it too. */
2545 read_number (pp, ';');
2546
2547 /* The third number is the number of bits for this type. */
2548 nbits = read_number (pp, 0);
2549
2550 /* FIXME. Here we should just be able to make a type of the right
2551 number of bits and signedness. FIXME. */
2552
2553 if (nbits == TARGET_LONG_LONG_BIT)
2554 return (lookup_fundamental_type (objfile,
2555 signed_type? FT_LONG_LONG: FT_UNSIGNED_LONG_LONG));
2556
2557 if (nbits == TARGET_INT_BIT)
2558 {
2559 /* FIXME -- the only way to distinguish `int' from `long'
2560 is to look at its name! */
2561 if (signed_type)
2562 {
2563 if (long_kludge_name && long_kludge_name[0] == 'l' /* long */)
2564 return lookup_fundamental_type (objfile, FT_LONG);
2565 else
2566 return lookup_fundamental_type (objfile, FT_INTEGER);
2567 }
2568 else
2569 {
2570 if (long_kludge_name
2571 && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2572 long_kludge_name[9] == 'l' /* long */)
2573 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2574 return lookup_fundamental_type (objfile, FT_UNSIGNED_LONG);
2575 else
2576 return lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
2577 }
2578 }
2579
2580 if (nbits == TARGET_SHORT_BIT)
2581 return (lookup_fundamental_type (objfile,
2582 signed_type? FT_SHORT: FT_UNSIGNED_SHORT));
2583
2584 if (nbits == TARGET_CHAR_BIT)
2585 return (lookup_fundamental_type (objfile,
2586 signed_type? FT_CHAR: FT_UNSIGNED_CHAR));
2587
2588 if (nbits == 0)
2589 return lookup_fundamental_type (objfile, FT_VOID);
2590
2591 return error_type (pp);
2592}
2593
2594static struct type *
2595read_sun_floating_type (pp, typenums, objfile)
2596 char **pp;
2597 int typenums[2];
2598 struct objfile *objfile;
2599{
2600 int nbytes;
2601
2602 /* The first number has more details about the type, for example
2603 FN_COMPLEX. See the sun stab.h. */
2604 read_number (pp, ';');
2605
2606 /* The second number is the number of bytes occupied by this type */
2607 nbytes = read_number (pp, ';');
2608
2609 if (**pp != 0)
2610 return error_type (pp);
2611
2612 if (nbytes == TARGET_FLOAT_BIT / TARGET_CHAR_BIT)
2613 return lookup_fundamental_type (objfile, FT_FLOAT);
2614
2615 if (nbytes == TARGET_DOUBLE_BIT / TARGET_CHAR_BIT)
2616 return lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
2617
2618 if (nbytes == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT)
2619 return lookup_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
2620
2621 return error_type (pp);
2622}
2623
2624/* Read a number from the string pointed to by *PP.
2625 The value of *PP is advanced over the number.
2626 If END is nonzero, the character that ends the
2627 number must match END, or an error happens;
2628 and that character is skipped if it does match.
2629 If END is zero, *PP is left pointing to that character.
2630
2631 If the number fits in a long, set *VALUE and set *BITS to 0.
2632 If not, set *BITS to be the number of bits in the number.
2633
2634 If encounter garbage, set *BITS to -1. */
2635
2636static void
2637read_huge_number (pp, end, valu, bits)
2638 char **pp;
2639 int end;
2640 long *valu;
2641 int *bits;
2642{
2643 char *p = *pp;
2644 int sign = 1;
2645 long n = 0;
2646 int radix = 10;
2647 char overflow = 0;
2648 int nbits = 0;
2649 int c;
2650 long upper_limit;
2651
2652 if (*p == '-')
2653 {
2654 sign = -1;
2655 p++;
2656 }
2657
2658 /* Leading zero means octal. GCC uses this to output values larger
2659 than an int (because that would be hard in decimal). */
2660 if (*p == '0')
2661 {
2662 radix = 8;
2663 p++;
2664 }
2665
2666 upper_limit = LONG_MAX / radix;
2667 while ((c = *p++) >= '0' && c <= ('0' + radix))
2668 {
2669 if (n <= upper_limit)
2670 {
2671 n *= radix;
2672 n += c - '0'; /* FIXME this overflows anyway */
2673 }
2674 else
2675 overflow = 1;
2676
2677 /* This depends on large values being output in octal, which is
2678 what GCC does. */
2679 if (radix == 8)
2680 {
2681 if (nbits == 0)
2682 {
2683 if (c == '0')
2684 /* Ignore leading zeroes. */
2685 ;
2686 else if (c == '1')
2687 nbits = 1;
2688 else if (c == '2' || c == '3')
2689 nbits = 2;
2690 else
2691 nbits = 3;
2692 }
2693 else
2694 nbits += 3;
2695 }
2696 }
2697 if (end)
2698 {
2699 if (c && c != end)
2700 {
2701 if (bits != NULL)
2702 *bits = -1;
2703 return;
2704 }
2705 }
2706 else
2707 --p;
2708
2709 *pp = p;
2710 if (overflow)
2711 {
2712 if (nbits == 0)
2713 {
2714 /* Large decimal constants are an error (because it is hard to
2715 count how many bits are in them). */
2716 if (bits != NULL)
2717 *bits = -1;
2718 return;
2719 }
2720
2721 /* -0x7f is the same as 0x80. So deal with it by adding one to
2722 the number of bits. */
2723 if (sign == -1)
2724 ++nbits;
2725 if (bits)
2726 *bits = nbits;
2727 }
2728 else
2729 {
2730 if (valu)
2731 *valu = n * sign;
2732 if (bits)
2733 *bits = 0;
2734 }
2735}
2736
2737static struct type *
2738read_range_type (pp, typenums, objfile)
2739 char **pp;
2740 int typenums[2];
2741 struct objfile *objfile;
2742{
2743 int rangenums[2];
2744 long n2, n3;
2745 int n2bits, n3bits;
2746 int self_subrange;
2747 struct type *result_type;
2748
2749 /* First comes a type we are a subrange of.
2750 In C it is usually 0, 1 or the type being defined. */
2751 read_type_number (pp, rangenums);
2752 self_subrange = (rangenums[0] == typenums[0] &&
2753 rangenums[1] == typenums[1]);
2754
2755 /* A semicolon should now follow; skip it. */
2756 if (**pp == ';')
2757 (*pp)++;
2758
2759 /* The remaining two operands are usually lower and upper bounds
2760 of the range. But in some special cases they mean something else. */
2761 read_huge_number (pp, ';', &n2, &n2bits);
2762 read_huge_number (pp, ';', &n3, &n3bits);
2763
2764 if (n2bits == -1 || n3bits == -1)
2765 return error_type (pp);
2766
2767 /* If limits are huge, must be large integral type. */
2768 if (n2bits != 0 || n3bits != 0)
2769 {
2770 char got_signed = 0;
2771 char got_unsigned = 0;
2772 /* Number of bits in the type. */
2773 int nbits;
2774
2775 /* Range from 0 to <large number> is an unsigned large integral type. */
2776 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
2777 {
2778 got_unsigned = 1;
2779 nbits = n3bits;
2780 }
2781 /* Range from <large number> to <large number>-1 is a large signed
2782 integral type. */
2783 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
2784 {
2785 got_signed = 1;
2786 nbits = n2bits;
2787 }
2788
2789 /* Check for "long long". */
2790 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
2791 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
2792 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
2793 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
2794
2795 if (got_signed || got_unsigned)
2796 {
dac9734e 2797 result_type = alloc_type (objfile);
d07734e3
FF
2798 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
2799 TYPE_CODE (result_type) = TYPE_CODE_INT;
2800 if (got_unsigned)
2801 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
2802 return result_type;
2803 }
2804 else
2805 return error_type (pp);
2806 }
2807
2808 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2809 if (self_subrange && n2 == 0 && n3 == 0)
2810 return (lookup_fundamental_type (objfile, FT_VOID));
2811
2812 /* If n3 is zero and n2 is not, we want a floating type,
2813 and n2 is the width in bytes.
2814
2815 Fortran programs appear to use this for complex types also,
2816 and they give no way to distinguish between double and single-complex!
2817 We don't have complex types, so we would lose on all fortran files!
2818 So return type `double' for all of those. It won't work right
2819 for the complex values, but at least it makes the file loadable.
2820
2821 FIXME, we may be able to distinguish these by their names. FIXME. */
2822
2823 if (n3 == 0 && n2 > 0)
2824 {
2825 if (n2 == sizeof (float))
2826 return (lookup_fundamental_type (objfile, FT_FLOAT));
2827 return (lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT));
2828 }
2829
2830 /* If the upper bound is -1, it must really be an unsigned int. */
2831
2832 else if (n2 == 0 && n3 == -1)
2833 {
2834 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2835 long' is to look at its name! */
2836 if (
2837 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2838 long_kludge_name[9] == 'l' /* long */)
2839 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2840 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
2841 else
2842 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
2843 }
2844
2845 /* Special case: char is defined (Who knows why) as a subrange of
2846 itself with range 0-127. */
2847 else if (self_subrange && n2 == 0 && n3 == 127)
2848 return (lookup_fundamental_type (objfile, FT_CHAR));
2849
2850 /* Assumptions made here: Subrange of self is equivalent to subrange
2851 of int. FIXME: Host and target type-sizes assumed the same. */
2852 /* FIXME: This is the *only* place in GDB that depends on comparing
2853 some type to a builtin type with ==. Fix it! */
2854 else if (n2 == 0
2855 && (self_subrange ||
2856 *dbx_lookup_type (rangenums) == lookup_fundamental_type (objfile, FT_INTEGER)))
2857 {
2858 /* an unsigned type */
2859#ifdef LONG_LONG
2860 if (n3 == - sizeof (long long))
2861 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
2862#endif
2863 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2864 long' is to look at its name! */
2865 if (n3 == (unsigned long)~0L &&
2866 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2867 long_kludge_name[9] == 'l' /* long */)
2868 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2869 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
2870 if (n3 == (unsigned int)~0L)
2871 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
2872 if (n3 == (unsigned short)~0L)
2873 return (lookup_fundamental_type (objfile, FT_UNSIGNED_SHORT));
2874 if (n3 == (unsigned char)~0L)
2875 return (lookup_fundamental_type (objfile, FT_UNSIGNED_CHAR));
2876 }
2877#ifdef LONG_LONG
2878 else if (n3 == 0 && n2 == -sizeof (long long))
2879 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
2880#endif
2881 else if (n2 == -n3 -1)
2882 {
2883 /* a signed type */
2884 /* FIXME -- the only way to distinguish `int' from `long' is to look
2885 at its name! */
2886 if ((n3 ==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2887 long_kludge_name && long_kludge_name[0] == 'l' /* long */)
2888 return (lookup_fundamental_type (objfile, FT_LONG));
2889 if (n3 == (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2890 return (lookup_fundamental_type (objfile, FT_INTEGER));
2891 if (n3 == ( 1 << (8 * sizeof (short) - 1)) - 1)
2892 return (lookup_fundamental_type (objfile, FT_SHORT));
2893 if (n3 == ( 1 << (8 * sizeof (char) - 1)) - 1)
2894 return (lookup_fundamental_type (objfile, FT_SIGNED_CHAR));
2895 }
2896
2897 /* We have a real range type on our hands. Allocate space and
2898 return a real pointer. */
2899
2900 /* At this point I don't have the faintest idea how to deal with
2901 a self_subrange type; I'm going to assume that this is used
2902 as an idiom, and that all of them are special cases. So . . . */
2903 if (self_subrange)
2904 return error_type (pp);
2905
dac9734e 2906 result_type = alloc_type (objfile);
d07734e3
FF
2907
2908 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
2909
2910 TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
2911 if (TYPE_TARGET_TYPE (result_type) == 0) {
51b80b00 2912 complain (&range_type_base_complaint, rangenums[1]);
d07734e3
FF
2913 TYPE_TARGET_TYPE (result_type) = lookup_fundamental_type (objfile, FT_INTEGER);
2914 }
2915
2916 TYPE_NFIELDS (result_type) = 2;
c02a37ea 2917 TYPE_FIELDS (result_type) = (struct field *)
e7177cc2 2918 TYPE_ALLOC (result_type, 2 * sizeof (struct field));
d07734e3
FF
2919 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
2920 TYPE_FIELD_BITPOS (result_type, 0) = n2;
2921 TYPE_FIELD_BITPOS (result_type, 1) = n3;
2922
2923 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
2924
2925 return result_type;
2926}
2927
2928/* Read a number from the string pointed to by *PP.
2929 The value of *PP is advanced over the number.
2930 If END is nonzero, the character that ends the
2931 number must match END, or an error happens;
2932 and that character is skipped if it does match.
2933 If END is zero, *PP is left pointing to that character. */
2934
2935long
2936read_number (pp, end)
2937 char **pp;
2938 int end;
2939{
2940 register char *p = *pp;
2941 register long n = 0;
2942 register int c;
2943 int sign = 1;
2944
2945 /* Handle an optional leading minus sign. */
2946
2947 if (*p == '-')
2948 {
2949 sign = -1;
2950 p++;
2951 }
2952
2953 /* Read the digits, as far as they go. */
2954
2955 while ((c = *p++) >= '0' && c <= '9')
2956 {
2957 n *= 10;
2958 n += c - '0';
2959 }
2960 if (end)
2961 {
2962 if (c && c != end)
2963 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
2964 }
2965 else
2966 --p;
2967
2968 *pp = p;
2969 return n * sign;
2970}
2971
2972/* Read in an argument list. This is a list of types, separated by commas
2973 and terminated with END. Return the list of types read in, or (struct type
2974 **)-1 if there is an error. */
2975
2976static struct type **
2977read_args (pp, end, objfile)
2978 char **pp;
2979 int end;
2980 struct objfile *objfile;
2981{
2982 /* FIXME! Remove this arbitrary limit! */
2983 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
2984 int n = 0;
2985
2986 while (**pp != end)
2987 {
2988 if (**pp != ',')
2989 /* Invalid argument list: no ','. */
2990 return (struct type **)-1;
e7177cc2
FF
2991 (*pp)++;
2992 STABS_CONTINUE (pp);
d07734e3
FF
2993 types[n++] = read_type (pp, objfile);
2994 }
e7177cc2 2995 (*pp)++; /* get past `end' (the ':' character) */
d07734e3
FF
2996
2997 if (n == 1)
2998 {
2999 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3000 }
3001 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3002 {
3003 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3004 memset (rval + n, 0, sizeof (struct type *));
3005 }
3006 else
3007 {
3008 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3009 }
3010 memcpy (rval, types, n * sizeof (struct type *));
3011 return rval;
3012}
3013
3014/* Add a common block's start address to the offset of each symbol
3015 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3016 the common block name). */
3017
3018static void
3019fix_common_block (sym, valu)
3020 struct symbol *sym;
3021 int valu;
3022{
3023 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
3024 for ( ; next; next = next->next)
3025 {
3026 register int j;
3027 for (j = next->nsyms - 1; j >= 0; j--)
3028 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3029 }
3030}
3031
3032
3033\f
3034/* What about types defined as forward references inside of a small lexical
3035 scope? */
3036/* Add a type to the list of undefined types to be checked through
3037 once this file has been read in. */
3038
3039void
3040add_undefined_type (type)
3041 struct type *type;
3042{
3043 if (undef_types_length == undef_types_allocated)
3044 {
3045 undef_types_allocated *= 2;
3046 undef_types = (struct type **)
3047 xrealloc ((char *) undef_types,
3048 undef_types_allocated * sizeof (struct type *));
3049 }
3050 undef_types[undef_types_length++] = type;
3051}
3052
3053/* Go through each undefined type, see if it's still undefined, and fix it
3054 up if possible. We have two kinds of undefined types:
3055
3056 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3057 Fix: update array length using the element bounds
3058 and the target type's length.
3059 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3060 yet defined at the time a pointer to it was made.
3061 Fix: Do a full lookup on the struct/union tag. */
3062void
3063cleanup_undefined_types ()
3064{
3065 struct type **type;
3066
3067 for (type = undef_types; type < undef_types + undef_types_length; type++)
3068 {
3069 switch (TYPE_CODE (*type))
3070 {
3071
3072 case TYPE_CODE_STRUCT:
3073 case TYPE_CODE_UNION:
3074 case TYPE_CODE_ENUM:
3075 {
3076 /* Check if it has been defined since. */
3077 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
3078 {
3079 struct pending *ppt;
3080 int i;
3081 /* Name of the type, without "struct" or "union" */
3082 char *typename = TYPE_NAME (*type);
3083
3084 if (!strncmp (typename, "struct ", 7))
3085 typename += 7;
3086 if (!strncmp (typename, "union ", 6))
3087 typename += 6;
3088 if (!strncmp (typename, "enum ", 5))
3089 typename += 5;
3090
3091 for (ppt = file_symbols; ppt; ppt = ppt->next)
3092 {
3093 for (i = 0; i < ppt->nsyms; i++)
3094 {
3095 struct symbol *sym = ppt->symbol[i];
3096
3097 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3098 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
3099 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
3100 TYPE_CODE (*type))
3101 && !strcmp (SYMBOL_NAME (sym), typename))
3102 {
3103 memcpy (*type, SYMBOL_TYPE (sym),
3104 sizeof (struct type));
3105 }
3106 }
3107 }
3108 }
3109 }
3110 break;
3111
3112 case TYPE_CODE_ARRAY:
3113 {
3114 struct type *range_type;
3115 int lower, upper;
3116
3117 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
3118 goto badtype;
3119 if (TYPE_NFIELDS (*type) != 1)
3120 goto badtype;
3121 range_type = TYPE_FIELD_TYPE (*type, 0);
3122 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
3123 goto badtype;
3124
3125 /* Now recompute the length of the array type, based on its
3126 number of elements and the target type's length. */
3127 lower = TYPE_FIELD_BITPOS (range_type, 0);
3128 upper = TYPE_FIELD_BITPOS (range_type, 1);
3129 TYPE_LENGTH (*type) = (upper - lower + 1)
3130 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
3131 }
3132 break;
3133
3134 default:
3135 badtype:
3136 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type));
3137 break;
3138 }
3139 }
3140 undef_types_length = 0;
3141}
3142
3143/* Scan through all of the global symbols defined in the object file,
3144 assigning values to the debugging symbols that need to be assigned
3145 to. Get these symbols from the minimal symbol table. */
3146
3147void
3148scan_file_globals (objfile)
3149 struct objfile *objfile;
3150{
3151 int hash;
3152 struct minimal_symbol *msymbol;
3153 struct symbol *sym, *prev;
3154
3155 if (objfile->msymbols == 0) /* Beware the null file. */
3156 return;
3157
3158 for (msymbol = objfile -> msymbols; msymbol -> name != NULL; msymbol++)
3159 {
3160 QUIT;
3161
3162 prev = NULL;
3163
3164 /* Get the hash index and check all the symbols
3165 under that hash index. */
3166
3167 hash = hashname (msymbol -> name);
3168
3169 for (sym = global_sym_chain[hash]; sym;)
3170 {
3171 if (*(msymbol -> name) == SYMBOL_NAME (sym)[0]
3172 && !strcmp(msymbol -> name + 1, SYMBOL_NAME (sym) + 1))
3173 {
3174 /* Splice this symbol out of the hash chain and
3175 assign the value we have to it. */
3176 if (prev)
3177 {
3178 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
3179 }
3180 else
3181 {
3182 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
3183 }
3184
3185 /* Check to see whether we need to fix up a common block. */
3186 /* Note: this code might be executed several times for
3187 the same symbol if there are multiple references. */
3188
3189 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3190 {
3191 fix_common_block (sym, msymbol -> address);
3192 }
3193 else
3194 {
3195 SYMBOL_VALUE_ADDRESS (sym) = msymbol -> address;
3196 }
3197
3198 if (prev)
3199 {
3200 sym = SYMBOL_VALUE_CHAIN (prev);
3201 }
3202 else
3203 {
3204 sym = global_sym_chain[hash];
3205 }
3206 }
3207 else
3208 {
3209 prev = sym;
3210 sym = SYMBOL_VALUE_CHAIN (sym);
3211 }
3212 }
3213 }
3214}
3215
3216/* Initialize anything that needs initializing when starting to read
3217 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3218 to a psymtab. */
3219
3220void
3221stabsread_init ()
3222{
3223}
3224
3225/* Initialize anything that needs initializing when a completely new
3226 symbol file is specified (not just adding some symbols from another
3227 file, e.g. a shared library). */
3228
3229void
3230stabsread_new_init ()
3231{
3232 /* Empty the hash table of global syms looking for values. */
3233 memset (global_sym_chain, 0, sizeof (global_sym_chain));
3234}
3235
3236/* Initialize anything that needs initializing at the same time as
3237 start_symtab() is called. */
3238
3239void start_stabs ()
3240{
3241 global_stabs = NULL; /* AIX COFF */
3242 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3243 n_this_object_header_files = 1;
3244 type_vector_length = 0;
3245 type_vector = (struct type **) 0;
3246}
3247
3248/* Call after end_symtab() */
3249
3250void end_stabs ()
3251{
3252 if (type_vector)
3253 {
3254 free ((char *) type_vector);
3255 }
3256 type_vector = 0;
3257 type_vector_length = 0;
3258 previous_stab_code = 0;
3259}
3260
3261void
3262finish_global_stabs (objfile)
d07734e3
FF
3263 struct objfile *objfile;
3264{
3265 if (global_stabs)
3266 {
3267 patch_block_stabs (global_symbols, global_stabs, objfile);
3268 free ((PTR) global_stabs);
3269 global_stabs = NULL;
3270 }
3271}
3272
3273/* Initializer for this module */
3274
3275void
3276_initialize_stabsread ()
3277{
3278 undef_types_allocated = 20;
3279 undef_types_length = 0;
3280 undef_types = (struct type **)
3281 xmalloc (undef_types_allocated * sizeof (struct type *));
3282}
This page took 0.196715 seconds and 4 git commands to generate.