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