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