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