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