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