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