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