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