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