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