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