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