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