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