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