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