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