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