Obsolete stuff.c and kdb-start.c.
[deliverable/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);
64485362 1805 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
c906108c 1806 {
64485362
AC
1807 complain (&reg_value_complaint, SYMBOL_VALUE (sym),
1808 NUM_REGS + NUM_PSEUDO_REGS,
c906108c 1809 SYMBOL_SOURCE_NAME (sym));
c5aa993b 1810 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
c906108c
SS
1811 }
1812 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1813 add_symbol_to_list (sym, &local_symbols);
1814 break;
1815
1816 case 'r':
1817 /* Register variable (either global or local). */
1818 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1819 SYMBOL_CLASS (sym) = LOC_REGISTER;
1820 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
64485362 1821 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
c906108c 1822 {
64485362
AC
1823 complain (&reg_value_complaint, SYMBOL_VALUE (sym),
1824 NUM_REGS + NUM_PSEUDO_REGS,
c906108c 1825 SYMBOL_SOURCE_NAME (sym));
c5aa993b 1826 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
c906108c
SS
1827 }
1828 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1829 if (within_function)
1830 {
1831 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1832 name to represent an argument passed in a register.
1833 GCC uses 'P' for the same case. So if we find such a symbol pair
1834 we combine it into one 'P' symbol. For Sun cc we need to do this
1835 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1836 the 'p' symbol even if it never saves the argument onto the stack.
1837
1838 On most machines, we want to preserve both symbols, so that
1839 we can still get information about what is going on with the
1840 stack (VAX for computing args_printed, using stack slots instead
1841 of saved registers in backtraces, etc.).
1842
1843 Note that this code illegally combines
c5aa993b 1844 main(argc) struct foo argc; { register struct foo argc; }
c906108c
SS
1845 but this case is considered pathological and causes a warning
1846 from a decent compiler. */
1847
1848 if (local_symbols
1849 && local_symbols->nsyms > 0
1850#ifndef USE_REGISTER_NOT_ARG
d03e67c9 1851 && REG_STRUCT_HAS_ADDR_P ()
c906108c
SS
1852 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1853 SYMBOL_TYPE (sym))
1854 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1855 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1856 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1857 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1858#endif
c5aa993b 1859 )
c906108c
SS
1860 {
1861 struct symbol *prev_sym;
1862 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
1863 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1864 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
c5aa993b 1865 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME (sym)))
c906108c
SS
1866 {
1867 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
1868 /* Use the type from the LOC_REGISTER; that is the type
1869 that is actually in that register. */
1870 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
1871 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1872 sym = prev_sym;
1873 break;
1874 }
1875 }
c5aa993b 1876 add_symbol_to_list (sym, &local_symbols);
c906108c
SS
1877 }
1878 else
c5aa993b 1879 add_symbol_to_list (sym, &file_symbols);
c906108c
SS
1880 break;
1881
1882 case 'S':
1883 /* Static symbol at top level of file */
1884 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1885 SYMBOL_CLASS (sym) = LOC_STATIC;
1886 SYMBOL_VALUE_ADDRESS (sym) = valu;
1887#ifdef STATIC_TRANSFORM_NAME
1888 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
c5aa993b
JM
1889 {
1890 struct minimal_symbol *msym;
1891 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1892 if (msym != NULL)
1893 {
1894 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1895 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1896 }
1897 }
c906108c
SS
1898#endif
1899 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1900 add_symbol_to_list (sym, &file_symbols);
1901 break;
1902
1903 case 't':
1904 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1905
1906 /* For a nameless type, we don't want a create a symbol, thus we
c5aa993b
JM
1907 did not use `sym'. Return without further processing. */
1908 if (nameless)
1909 return NULL;
c906108c
SS
1910
1911 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1912 SYMBOL_VALUE (sym) = valu;
1913 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1914 /* C++ vagaries: we may have a type which is derived from
c5aa993b
JM
1915 a base type which did not have its name defined when the
1916 derived class was output. We fill in the derived class's
1917 base part member's name here in that case. */
c906108c
SS
1918 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1919 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1920 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1921 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1922 {
1923 int j;
1924 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1925 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1926 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1927 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1928 }
1929
1930 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1931 {
1932 /* gcc-2.6 or later (when using -fvtable-thunks)
1933 emits a unique named type for a vtable entry.
1934 Some gdb code depends on that specific name. */
1935 extern const char vtbl_ptr_name[];
1936
1937 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1938 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
1939 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
1940 {
1941 /* If we are giving a name to a type such as "pointer to
c5aa993b
JM
1942 foo" or "function returning foo", we better not set
1943 the TYPE_NAME. If the program contains "typedef char
1944 *caddr_t;", we don't want all variables of type char
1945 * to print as caddr_t. This is not just a
1946 consequence of GDB's type management; PCC and GCC (at
1947 least through version 2.4) both output variables of
1948 either type char * or caddr_t with the type number
1949 defined in the 't' symbol for caddr_t. If a future
1950 compiler cleans this up it GDB is not ready for it
1951 yet, but if it becomes ready we somehow need to
1952 disable this check (without breaking the PCC/GCC2.4
1953 case).
1954
1955 Sigh.
1956
1957 Fortunately, this check seems not to be necessary
1958 for anything except pointers or functions. */
49d97c60
EZ
1959 /* ezannoni: 2000-10-26. This seems to apply for
1960 versions of gcc older than 2.8. This was the original
1961 problem: with the following code gdb would tell that
1962 the type for name1 is caddr_t, and func is char()
1963 typedef char *caddr_t;
1964 char *name2;
1965 struct x
1966 {
1967 char *name1;
1968 } xx;
1969 char *func()
1970 {
1971 }
1972 main () {}
1973 */
1974
1975 /* Pascal accepts names for pointer types. */
1976 if (current_subfile->language == language_pascal)
1977 {
1978 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1979 }
c906108c
SS
1980 }
1981 else
1982 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1983 }
1984
1985 add_symbol_to_list (sym, &file_symbols);
1986 break;
1987
1988 case 'T':
1989 /* Struct, union, or enum tag. For GNU C++, this can be be followed
c5aa993b 1990 by 't' which means we are typedef'ing it as well. */
c906108c
SS
1991 synonym = *p == 't';
1992
1993 if (synonym)
1994 p++;
1995 /* The semantics of C++ state that "struct foo { ... }" also defines
c5aa993b
JM
1996 a typedef for "foo". Unfortunately, cfront never makes the typedef
1997 when translating C++ into C. We make the typedef here so that
1998 "ptype foo" works as expected for cfront translated code. */
c906108c
SS
1999 else if (current_subfile->language == language_cplus)
2000 synonym = 1;
2001
2002 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2003
2004 /* For a nameless type, we don't want a create a symbol, thus we
c5aa993b
JM
2005 did not use `sym'. Return without further processing. */
2006 if (nameless)
2007 return NULL;
c906108c
SS
2008
2009 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
2010 SYMBOL_VALUE (sym) = valu;
2011 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
2012 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
2013 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
c5aa993b 2014 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
c906108c
SS
2015 add_symbol_to_list (sym, &file_symbols);
2016
2017 if (synonym)
2018 {
2019 /* Clone the sym and then modify it. */
2020 register struct symbol *typedef_sym = (struct symbol *)
c5aa993b 2021 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
c906108c
SS
2022 *typedef_sym = *sym;
2023 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
2024 SYMBOL_VALUE (typedef_sym) = valu;
2025 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
2026 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
2027 TYPE_NAME (SYMBOL_TYPE (sym))
c5aa993b 2028 = obconcat (&objfile->type_obstack, "", "", SYMBOL_NAME (sym));
c906108c
SS
2029 add_symbol_to_list (typedef_sym, &file_symbols);
2030 }
2031 break;
2032
2033 case 'V':
2034 /* Static symbol of local scope */
2035 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2036 SYMBOL_CLASS (sym) = LOC_STATIC;
2037 SYMBOL_VALUE_ADDRESS (sym) = valu;
2038#ifdef STATIC_TRANSFORM_NAME
2039 if (IS_STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym)))
c5aa993b
JM
2040 {
2041 struct minimal_symbol *msym;
2042 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
2043 if (msym != NULL)
2044 {
2045 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
2046 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
2047 }
2048 }
c906108c
SS
2049#endif
2050 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2051 if (os9k_stabs)
2052 add_symbol_to_list (sym, &global_symbols);
2053 else
2054 add_symbol_to_list (sym, &local_symbols);
2055 break;
2056
2057 case 'v':
2058 /* Reference parameter */
2059 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2060 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2061 SYMBOL_VALUE (sym) = valu;
2062 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2063 add_symbol_to_list (sym, &local_symbols);
2064 break;
2065
2066 case 'a':
2067 /* Reference parameter which is in a register. */
2068 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2069 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2070 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
64485362 2071 if (SYMBOL_VALUE (sym) >= NUM_REGS + NUM_PSEUDO_REGS)
c906108c 2072 {
64485362
AC
2073 complain (&reg_value_complaint, SYMBOL_VALUE (sym),
2074 NUM_REGS + NUM_PSEUDO_REGS,
c906108c 2075 SYMBOL_SOURCE_NAME (sym));
c5aa993b 2076 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
c906108c
SS
2077 }
2078 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2079 add_symbol_to_list (sym, &local_symbols);
2080 break;
2081
2082 case 'X':
2083 /* This is used by Sun FORTRAN for "function result value".
c5aa993b
JM
2084 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
2085 that Pascal uses it too, but when I tried it Pascal used
2086 "x:3" (local symbol) instead. */
c906108c
SS
2087 SYMBOL_TYPE (sym) = read_type (&p, objfile);
2088 SYMBOL_CLASS (sym) = LOC_LOCAL;
2089 SYMBOL_VALUE (sym) = valu;
2090 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2091 add_symbol_to_list (sym, &local_symbols);
2092 break;
2093
c5aa993b
JM
2094 /* New code added to support cfront stabs strings.
2095 Note: case 'P' already handled above */
c906108c
SS
2096 case 'Z':
2097 /* Cfront type continuation coming up!
c5aa993b
JM
2098 Find the original definition and add to it.
2099 We'll have to do this for the typedef too,
2100 since we cloned the symbol to define a type in read_type.
2101 Stabs info examples:
2102 __1C :Ztl
2103 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
2104 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
2105 where C is the name of the class.
2106 Unfortunately, we can't lookup the original symbol yet 'cuz
2107 we haven't finished reading all the symbols.
2108 Instead, we save it for processing later */
c906108c 2109 process_later (sym, p, resolve_cfront_continuation);
c5aa993b
JM
2110 SYMBOL_TYPE (sym) = error_type (&p, objfile); /* FIXME! change later */
2111 SYMBOL_CLASS (sym) = LOC_CONST;
2112 SYMBOL_VALUE (sym) = 0;
c906108c
SS
2113 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2114 /* Don't add to list - we'll delete it later when
2115 we add the continuation to the real sym */
2116 return sym;
2117 /* End of new code added to support cfront stabs strings */
2118
2119 default:
2120 SYMBOL_TYPE (sym) = error_type (&p, objfile);
2121 SYMBOL_CLASS (sym) = LOC_CONST;
2122 SYMBOL_VALUE (sym) = 0;
2123 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2124 add_symbol_to_list (sym, &file_symbols);
2125 break;
2126 }
2127
2128 /* When passing structures to a function, some systems sometimes pass
2129 the address in a register, not the structure itself. */
2130
d03e67c9
AC
2131 if (REG_STRUCT_HAS_ADDR_P ()
2132 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation, SYMBOL_TYPE (sym))
2133 && (SYMBOL_CLASS (sym) == LOC_REGPARM || SYMBOL_CLASS (sym) == LOC_ARG))
c906108c
SS
2134 {
2135 struct type *symbol_type = check_typedef (SYMBOL_TYPE (sym));
2136
2137 if ((TYPE_CODE (symbol_type) == TYPE_CODE_STRUCT)
2138 || (TYPE_CODE (symbol_type) == TYPE_CODE_UNION)
2139 || (TYPE_CODE (symbol_type) == TYPE_CODE_BITSTRING)
2140 || (TYPE_CODE (symbol_type) == TYPE_CODE_SET))
2141 {
2142 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to convert
2143 LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
2144 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
2145 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
2146 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th
2147 and subsequent arguments on the sparc, for example). */
2148 else if (SYMBOL_CLASS (sym) == LOC_ARG)
2149 SYMBOL_CLASS (sym) = LOC_REF_ARG;
2150 }
2151 }
2152
2153 /* Is there more to parse? For example LRS/alias information? */
2154 while (*p && *p == ';')
2155 {
2156 p++;
7a292a7a 2157 if (*p && p[0] == 'l' && p[1] == '(')
c5aa993b
JM
2158 {
2159 /* GNU extensions for live range splitting may be appended to
2160 the end of the stab string. eg. "l(#1,#2);l(#3,#5)" */
c906108c
SS
2161
2162 /* Resolve the live range and add it to SYM's live range list. */
2163 if (!resolve_live_range (objfile, sym, p))
2164 return NULL;
2165
2166 /* Find end of live range info. */
2167 p = strchr (p, ')');
c5aa993b 2168 if (!*p || *p != ')')
c906108c
SS
2169 {
2170 complain (&lrs_general_complaint, "live range format not recognized");
2171 return NULL;
2172 }
c5aa993b
JM
2173 p++;
2174 }
c906108c
SS
2175 }
2176 return sym;
2177}
2178
2179/* Add the live range found in P to the symbol SYM in objfile OBJFILE. Returns
2180 non-zero on success, zero otherwise. */
2181
2182static int
fba45db2 2183resolve_live_range (struct objfile *objfile, struct symbol *sym, char *p)
c906108c
SS
2184{
2185 int refnum;
2186 CORE_ADDR start, end;
2187
2188 /* Sanity check the beginning of the stabs string. */
2189 if (!*p || *p != 'l')
2190 {
2191 complain (&lrs_general_complaint, "live range string 1");
2192 return 0;
2193 }
2194 p++;
2195
2196 if (!*p || *p != '(')
2197 {
2198 complain (&lrs_general_complaint, "live range string 2");
2199 return 0;
2200 }
2201 p++;
c5aa993b 2202
c906108c
SS
2203 /* Get starting value of range and advance P past the reference id.
2204
2205 ?!? In theory, the process_reference should never fail, but we should
2206 catch that case just in case the compiler scrogged the stabs. */
2207 refnum = process_reference (&p);
2208 start = ref_search_value (refnum);
2209 if (!start)
2210 {
2211 complain (&lrs_general_complaint, "Live range symbol not found 1");
2212 return 0;
2213 }
2214
2215 if (!*p || *p != ',')
2216 {
2217 complain (&lrs_general_complaint, "live range string 3");
2218 return 0;
2219 }
2220 p++;
2221
2222 /* Get ending value of range and advance P past the reference id.
2223
2224 ?!? In theory, the process_reference should never fail, but we should
2225 catch that case just in case the compiler scrogged the stabs. */
2226 refnum = process_reference (&p);
2227 end = ref_search_value (refnum);
2228 if (!end)
2229 {
2230 complain (&lrs_general_complaint, "Live range symbol not found 2");
2231 return 0;
2232 }
2233
2234 if (!*p || *p != ')')
2235 {
2236 complain (&lrs_general_complaint, "live range string 4");
2237 return 0;
2238 }
2239
2240 /* Now that we know the bounds of the range, add it to the
2241 symbol. */
2242 add_live_range (objfile, sym, start, end);
2243
2244 return 1;
2245}
2246
2247/* Add a new live range defined by START and END to the symbol SYM
2248 in objfile OBJFILE. */
2249
2250static void
fba45db2
KB
2251add_live_range (struct objfile *objfile, struct symbol *sym, CORE_ADDR start,
2252 CORE_ADDR end)
c906108c
SS
2253{
2254 struct range_list *r, *rs;
2255
2256 if (start >= end)
2257 {
2258 complain (&lrs_general_complaint, "end of live range follows start");
2259 return;
2260 }
2261
2262 /* Alloc new live range structure. */
2263 r = (struct range_list *)
c5aa993b 2264 obstack_alloc (&objfile->type_obstack,
c906108c
SS
2265 sizeof (struct range_list));
2266 r->start = start;
2267 r->end = end;
2268 r->next = 0;
2269
2270 /* Append this range to the symbol's range list. */
2271 if (!SYMBOL_RANGES (sym))
2272 SYMBOL_RANGES (sym) = r;
2273 else
2274 {
2275 /* Get the last range for the symbol. */
2276 for (rs = SYMBOL_RANGES (sym); rs->next; rs = rs->next)
2277 ;
2278 rs->next = r;
2279 }
2280}
c906108c 2281\f
c5aa993b 2282
c906108c
SS
2283/* Skip rest of this symbol and return an error type.
2284
2285 General notes on error recovery: error_type always skips to the
2286 end of the symbol (modulo cretinous dbx symbol name continuation).
2287 Thus code like this:
2288
2289 if (*(*pp)++ != ';')
c5aa993b 2290 return error_type (pp, objfile);
c906108c
SS
2291
2292 is wrong because if *pp starts out pointing at '\0' (typically as the
2293 result of an earlier error), it will be incremented to point to the
2294 start of the next symbol, which might produce strange results, at least
2295 if you run off the end of the string table. Instead use
2296
2297 if (**pp != ';')
c5aa993b 2298 return error_type (pp, objfile);
c906108c
SS
2299 ++*pp;
2300
2301 or
2302
2303 if (**pp != ';')
c5aa993b 2304 foo = error_type (pp, objfile);
c906108c 2305 else
c5aa993b 2306 ++*pp;
c906108c
SS
2307
2308 And in case it isn't obvious, the point of all this hair is so the compiler
2309 can define new types and new syntaxes, and old versions of the
2310 debugger will be able to read the new symbol tables. */
2311
2312static struct type *
fba45db2 2313error_type (char **pp, struct objfile *objfile)
c906108c
SS
2314{
2315 complain (&error_type_complaint);
2316 while (1)
2317 {
2318 /* Skip to end of symbol. */
2319 while (**pp != '\0')
2320 {
2321 (*pp)++;
2322 }
2323
2324 /* Check for and handle cretinous dbx symbol name continuation! */
2325 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
2326 {
2327 *pp = next_symbol_text (objfile);
2328 }
2329 else
2330 {
2331 break;
2332 }
2333 }
2334 return (builtin_type_error);
2335}
c906108c 2336\f
c5aa993b 2337
c906108c
SS
2338/* Read type information or a type definition; return the type. Even
2339 though this routine accepts either type information or a type
2340 definition, the distinction is relevant--some parts of stabsread.c
2341 assume that type information starts with a digit, '-', or '(' in
2342 deciding whether to call read_type. */
2343
2344struct type *
fba45db2 2345read_type (register char **pp, struct objfile *objfile)
c906108c
SS
2346{
2347 register struct type *type = 0;
2348 struct type *type1;
2349 int typenums[2];
2350 char type_descriptor;
2351
2352 /* Size in bits of type if specified by a type attribute, or -1 if
2353 there is no size attribute. */
2354 int type_size = -1;
2355
2356 /* Used to distinguish string and bitstring from char-array and set. */
2357 int is_string = 0;
2358
2359 /* Read type number if present. The type number may be omitted.
2360 for instance in a two-dimensional array declared with type
2361 "ar1;1;10;ar1;1;10;4". */
2362 if ((**pp >= '0' && **pp <= '9')
2363 || **pp == '('
2364 || **pp == '-')
2365 {
2366 if (read_type_number (pp, typenums) != 0)
2367 return error_type (pp, objfile);
c5aa993b 2368
c906108c 2369 /* Type is not being defined here. Either it already exists,
c5aa993b
JM
2370 or this is a forward reference to it. dbx_alloc_type handles
2371 both cases. */
c906108c
SS
2372 if (**pp != '=')
2373 return dbx_alloc_type (typenums, objfile);
2374
2375 /* Type is being defined here. */
2376 /* Skip the '='.
c5aa993b
JM
2377 Also skip the type descriptor - we get it below with (*pp)[-1]. */
2378 (*pp) += 2;
c906108c
SS
2379 }
2380 else
2381 {
2382 /* 'typenums=' not present, type is anonymous. Read and return
c5aa993b 2383 the definition, but don't put it in the type vector. */
c906108c
SS
2384 typenums[0] = typenums[1] = -1;
2385 (*pp)++;
2386 }
2387
c5aa993b 2388again:
c906108c
SS
2389 type_descriptor = (*pp)[-1];
2390 switch (type_descriptor)
2391 {
2392 case 'x':
2393 {
2394 enum type_code code;
2395
2396 /* Used to index through file_symbols. */
2397 struct pending *ppt;
2398 int i;
c5aa993b 2399
c906108c
SS
2400 /* Name including "struct", etc. */
2401 char *type_name;
c5aa993b 2402
c906108c
SS
2403 {
2404 char *from, *to, *p, *q1, *q2;
c5aa993b 2405
c906108c
SS
2406 /* Set the type code according to the following letter. */
2407 switch ((*pp)[0])
2408 {
2409 case 's':
2410 code = TYPE_CODE_STRUCT;
2411 break;
2412 case 'u':
2413 code = TYPE_CODE_UNION;
2414 break;
2415 case 'e':
2416 code = TYPE_CODE_ENUM;
2417 break;
2418 default:
2419 {
2420 /* Complain and keep going, so compilers can invent new
2421 cross-reference types. */
2422 static struct complaint msg =
c5aa993b 2423 {"Unrecognized cross-reference type `%c'", 0, 0};
c906108c
SS
2424 complain (&msg, (*pp)[0]);
2425 code = TYPE_CODE_STRUCT;
2426 break;
2427 }
2428 }
c5aa993b 2429
c906108c
SS
2430 q1 = strchr (*pp, '<');
2431 p = strchr (*pp, ':');
2432 if (p == NULL)
2433 return error_type (pp, objfile);
2434 if (q1 && p > q1 && p[1] == ':')
2435 {
2436 int nesting_level = 0;
2437 for (q2 = q1; *q2; q2++)
2438 {
2439 if (*q2 == '<')
2440 nesting_level++;
2441 else if (*q2 == '>')
2442 nesting_level--;
2443 else if (*q2 == ':' && nesting_level == 0)
2444 break;
2445 }
2446 p = q2;
2447 if (*p != ':')
2448 return error_type (pp, objfile);
2449 }
c5aa993b
JM
2450 to = type_name =
2451 (char *) obstack_alloc (&objfile->type_obstack, p - *pp + 1);
2452
c906108c
SS
2453 /* Copy the name. */
2454 from = *pp + 1;
c5aa993b 2455 while (from < p)
c906108c
SS
2456 *to++ = *from++;
2457 *to = '\0';
c5aa993b 2458
c906108c
SS
2459 /* Set the pointer ahead of the name which we just read, and
2460 the colon. */
2461 *pp = from + 1;
2462 }
2463
2464 /* Now check to see whether the type has already been
2465 declared. This was written for arrays of cross-referenced
2466 types before we had TYPE_CODE_TARGET_STUBBED, so I'm pretty
2467 sure it is not necessary anymore. But it might be a good
2468 idea, to save a little memory. */
2469
2470 for (ppt = file_symbols; ppt; ppt = ppt->next)
2471 for (i = 0; i < ppt->nsyms; i++)
2472 {
2473 struct symbol *sym = ppt->symbol[i];
2474
2475 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2476 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2477 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
2478 && STREQ (SYMBOL_NAME (sym), type_name))
2479 {
c5aa993b 2480 obstack_free (&objfile->type_obstack, type_name);
c906108c
SS
2481 type = SYMBOL_TYPE (sym);
2482 return type;
2483 }
2484 }
2485
2486 /* Didn't find the type to which this refers, so we must
2487 be dealing with a forward reference. Allocate a type
2488 structure for it, and keep track of it so we can
2489 fill in the rest of the fields when we get the full
2490 type. */
2491 type = dbx_alloc_type (typenums, objfile);
2492 TYPE_CODE (type) = code;
2493 TYPE_TAG_NAME (type) = type_name;
c5aa993b 2494 INIT_CPLUS_SPECIFIC (type);
c906108c
SS
2495 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
2496
2497 add_undefined_type (type);
2498 return type;
2499 }
2500
c5aa993b 2501 case '-': /* RS/6000 built-in type */
c906108c
SS
2502 case '0':
2503 case '1':
2504 case '2':
2505 case '3':
2506 case '4':
2507 case '5':
2508 case '6':
2509 case '7':
2510 case '8':
2511 case '9':
2512 case '(':
2513 (*pp)--;
2514
2515 /* We deal with something like t(1,2)=(3,4)=... which
c5aa993b 2516 the Lucid compiler and recent gcc versions (post 2.7.3) use. */
c906108c
SS
2517
2518 /* Allocate and enter the typedef type first.
c5aa993b 2519 This handles recursive types. */
c906108c
SS
2520 type = dbx_alloc_type (typenums, objfile);
2521 TYPE_CODE (type) = TYPE_CODE_TYPEDEF;
c5aa993b
JM
2522 {
2523 struct type *xtype = read_type (pp, objfile);
c906108c
SS
2524 if (type == xtype)
2525 {
2526 /* It's being defined as itself. That means it is "void". */
2527 TYPE_CODE (type) = TYPE_CODE_VOID;
2528 TYPE_LENGTH (type) = 1;
2529 }
2530 else if (type_size >= 0 || is_string)
2531 {
2532 *type = *xtype;
2533 TYPE_NAME (type) = NULL;
2534 TYPE_TAG_NAME (type) = NULL;
2535 }
2536 else
2537 {
2538 TYPE_FLAGS (type) |= TYPE_FLAG_TARGET_STUB;
2539 TYPE_TARGET_TYPE (type) = xtype;
2540 }
2541 }
2542 break;
2543
c5aa993b
JM
2544 /* In the following types, we must be sure to overwrite any existing
2545 type that the typenums refer to, rather than allocating a new one
2546 and making the typenums point to the new one. This is because there
2547 may already be pointers to the existing type (if it had been
2548 forward-referenced), and we must change it to a pointer, function,
2549 reference, or whatever, *in-place*. */
c906108c
SS
2550
2551 case '*':
2552 type1 = read_type (pp, objfile);
2553 type = make_pointer_type (type1, dbx_lookup_type (typenums));
2554 break;
2555
c5aa993b 2556 case '&': /* Reference to another type */
c906108c
SS
2557 type1 = read_type (pp, objfile);
2558 type = make_reference_type (type1, dbx_lookup_type (typenums));
2559 break;
2560
c5aa993b 2561 case 'f': /* Function returning another type */
c906108c
SS
2562 if (os9k_stabs && **pp == '(')
2563 {
2564 /* Function prototype; parse it.
2565 We must conditionalize this on os9k_stabs because otherwise
2566 it could be confused with a Sun-style (1,3) typenumber
2567 (I think). */
2568 struct type *t;
2569 ++*pp;
2570 while (**pp != ')')
c5aa993b
JM
2571 {
2572 t = read_type (pp, objfile);
2573 if (**pp == ',')
2574 ++ * pp;
2575 }
c906108c
SS
2576 }
2577 type1 = read_type (pp, objfile);
2578 type = make_function_type (type1, dbx_lookup_type (typenums));
2579 break;
2580
c5aa993b
JM
2581 case 'k': /* Const qualifier on some type (Sun) */
2582 case 'c': /* Const qualifier on some type (OS9000) */
c906108c 2583 /* Because 'c' means other things to AIX and 'k' is perfectly good,
c5aa993b 2584 only accept 'c' in the os9k_stabs case. */
c906108c
SS
2585 if (type_descriptor == 'c' && !os9k_stabs)
2586 return error_type (pp, objfile);
2587 type = read_type (pp, objfile);
2588 /* FIXME! For now, we ignore const and volatile qualifiers. */
2589 break;
2590
c5aa993b
JM
2591 case 'B': /* Volatile qual on some type (Sun) */
2592 case 'i': /* Volatile qual on some type (OS9000) */
c906108c 2593 /* Because 'i' means other things to AIX and 'B' is perfectly good,
c5aa993b 2594 only accept 'i' in the os9k_stabs case. */
c906108c
SS
2595 if (type_descriptor == 'i' && !os9k_stabs)
2596 return error_type (pp, objfile);
2597 type = read_type (pp, objfile);
2598 /* FIXME! For now, we ignore const and volatile qualifiers. */
2599 break;
2600
2601 case '@':
c5aa993b
JM
2602 if (isdigit (**pp) || **pp == '(' || **pp == '-')
2603 { /* Member (class & variable) type */
c906108c
SS
2604 /* FIXME -- we should be doing smash_to_XXX types here. */
2605
2606 struct type *domain = read_type (pp, objfile);
2607 struct type *memtype;
2608
2609 if (**pp != ',')
2610 /* Invalid member type data format. */
2611 return error_type (pp, objfile);
2612 ++*pp;
2613
2614 memtype = read_type (pp, objfile);
2615 type = dbx_alloc_type (typenums, objfile);
2616 smash_to_member_type (type, domain, memtype);
2617 }
c5aa993b
JM
2618 else
2619 /* type attribute */
c906108c
SS
2620 {
2621 char *attr = *pp;
2622 /* Skip to the semicolon. */
2623 while (**pp != ';' && **pp != '\0')
2624 ++(*pp);
2625 if (**pp == '\0')
2626 return error_type (pp, objfile);
2627 else
c5aa993b 2628 ++ * pp; /* Skip the semicolon. */
c906108c
SS
2629
2630 switch (*attr)
2631 {
2632 case 's':
2633 type_size = atoi (attr + 1);
2634 if (type_size <= 0)
2635 type_size = -1;
2636 break;
2637
2638 case 'S':
2639 is_string = 1;
2640 break;
2641
2642 default:
2643 /* Ignore unrecognized type attributes, so future compilers
c5aa993b 2644 can invent new ones. */
c906108c
SS
2645 break;
2646 }
2647 ++*pp;
2648 goto again;
2649 }
2650 break;
2651
c5aa993b 2652 case '#': /* Method (class & fn) type */
c906108c
SS
2653 if ((*pp)[0] == '#')
2654 {
2655 /* We'll get the parameter types from the name. */
2656 struct type *return_type;
2657
2658 (*pp)++;
2659 return_type = read_type (pp, objfile);
2660 if (*(*pp)++ != ';')
2661 complain (&invalid_member_complaint, symnum);
2662 type = allocate_stub_method (return_type);
2663 if (typenums[0] != -1)
2664 *dbx_lookup_type (typenums) = type;
2665 }
2666 else
2667 {
2668 struct type *domain = read_type (pp, objfile);
2669 struct type *return_type;
2670 struct type **args;
2671
2672 if (**pp != ',')
2673 /* Invalid member type data format. */
2674 return error_type (pp, objfile);
2675 else
2676 ++(*pp);
2677
2678 return_type = read_type (pp, objfile);
2679 args = read_args (pp, ';', objfile);
2680 type = dbx_alloc_type (typenums, objfile);
2681 smash_to_method_type (type, domain, return_type, args);
2682 }
2683 break;
2684
c5aa993b 2685 case 'r': /* Range type */
c906108c
SS
2686 type = read_range_type (pp, typenums, objfile);
2687 if (typenums[0] != -1)
2688 *dbx_lookup_type (typenums) = type;
2689 break;
2690
2691 case 'b':
2692 if (os9k_stabs)
2693 /* Const and volatile qualified type. */
2694 type = read_type (pp, objfile);
2695 else
2696 {
2697 /* Sun ACC builtin int type */
2698 type = read_sun_builtin_type (pp, typenums, objfile);
2699 if (typenums[0] != -1)
2700 *dbx_lookup_type (typenums) = type;
2701 }
2702 break;
2703
c5aa993b 2704 case 'R': /* Sun ACC builtin float type */
c906108c
SS
2705 type = read_sun_floating_type (pp, typenums, objfile);
2706 if (typenums[0] != -1)
2707 *dbx_lookup_type (typenums) = type;
2708 break;
c5aa993b
JM
2709
2710 case 'e': /* Enumeration type */
c906108c
SS
2711 type = dbx_alloc_type (typenums, objfile);
2712 type = read_enum_type (pp, type, objfile);
2713 if (typenums[0] != -1)
2714 *dbx_lookup_type (typenums) = type;
2715 break;
2716
c5aa993b
JM
2717 case 's': /* Struct type */
2718 case 'u': /* Union type */
c906108c
SS
2719 type = dbx_alloc_type (typenums, objfile);
2720 switch (type_descriptor)
2721 {
c5aa993b
JM
2722 case 's':
2723 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2724 break;
2725 case 'u':
2726 TYPE_CODE (type) = TYPE_CODE_UNION;
2727 break;
c906108c
SS
2728 }
2729 type = read_struct_type (pp, type, objfile);
2730 break;
2731
c5aa993b 2732 case 'a': /* Array type */
c906108c
SS
2733 if (**pp != 'r')
2734 return error_type (pp, objfile);
2735 ++*pp;
c5aa993b 2736
c906108c
SS
2737 type = dbx_alloc_type (typenums, objfile);
2738 type = read_array_type (pp, type, objfile);
2739 if (is_string)
2740 TYPE_CODE (type) = TYPE_CODE_STRING;
2741 break;
2742
2743 case 'S':
2744 type1 = read_type (pp, objfile);
c5aa993b 2745 type = create_set_type ((struct type *) NULL, type1);
c906108c
SS
2746 if (is_string)
2747 TYPE_CODE (type) = TYPE_CODE_BITSTRING;
2748 if (typenums[0] != -1)
2749 *dbx_lookup_type (typenums) = type;
2750 break;
2751
2752 default:
2753 --*pp; /* Go back to the symbol in error */
c5aa993b 2754 /* Particularly important if it was \0! */
c906108c
SS
2755 return error_type (pp, objfile);
2756 }
2757
2758 if (type == 0)
2759 {
2760 warning ("GDB internal error, type is NULL in stabsread.c\n");
2761 return error_type (pp, objfile);
2762 }
2763
2764 /* Size specified in a type attribute overrides any other size. */
2765 if (type_size != -1)
2766 TYPE_LENGTH (type) = (type_size + TARGET_CHAR_BIT - 1) / TARGET_CHAR_BIT;
2767
2768 return type;
2769}
2770\f
2771/* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
2772 Return the proper type node for a given builtin type number. */
2773
2774static struct type *
fba45db2 2775rs6000_builtin_type (int typenum)
c906108c
SS
2776{
2777 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
2778#define NUMBER_RECOGNIZED 34
2779 /* This includes an empty slot for type number -0. */
2780 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
2781 struct type *rettype = NULL;
2782
2783 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
2784 {
2785 complain (&rs6000_builtin_complaint, typenum);
2786 return builtin_type_error;
2787 }
2788 if (negative_types[-typenum] != NULL)
2789 return negative_types[-typenum];
2790
2791#if TARGET_CHAR_BIT != 8
c5aa993b 2792#error This code wrong for TARGET_CHAR_BIT not 8
c906108c
SS
2793 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
2794 that if that ever becomes not true, the correct fix will be to
2795 make the size in the struct type to be in bits, not in units of
2796 TARGET_CHAR_BIT. */
2797#endif
2798
2799 switch (-typenum)
2800 {
2801 case 1:
2802 /* The size of this and all the other types are fixed, defined
c5aa993b
JM
2803 by the debugging format. If there is a type called "int" which
2804 is other than 32 bits, then it should use a new negative type
2805 number (or avoid negative type numbers for that case).
2806 See stabs.texinfo. */
c906108c
SS
2807 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
2808 break;
2809 case 2:
2810 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
2811 break;
2812 case 3:
2813 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
2814 break;
2815 case 4:
2816 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
2817 break;
2818 case 5:
2819 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
2820 "unsigned char", NULL);
2821 break;
2822 case 6:
2823 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
2824 break;
2825 case 7:
2826 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
2827 "unsigned short", NULL);
2828 break;
2829 case 8:
2830 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2831 "unsigned int", NULL);
2832 break;
2833 case 9:
2834 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2835 "unsigned", NULL);
2836 case 10:
2837 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
2838 "unsigned long", NULL);
2839 break;
2840 case 11:
2841 rettype = init_type (TYPE_CODE_VOID, 1, 0, "void", NULL);
2842 break;
2843 case 12:
2844 /* IEEE single precision (32 bit). */
2845 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
2846 break;
2847 case 13:
2848 /* IEEE double precision (64 bit). */
2849 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
2850 break;
2851 case 14:
2852 /* This is an IEEE double on the RS/6000, and different machines with
c5aa993b
JM
2853 different sizes for "long double" should use different negative
2854 type numbers. See stabs.texinfo. */
c906108c
SS
2855 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
2856 break;
2857 case 15:
2858 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
2859 break;
2860 case 16:
2861 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2862 "boolean", NULL);
2863 break;
2864 case 17:
2865 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
2866 break;
2867 case 18:
2868 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
2869 break;
2870 case 19:
2871 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
2872 break;
2873 case 20:
2874 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
2875 "character", NULL);
2876 break;
2877 case 21:
2878 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
2879 "logical*1", NULL);
2880 break;
2881 case 22:
2882 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
2883 "logical*2", NULL);
2884 break;
2885 case 23:
2886 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2887 "logical*4", NULL);
2888 break;
2889 case 24:
2890 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
2891 "logical", NULL);
2892 break;
2893 case 25:
2894 /* Complex type consisting of two IEEE single precision values. */
2895 rettype = init_type (TYPE_CODE_COMPLEX, 8, 0, "complex", NULL);
2896 break;
2897 case 26:
2898 /* Complex type consisting of two IEEE double precision values. */
2899 rettype = init_type (TYPE_CODE_COMPLEX, 16, 0, "double complex", NULL);
2900 break;
2901 case 27:
2902 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
2903 break;
2904 case 28:
2905 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
2906 break;
2907 case 29:
2908 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
2909 break;
2910 case 30:
2911 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
2912 break;
2913 case 31:
2914 rettype = init_type (TYPE_CODE_INT, 8, 0, "long long", NULL);
2915 break;
2916 case 32:
2917 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2918 "unsigned long long", NULL);
2919 break;
2920 case 33:
2921 rettype = init_type (TYPE_CODE_INT, 8, TYPE_FLAG_UNSIGNED,
2922 "logical*8", NULL);
2923 break;
2924 case 34:
2925 rettype = init_type (TYPE_CODE_INT, 8, 0, "integer*8", NULL);
2926 break;
2927 }
2928 negative_types[-typenum] = rettype;
2929 return rettype;
2930}
2931\f
2932/* This page contains subroutines of read_type. */
2933
2934/* Read member function stabs info for C++ classes. The form of each member
2935 function data is:
2936
c5aa993b 2937 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
c906108c
SS
2938
2939 An example with two member functions is:
2940
c5aa993b 2941 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
c906108c
SS
2942
2943 For the case of overloaded operators, the format is op$::*.funcs, where
2944 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
2945 name (such as `+=') and `.' marks the end of the operator name.
2946
2947 Returns 1 for success, 0 for failure. */
2948
2949static int
fba45db2
KB
2950read_member_functions (struct field_info *fip, char **pp, struct type *type,
2951 struct objfile *objfile)
c906108c
SS
2952{
2953 int nfn_fields = 0;
2954 int length = 0;
2955 /* Total number of member functions defined in this class. If the class
2956 defines two `f' functions, and one `g' function, then this will have
2957 the value 3. */
2958 int total_length = 0;
2959 int i;
2960 struct next_fnfield
2961 {
2962 struct next_fnfield *next;
2963 struct fn_field fn_field;
c5aa993b
JM
2964 }
2965 *sublist;
c906108c
SS
2966 struct type *look_ahead_type;
2967 struct next_fnfieldlist *new_fnlist;
2968 struct next_fnfield *new_sublist;
2969 char *main_fn_name;
2970 register char *p;
c5aa993b 2971
c906108c
SS
2972 /* Process each list until we find something that is not a member function
2973 or find the end of the functions. */
2974
2975 while (**pp != ';')
2976 {
2977 /* We should be positioned at the start of the function name.
c5aa993b
JM
2978 Scan forward to find the first ':' and if it is not the
2979 first of a "::" delimiter, then this is not a member function. */
c906108c
SS
2980 p = *pp;
2981 while (*p != ':')
2982 {
2983 p++;
2984 }
2985 if (p[1] != ':')
2986 {
2987 break;
2988 }
2989
2990 sublist = NULL;
2991 look_ahead_type = NULL;
2992 length = 0;
c5aa993b 2993
c906108c
SS
2994 new_fnlist = (struct next_fnfieldlist *)
2995 xmalloc (sizeof (struct next_fnfieldlist));
b8c9b27d 2996 make_cleanup (xfree, new_fnlist);
c906108c 2997 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
c5aa993b 2998
c906108c
SS
2999 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && is_cplus_marker ((*pp)[2]))
3000 {
3001 /* This is a completely wierd case. In order to stuff in the
3002 names that might contain colons (the usual name delimiter),
3003 Mike Tiemann defined a different name format which is
3004 signalled if the identifier is "op$". In that case, the
3005 format is "op$::XXXX." where XXXX is the name. This is
3006 used for names like "+" or "=". YUUUUUUUK! FIXME! */
3007 /* This lets the user type "break operator+".
3008 We could just put in "+" as the name, but that wouldn't
3009 work for "*". */
c5aa993b
JM
3010 static char opname[32] =
3011 {'o', 'p', CPLUS_MARKER};
c906108c 3012 char *o = opname + 3;
c5aa993b 3013
c906108c
SS
3014 /* Skip past '::'. */
3015 *pp = p + 2;
3016
3017 STABS_CONTINUE (pp, objfile);
3018 p = *pp;
3019 while (*p != '.')
3020 {
3021 *o++ = *p++;
3022 }
3023 main_fn_name = savestring (opname, o - opname);
3024 /* Skip past '.' */
3025 *pp = p + 1;
3026 }
3027 else
3028 {
3029 main_fn_name = savestring (*pp, p - *pp);
3030 /* Skip past '::'. */
3031 *pp = p + 2;
3032 }
c5aa993b
JM
3033 new_fnlist->fn_fieldlist.name = main_fn_name;
3034
c906108c
SS
3035 do
3036 {
3037 new_sublist =
3038 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
b8c9b27d 3039 make_cleanup (xfree, new_sublist);
c906108c 3040 memset (new_sublist, 0, sizeof (struct next_fnfield));
c5aa993b 3041
c906108c
SS
3042 /* Check for and handle cretinous dbx symbol name continuation! */
3043 if (look_ahead_type == NULL)
3044 {
3045 /* Normal case. */
3046 STABS_CONTINUE (pp, objfile);
c5aa993b
JM
3047
3048 new_sublist->fn_field.type = read_type (pp, objfile);
c906108c
SS
3049 if (**pp != ':')
3050 {
3051 /* Invalid symtab info for member function. */
3052 return 0;
3053 }
3054 }
3055 else
3056 {
3057 /* g++ version 1 kludge */
c5aa993b 3058 new_sublist->fn_field.type = look_ahead_type;
c906108c
SS
3059 look_ahead_type = NULL;
3060 }
c5aa993b 3061
c906108c
SS
3062 (*pp)++;
3063 p = *pp;
3064 while (*p != ';')
3065 {
3066 p++;
3067 }
c5aa993b 3068
c906108c
SS
3069 /* If this is just a stub, then we don't have the real name here. */
3070
c5aa993b 3071 if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
c906108c 3072 {
c5aa993b
JM
3073 if (!TYPE_DOMAIN_TYPE (new_sublist->fn_field.type))
3074 TYPE_DOMAIN_TYPE (new_sublist->fn_field.type) = type;
3075 new_sublist->fn_field.is_stub = 1;
c906108c 3076 }
c5aa993b 3077 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
c906108c 3078 *pp = p + 1;
c5aa993b 3079
c906108c
SS
3080 /* Set this member function's visibility fields. */
3081 switch (*(*pp)++)
3082 {
c5aa993b
JM
3083 case VISIBILITY_PRIVATE:
3084 new_sublist->fn_field.is_private = 1;
3085 break;
3086 case VISIBILITY_PROTECTED:
3087 new_sublist->fn_field.is_protected = 1;
3088 break;
c906108c 3089 }
c5aa993b 3090
c906108c
SS
3091 STABS_CONTINUE (pp, objfile);
3092 switch (**pp)
3093 {
c5aa993b
JM
3094 case 'A': /* Normal functions. */
3095 new_sublist->fn_field.is_const = 0;
3096 new_sublist->fn_field.is_volatile = 0;
3097 (*pp)++;
3098 break;
3099 case 'B': /* `const' member functions. */
3100 new_sublist->fn_field.is_const = 1;
3101 new_sublist->fn_field.is_volatile = 0;
3102 (*pp)++;
3103 break;
3104 case 'C': /* `volatile' member function. */
3105 new_sublist->fn_field.is_const = 0;
3106 new_sublist->fn_field.is_volatile = 1;
3107 (*pp)++;
3108 break;
3109 case 'D': /* `const volatile' member function. */
3110 new_sublist->fn_field.is_const = 1;
3111 new_sublist->fn_field.is_volatile = 1;
3112 (*pp)++;
3113 break;
3114 case '*': /* File compiled with g++ version 1 -- no info */
3115 case '?':
3116 case '.':
3117 break;
3118 default:
3119 complain (&const_vol_complaint, **pp);
3120 break;
c906108c 3121 }
c5aa993b 3122
c906108c
SS
3123 switch (*(*pp)++)
3124 {
c5aa993b 3125 case '*':
c906108c
SS
3126 {
3127 int nbits;
c5aa993b 3128 /* virtual member function, followed by index.
c906108c
SS
3129 The sign bit is set to distinguish pointers-to-methods
3130 from virtual function indicies. Since the array is
3131 in words, the quantity must be shifted left by 1
3132 on 16 bit machine, and by 2 on 32 bit machine, forcing
3133 the sign bit out, and usable as a valid index into
3134 the array. Remove the sign bit here. */
c5aa993b 3135 new_sublist->fn_field.voffset =
c906108c
SS
3136 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
3137 if (nbits != 0)
3138 return 0;
c5aa993b 3139
c906108c
SS
3140 STABS_CONTINUE (pp, objfile);
3141 if (**pp == ';' || **pp == '\0')
3142 {
3143 /* Must be g++ version 1. */
c5aa993b 3144 new_sublist->fn_field.fcontext = 0;
c906108c
SS
3145 }
3146 else
3147 {
3148 /* Figure out from whence this virtual function came.
3149 It may belong to virtual function table of
3150 one of its baseclasses. */
3151 look_ahead_type = read_type (pp, objfile);
3152 if (**pp == ':')
3153 {
3154 /* g++ version 1 overloaded methods. */
3155 }
3156 else
3157 {
c5aa993b 3158 new_sublist->fn_field.fcontext = look_ahead_type;
c906108c
SS
3159 if (**pp != ';')
3160 {
3161 return 0;
3162 }
3163 else
3164 {
3165 ++*pp;
3166 }
3167 look_ahead_type = NULL;
3168 }
3169 }
3170 break;
3171 }
c5aa993b
JM
3172 case '?':
3173 /* static member function. */
3174 new_sublist->fn_field.voffset = VOFFSET_STATIC;
3175 if (strncmp (new_sublist->fn_field.physname,
3176 main_fn_name, strlen (main_fn_name)))
3177 {
3178 new_sublist->fn_field.is_stub = 1;
3179 }
3180 break;
3181
3182 default:
3183 /* error */
3184 complain (&member_fn_complaint, (*pp)[-1]);
3185 /* Fall through into normal member function. */
3186
3187 case '.':
3188 /* normal member function. */
3189 new_sublist->fn_field.voffset = 0;
3190 new_sublist->fn_field.fcontext = 0;
3191 break;
c906108c 3192 }
c5aa993b
JM
3193
3194 new_sublist->next = sublist;
c906108c
SS
3195 sublist = new_sublist;
3196 length++;
3197 STABS_CONTINUE (pp, objfile);
3198 }
3199 while (**pp != ';' && **pp != '\0');
c5aa993b 3200
c906108c 3201 (*pp)++;
c5aa993b
JM
3202
3203 new_fnlist->fn_fieldlist.fn_fields = (struct fn_field *)
3204 obstack_alloc (&objfile->type_obstack,
c906108c 3205 sizeof (struct fn_field) * length);
c5aa993b 3206 memset (new_fnlist->fn_fieldlist.fn_fields, 0,
c906108c 3207 sizeof (struct fn_field) * length);
c5aa993b 3208 for (i = length; (i--, sublist); sublist = sublist->next)
c906108c 3209 {
c5aa993b 3210 new_fnlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
c906108c 3211 }
c5aa993b
JM
3212
3213 new_fnlist->fn_fieldlist.length = length;
3214 new_fnlist->next = fip->fnlist;
3215 fip->fnlist = new_fnlist;
c906108c
SS
3216 nfn_fields++;
3217 total_length += length;
3218 STABS_CONTINUE (pp, objfile);
3219 }
3220
3221 if (nfn_fields)
3222 {
3223 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3224 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
3225 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
3226 memset (TYPE_FN_FIELDLISTS (type), 0,
3227 sizeof (struct fn_fieldlist) * nfn_fields);
3228 TYPE_NFN_FIELDS (type) = nfn_fields;
3229 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
3230 }
3231
3232 return 1;
3233}
3234
3235/* Special GNU C++ name.
3236
3237 Returns 1 for success, 0 for failure. "failure" means that we can't
3238 keep parsing and it's time for error_type(). */
3239
3240static int
fba45db2
KB
3241read_cpp_abbrev (struct field_info *fip, char **pp, struct type *type,
3242 struct objfile *objfile)
c906108c
SS
3243{
3244 register char *p;
3245 char *name;
3246 char cpp_abbrev;
3247 struct type *context;
3248
3249 p = *pp;
3250 if (*++p == 'v')
3251 {
3252 name = NULL;
3253 cpp_abbrev = *++p;
3254
3255 *pp = p + 1;
3256
3257 /* At this point, *pp points to something like "22:23=*22...",
c5aa993b
JM
3258 where the type number before the ':' is the "context" and
3259 everything after is a regular type definition. Lookup the
3260 type, find it's name, and construct the field name. */
c906108c
SS
3261
3262 context = read_type (pp, objfile);
3263
3264 switch (cpp_abbrev)
3265 {
c5aa993b
JM
3266 case 'f': /* $vf -- a virtual function table pointer */
3267 fip->list->field.name =
3268 obconcat (&objfile->type_obstack, vptr_name, "", "");
3269 break;
c906108c 3270
c5aa993b
JM
3271 case 'b': /* $vb -- a virtual bsomethingorother */
3272 name = type_name_no_tag (context);
3273 if (name == NULL)
3274 {
3275 complain (&invalid_cpp_type_complaint, symnum);
3276 name = "FOO";
3277 }
3278 fip->list->field.name =
3279 obconcat (&objfile->type_obstack, vb_name, name, "");
3280 break;
c906108c 3281
c5aa993b
JM
3282 default:
3283 complain (&invalid_cpp_abbrev_complaint, *pp);
3284 fip->list->field.name =
3285 obconcat (&objfile->type_obstack,
3286 "INVALID_CPLUSPLUS_ABBREV", "", "");
3287 break;
c906108c
SS
3288 }
3289
3290 /* At this point, *pp points to the ':'. Skip it and read the
c5aa993b 3291 field type. */
c906108c
SS
3292
3293 p = ++(*pp);
3294 if (p[-1] != ':')
3295 {
3296 complain (&invalid_cpp_abbrev_complaint, *pp);
3297 return 0;
3298 }
3299 fip->list->field.type = read_type (pp, objfile);
3300 if (**pp == ',')
c5aa993b 3301 (*pp)++; /* Skip the comma. */
c906108c
SS
3302 else
3303 return 0;
3304
3305 {
3306 int nbits;
3307 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ';', &nbits);
3308 if (nbits != 0)
3309 return 0;
3310 }
3311 /* This field is unpacked. */
3312 FIELD_BITSIZE (fip->list->field) = 0;
3313 fip->list->visibility = VISIBILITY_PRIVATE;
3314 }
3315 else
3316 {
3317 complain (&invalid_cpp_abbrev_complaint, *pp);
3318 /* We have no idea what syntax an unrecognized abbrev would have, so
c5aa993b
JM
3319 better return 0. If we returned 1, we would need to at least advance
3320 *pp to avoid an infinite loop. */
c906108c
SS
3321 return 0;
3322 }
3323 return 1;
3324}
3325
3326static void
fba45db2
KB
3327read_one_struct_field (struct field_info *fip, char **pp, char *p,
3328 struct type *type, struct objfile *objfile)
c906108c
SS
3329{
3330 /* The following is code to work around cfront generated stabs.
3331 The stabs contains full mangled name for each field.
3332 We try to demangle the name and extract the field name out of it.
c5aa993b 3333 */
c906108c
SS
3334 if (ARM_DEMANGLING && current_subfile->language == language_cplus)
3335 {
3336 char save_p;
3337 char *dem, *dem_p;
3338 save_p = *p;
3339 *p = '\0';
3340 dem = cplus_demangle (*pp, DMGL_ANSI | DMGL_PARAMS);
3341 if (dem != NULL)
c5aa993b
JM
3342 {
3343 dem_p = strrchr (dem, ':');
3344 if (dem_p != 0 && *(dem_p - 1) == ':')
3345 dem_p++;
3346 FIELD_NAME (fip->list->field) =
3347 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
3348 }
c906108c 3349 else
c5aa993b
JM
3350 {
3351 FIELD_NAME (fip->list->field) =
3352 obsavestring (*pp, p - *pp, &objfile->type_obstack);
3353 }
c906108c
SS
3354 *p = save_p;
3355 }
3356 /* end of code for cfront work around */
3357
3358 else
c5aa993b
JM
3359 fip->list->field.name =
3360 obsavestring (*pp, p - *pp, &objfile->type_obstack);
c906108c
SS
3361 *pp = p + 1;
3362
3363 /* This means we have a visibility for a field coming. */
3364 if (**pp == '/')
3365 {
3366 (*pp)++;
c5aa993b 3367 fip->list->visibility = *(*pp)++;
c906108c
SS
3368 }
3369 else
3370 {
3371 /* normal dbx-style format, no explicit visibility */
c5aa993b 3372 fip->list->visibility = VISIBILITY_PUBLIC;
c906108c
SS
3373 }
3374
c5aa993b 3375 fip->list->field.type = read_type (pp, objfile);
c906108c
SS
3376 if (**pp == ':')
3377 {
3378 p = ++(*pp);
3379#if 0
3380 /* Possible future hook for nested types. */
3381 if (**pp == '!')
3382 {
c5aa993b 3383 fip->list->field.bitpos = (long) -2; /* nested type */
c906108c
SS
3384 p = ++(*pp);
3385 }
c5aa993b
JM
3386 else
3387 ...;
c906108c 3388#endif
c5aa993b 3389 while (*p != ';')
c906108c
SS
3390 {
3391 p++;
3392 }
3393 /* Static class member. */
3394 SET_FIELD_PHYSNAME (fip->list->field, savestring (*pp, p - *pp));
3395 *pp = p + 1;
3396 return;
3397 }
3398 else if (**pp != ',')
3399 {
3400 /* Bad structure-type format. */
3401 complain (&stabs_general_complaint, "bad structure-type format");
3402 return;
3403 }
3404
3405 (*pp)++; /* Skip the comma. */
3406
3407 {
3408 int nbits;
3409 FIELD_BITPOS (fip->list->field) = read_huge_number (pp, ',', &nbits);
3410 if (nbits != 0)
3411 {
3412 complain (&stabs_general_complaint, "bad structure-type format");
3413 return;
3414 }
3415 FIELD_BITSIZE (fip->list->field) = read_huge_number (pp, ';', &nbits);
3416 if (nbits != 0)
3417 {
3418 complain (&stabs_general_complaint, "bad structure-type format");
3419 return;
3420 }
3421 }
3422
3423 if (FIELD_BITPOS (fip->list->field) == 0
3424 && FIELD_BITSIZE (fip->list->field) == 0)
3425 {
3426 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
c5aa993b
JM
3427 it is a field which has been optimized out. The correct stab for
3428 this case is to use VISIBILITY_IGNORE, but that is a recent
3429 invention. (2) It is a 0-size array. For example
3430 union { int num; char str[0]; } foo. Printing "<no value>" for
3431 str in "p foo" is OK, since foo.str (and thus foo.str[3])
3432 will continue to work, and a 0-size array as a whole doesn't
3433 have any contents to print.
3434
3435 I suspect this probably could also happen with gcc -gstabs (not
3436 -gstabs+) for static fields, and perhaps other C++ extensions.
3437 Hopefully few people use -gstabs with gdb, since it is intended
3438 for dbx compatibility. */
c906108c
SS
3439
3440 /* Ignore this field. */
c5aa993b 3441 fip->list->visibility = VISIBILITY_IGNORE;
c906108c
SS
3442 }
3443 else
3444 {
3445 /* Detect an unpacked field and mark it as such.
c5aa993b
JM
3446 dbx gives a bit size for all fields.
3447 Note that forward refs cannot be packed,
3448 and treat enums as if they had the width of ints. */
c906108c
SS
3449
3450 struct type *field_type = check_typedef (FIELD_TYPE (fip->list->field));
3451
3452 if (TYPE_CODE (field_type) != TYPE_CODE_INT
3453 && TYPE_CODE (field_type) != TYPE_CODE_RANGE
3454 && TYPE_CODE (field_type) != TYPE_CODE_BOOL
3455 && TYPE_CODE (field_type) != TYPE_CODE_ENUM)
3456 {
3457 FIELD_BITSIZE (fip->list->field) = 0;
3458 }
c5aa993b 3459 if ((FIELD_BITSIZE (fip->list->field)
c906108c
SS
3460 == TARGET_CHAR_BIT * TYPE_LENGTH (field_type)
3461 || (TYPE_CODE (field_type) == TYPE_CODE_ENUM
c5aa993b
JM
3462 && FIELD_BITSIZE (fip->list->field) == TARGET_INT_BIT)
3463 )
c906108c
SS
3464 &&
3465 FIELD_BITPOS (fip->list->field) % 8 == 0)
3466 {
3467 FIELD_BITSIZE (fip->list->field) = 0;
3468 }
3469 }
3470}
3471
3472
3473/* Read struct or class data fields. They have the form:
3474
c5aa993b 3475 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
c906108c
SS
3476
3477 At the end, we see a semicolon instead of a field.
3478
3479 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
3480 a static field.
3481
3482 The optional VISIBILITY is one of:
3483
c5aa993b
JM
3484 '/0' (VISIBILITY_PRIVATE)
3485 '/1' (VISIBILITY_PROTECTED)
3486 '/2' (VISIBILITY_PUBLIC)
3487 '/9' (VISIBILITY_IGNORE)
c906108c
SS
3488
3489 or nothing, for C style fields with public visibility.
3490
3491 Returns 1 for success, 0 for failure. */
3492
3493static int
fba45db2
KB
3494read_struct_fields (struct field_info *fip, char **pp, struct type *type,
3495 struct objfile *objfile)
c906108c
SS
3496{
3497 register char *p;
3498 struct nextfield *new;
3499
3500 /* We better set p right now, in case there are no fields at all... */
3501
3502 p = *pp;
3503
3504 /* Read each data member type until we find the terminating ';' at the end of
3505 the data member list, or break for some other reason such as finding the
3506 start of the member function list. */
3507
3508 while (**pp != ';')
3509 {
c5aa993b
JM
3510 if (os9k_stabs && **pp == ',')
3511 break;
c906108c
SS
3512 STABS_CONTINUE (pp, objfile);
3513 /* Get space to record the next field's data. */
3514 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
b8c9b27d 3515 make_cleanup (xfree, new);
c906108c 3516 memset (new, 0, sizeof (struct nextfield));
c5aa993b
JM
3517 new->next = fip->list;
3518 fip->list = new;
c906108c
SS
3519
3520 /* Get the field name. */
3521 p = *pp;
3522
3523 /* If is starts with CPLUS_MARKER it is a special abbreviation,
c5aa993b
JM
3524 unless the CPLUS_MARKER is followed by an underscore, in
3525 which case it is just the name of an anonymous type, which we
3526 should handle like any other type name. */
c906108c
SS
3527
3528 if (is_cplus_marker (p[0]) && p[1] != '_')
3529 {
3530 if (!read_cpp_abbrev (fip, pp, type, objfile))
3531 return 0;
3532 continue;
3533 }
3534
3535 /* Look for the ':' that separates the field name from the field
c5aa993b
JM
3536 values. Data members are delimited by a single ':', while member
3537 functions are delimited by a pair of ':'s. When we hit the member
3538 functions (if any), terminate scan loop and return. */
c906108c 3539
c5aa993b 3540 while (*p != ':' && *p != '\0')
c906108c
SS
3541 {
3542 p++;
3543 }
3544 if (*p == '\0')
3545 return 0;
3546
3547 /* Check to see if we have hit the member functions yet. */
3548 if (p[1] == ':')
3549 {
3550 break;
3551 }
3552 read_one_struct_field (fip, pp, p, type, objfile);
3553 }
3554 if (p[0] == ':' && p[1] == ':')
3555 {
3556 /* chill the list of fields: the last entry (at the head) is a
c5aa993b
JM
3557 partially constructed entry which we now scrub. */
3558 fip->list = fip->list->next;
c906108c
SS
3559 }
3560 return 1;
3561}
9846de1b 3562/* *INDENT-OFF* */
c906108c
SS
3563/* The stabs for C++ derived classes contain baseclass information which
3564 is marked by a '!' character after the total size. This function is
3565 called when we encounter the baseclass marker, and slurps up all the
3566 baseclass information.
3567
3568 Immediately following the '!' marker is the number of base classes that
3569 the class is derived from, followed by information for each base class.
3570 For each base class, there are two visibility specifiers, a bit offset
3571 to the base class information within the derived class, a reference to
3572 the type for the base class, and a terminating semicolon.
3573
3574 A typical example, with two base classes, would be "!2,020,19;0264,21;".
3575 ^^ ^ ^ ^ ^ ^ ^
3576 Baseclass information marker __________________|| | | | | | |
3577 Number of baseclasses __________________________| | | | | | |
3578 Visibility specifiers (2) ________________________| | | | | |
3579 Offset in bits from start of class _________________| | | | |
3580 Type number for base class ___________________________| | | |
3581 Visibility specifiers (2) _______________________________| | |
3582 Offset in bits from start of class ________________________| |
3583 Type number of base class ____________________________________|
3584
3585 Return 1 for success, 0 for (error-type-inducing) failure. */
9846de1b 3586/* *INDENT-ON* */
c906108c 3587
c5aa993b
JM
3588
3589
c906108c 3590static int
fba45db2
KB
3591read_baseclasses (struct field_info *fip, char **pp, struct type *type,
3592 struct objfile *objfile)
c906108c
SS
3593{
3594 int i;
3595 struct nextfield *new;
3596
3597 if (**pp != '!')
3598 {
3599 return 1;
3600 }
3601 else
3602 {
3603 /* Skip the '!' baseclass information marker. */
3604 (*pp)++;
3605 }
3606
3607 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3608 {
3609 int nbits;
3610 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
3611 if (nbits != 0)
3612 return 0;
3613 }
3614
3615#if 0
3616 /* Some stupid compilers have trouble with the following, so break
3617 it up into simpler expressions. */
3618 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
3619 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
3620#else
3621 {
3622 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
3623 char *pointer;
3624
3625 pointer = (char *) TYPE_ALLOC (type, num_bytes);
3626 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
3627 }
3628#endif /* 0 */
3629
3630 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
3631
3632 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
3633 {
3634 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
b8c9b27d 3635 make_cleanup (xfree, new);
c906108c 3636 memset (new, 0, sizeof (struct nextfield));
c5aa993b
JM
3637 new->next = fip->list;
3638 fip->list = new;
c906108c
SS
3639 FIELD_BITSIZE (new->field) = 0; /* this should be an unpacked field! */
3640
3641 STABS_CONTINUE (pp, objfile);
3642 switch (**pp)
3643 {
c5aa993b
JM
3644 case '0':
3645 /* Nothing to do. */
3646 break;
3647 case '1':
3648 SET_TYPE_FIELD_VIRTUAL (type, i);
3649 break;
3650 default:
3651 /* Unknown character. Complain and treat it as non-virtual. */
3652 {
3653 static struct complaint msg =
c906108c 3654 {
c5aa993b
JM
3655 "Unknown virtual character `%c' for baseclass", 0, 0};
3656 complain (&msg, **pp);
3657 }
c906108c
SS
3658 }
3659 ++(*pp);
3660
c5aa993b
JM
3661 new->visibility = *(*pp)++;
3662 switch (new->visibility)
c906108c 3663 {
c5aa993b
JM
3664 case VISIBILITY_PRIVATE:
3665 case VISIBILITY_PROTECTED:
3666 case VISIBILITY_PUBLIC:
3667 break;
3668 default:
3669 /* Bad visibility format. Complain and treat it as
3670 public. */
3671 {
3672 static struct complaint msg =
c906108c 3673 {
53a5351d
JM
3674 "Unknown visibility `%c' for baseclass", 0, 0
3675 };
c5aa993b
JM
3676 complain (&msg, new->visibility);
3677 new->visibility = VISIBILITY_PUBLIC;
3678 }
c906108c
SS
3679 }
3680
3681 {
3682 int nbits;
c5aa993b 3683
c906108c
SS
3684 /* The remaining value is the bit offset of the portion of the object
3685 corresponding to this baseclass. Always zero in the absence of
3686 multiple inheritance. */
3687
3688 FIELD_BITPOS (new->field) = read_huge_number (pp, ',', &nbits);
3689 if (nbits != 0)
3690 return 0;
3691 }
3692
3693 /* The last piece of baseclass information is the type of the
c5aa993b
JM
3694 base class. Read it, and remember it's type name as this
3695 field's name. */
c906108c 3696
c5aa993b
JM
3697 new->field.type = read_type (pp, objfile);
3698 new->field.name = type_name_no_tag (new->field.type);
c906108c
SS
3699
3700 /* skip trailing ';' and bump count of number of fields seen */
3701 if (**pp == ';')
3702 (*pp)++;
3703 else
3704 return 0;
3705 }
3706 return 1;
3707}
3708
3709/* The tail end of stabs for C++ classes that contain a virtual function
3710 pointer contains a tilde, a %, and a type number.
3711 The type number refers to the base class (possibly this class itself) which
3712 contains the vtable pointer for the current class.
3713
3714 This function is called when we have parsed all the method declarations,
3715 so we can look for the vptr base class info. */
3716
3717static int
fba45db2
KB
3718read_tilde_fields (struct field_info *fip, char **pp, struct type *type,
3719 struct objfile *objfile)
c906108c
SS
3720{
3721 register char *p;
3722
3723 STABS_CONTINUE (pp, objfile);
3724
3725 /* If we are positioned at a ';', then skip it. */
3726 if (**pp == ';')
3727 {
3728 (*pp)++;
3729 }
3730
3731 if (**pp == '~')
3732 {
3733 (*pp)++;
3734
3735 if (**pp == '=' || **pp == '+' || **pp == '-')
3736 {
3737 /* Obsolete flags that used to indicate the presence
3738 of constructors and/or destructors. */
3739 (*pp)++;
3740 }
3741
3742 /* Read either a '%' or the final ';'. */
3743 if (*(*pp)++ == '%')
3744 {
3745 /* The next number is the type number of the base class
3746 (possibly our own class) which supplies the vtable for
3747 this class. Parse it out, and search that class to find
3748 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
3749 and TYPE_VPTR_FIELDNO. */
3750
3751 struct type *t;
3752 int i;
3753
3754 t = read_type (pp, objfile);
3755 p = (*pp)++;
3756 while (*p != '\0' && *p != ';')
3757 {
3758 p++;
3759 }
3760 if (*p == '\0')
3761 {
3762 /* Premature end of symbol. */
3763 return 0;
3764 }
c5aa993b 3765
c906108c 3766 TYPE_VPTR_BASETYPE (type) = t;
c5aa993b 3767 if (type == t) /* Our own class provides vtbl ptr */
c906108c
SS
3768 {
3769 for (i = TYPE_NFIELDS (t) - 1;
3770 i >= TYPE_N_BASECLASSES (t);
3771 --i)
3772 {
c5aa993b
JM
3773 if (!strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
3774 sizeof (vptr_name) - 1))
c906108c
SS
3775 {
3776 TYPE_VPTR_FIELDNO (type) = i;
3777 goto gotit;
3778 }
3779 }
3780 /* Virtual function table field not found. */
3781 complain (&vtbl_notfound_complaint, TYPE_NAME (type));
3782 return 0;
3783 }
3784 else
3785 {
3786 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
3787 }
3788
c5aa993b 3789 gotit:
c906108c
SS
3790 *pp = p + 1;
3791 }
3792 }
3793 return 1;
3794}
3795
3796static int
fba45db2 3797attach_fn_fields_to_type (struct field_info *fip, register struct type *type)
c906108c
SS
3798{
3799 register int n;
3800
3801 for (n = TYPE_NFN_FIELDS (type);
c5aa993b
JM
3802 fip->fnlist != NULL;
3803 fip->fnlist = fip->fnlist->next)
c906108c 3804 {
c5aa993b
JM
3805 --n; /* Circumvent Sun3 compiler bug */
3806 TYPE_FN_FIELDLISTS (type)[n] = fip->fnlist->fn_fieldlist;
c906108c
SS
3807 }
3808 return 1;
3809}
3810
3811/* read cfront class static data.
3812 pp points to string starting with the list of static data
3813 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
c5aa993b 3814 ^^^^^^^^
c906108c 3815
c5aa993b
JM
3816 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
3817 ^
3818 */
c906108c
SS
3819
3820static int
fba45db2
KB
3821read_cfront_static_fields (struct field_info *fip, char **pp, struct type *type,
3822 struct objfile *objfile)
c906108c 3823{
c5aa993b 3824 struct nextfield *new;
c906108c 3825 struct type *stype;
c5aa993b
JM
3826 char *sname;
3827 struct symbol *ref_static = 0;
3828
3829 if (**pp == ';') /* no static data; return */
c906108c
SS
3830 {
3831 ++(*pp);
3832 return 1;
3833 }
3834
3835 /* Process each field in the list until we find the terminating ";" */
3836
3837 /* eg: p = "as__1A ;;;" */
c5aa993b
JM
3838 STABS_CONTINUE (pp, objfile); /* handle \\ */
3839 while (**pp != ';' && (sname = get_substring (pp, ' '), sname))
c906108c 3840 {
c5aa993b
JM
3841 ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name */
3842 if (!ref_static)
3843 {
3844 static struct complaint msg =
3845 {"\
c906108c 3846 Unable to find symbol for static data field %s\n",
c5aa993b 3847 0, 0};
c906108c
SS
3848 complain (&msg, sname);
3849 continue;
3850 }
c5aa993b 3851 stype = SYMBOL_TYPE (ref_static);
c906108c
SS
3852
3853 /* allocate a new fip */
3854 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
b8c9b27d 3855 make_cleanup (xfree, new);
c906108c 3856 memset (new, 0, sizeof (struct nextfield));
c5aa993b
JM
3857 new->next = fip->list;
3858 fip->list = new;
c906108c
SS
3859
3860 /* set visibility */
3861 /* FIXME! no way to tell visibility from stabs??? */
c5aa993b 3862 new->visibility = VISIBILITY_PUBLIC;
c906108c
SS
3863
3864 /* set field info into fip */
c5aa993b 3865 fip->list->field.type = stype;
c906108c
SS
3866
3867 /* set bitpos & bitsize */
3868 SET_FIELD_PHYSNAME (fip->list->field, savestring (sname, strlen (sname)));
3869
3870 /* set name field */
3871 /* The following is code to work around cfront generated stabs.
3872 The stabs contains full mangled name for each field.
3873 We try to demangle the name and extract the field name out of it.
c5aa993b 3874 */
c906108c 3875 if (ARM_DEMANGLING)
c5aa993b
JM
3876 {
3877 char *dem, *dem_p;
3878 dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
3879 if (dem != NULL)
3880 {
3881 dem_p = strrchr (dem, ':');
3882 if (dem_p != 0 && *(dem_p - 1) == ':')
3883 dem_p++;
3884 fip->list->field.name =
3885 obsavestring (dem_p, strlen (dem_p), &objfile->type_obstack);
c906108c 3886 }
c5aa993b
JM
3887 else
3888 {
3889 fip->list->field.name =
3890 obsavestring (sname, strlen (sname), &objfile->type_obstack);
3891 }
3892 } /* end of code for cfront work around */
3893 } /* loop again for next static field */
c906108c
SS
3894 return 1;
3895}
3896
3897/* Copy structure fields to fip so attach_fields_to_type will work.
3898 type has already been created with the initial instance data fields.
3899 Now we want to be able to add the other members to the class,
3900 so we want to add them back to the fip and reattach them again
3901 once we have collected all the class members. */
3902
3903static int
fba45db2
KB
3904copy_cfront_struct_fields (struct field_info *fip, struct type *type,
3905 struct objfile *objfile)
c906108c 3906{
c5aa993b 3907 int nfields = TYPE_NFIELDS (type);
c906108c 3908 int i;
c5aa993b 3909 struct nextfield *new;
c906108c
SS
3910
3911 /* Copy the fields into the list of fips and reset the types
3912 to remove the old fields */
3913
c5aa993b 3914 for (i = 0; i < nfields; i++)
c906108c
SS
3915 {
3916 /* allocate a new fip */
3917 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
b8c9b27d 3918 make_cleanup (xfree, new);
c906108c 3919 memset (new, 0, sizeof (struct nextfield));
c5aa993b
JM
3920 new->next = fip->list;
3921 fip->list = new;
c906108c
SS
3922
3923 /* copy field info into fip */
c5aa993b 3924 new->field = TYPE_FIELD (type, i);
c906108c
SS
3925 /* set visibility */
3926 if (TYPE_FIELD_PROTECTED (type, i))
c5aa993b 3927 new->visibility = VISIBILITY_PROTECTED;
c906108c 3928 else if (TYPE_FIELD_PRIVATE (type, i))
c5aa993b 3929 new->visibility = VISIBILITY_PRIVATE;
c906108c 3930 else
c5aa993b 3931 new->visibility = VISIBILITY_PUBLIC;
c906108c
SS
3932 }
3933 /* Now delete the fields from the type since we will be
3934 allocing new space once we get the rest of the fields
3935 in attach_fields_to_type.
3936 The pointer TYPE_FIELDS(type) is left dangling but should
3937 be freed later by objstack_free */
c5aa993b 3938 TYPE_FIELDS (type) = 0;
c906108c
SS
3939 TYPE_NFIELDS (type) = 0;
3940
3941 return 1;
3942}
3943
3944/* Create the vector of fields, and record how big it is.
3945 We need this info to record proper virtual function table information
3946 for this class's virtual functions. */
3947
3948static int
fba45db2
KB
3949attach_fields_to_type (struct field_info *fip, register struct type *type,
3950 struct objfile *objfile)
c906108c
SS
3951{
3952 register int nfields = 0;
3953 register int non_public_fields = 0;
3954 register struct nextfield *scan;
3955
3956 /* Count up the number of fields that we have, as well as taking note of
3957 whether or not there are any non-public fields, which requires us to
3958 allocate and build the private_field_bits and protected_field_bits
3959 bitfields. */
3960
c5aa993b 3961 for (scan = fip->list; scan != NULL; scan = scan->next)
c906108c
SS
3962 {
3963 nfields++;
c5aa993b 3964 if (scan->visibility != VISIBILITY_PUBLIC)
c906108c
SS
3965 {
3966 non_public_fields++;
3967 }
3968 }
3969
3970 /* Now we know how many fields there are, and whether or not there are any
3971 non-public fields. Record the field count, allocate space for the
3972 array of fields, and create blank visibility bitfields if necessary. */
3973
3974 TYPE_NFIELDS (type) = nfields;
3975 TYPE_FIELDS (type) = (struct field *)
3976 TYPE_ALLOC (type, sizeof (struct field) * nfields);
3977 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3978
3979 if (non_public_fields)
3980 {
3981 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3982
3983 TYPE_FIELD_PRIVATE_BITS (type) =
3984 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3985 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3986
3987 TYPE_FIELD_PROTECTED_BITS (type) =
3988 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3989 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
3990
3991 TYPE_FIELD_IGNORE_BITS (type) =
3992 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3993 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
3994 }
3995
3996 /* Copy the saved-up fields into the field vector. Start from the head
3997 of the list, adding to the tail of the field array, so that they end
3998 up in the same order in the array in which they were added to the list. */
3999
4000 while (nfields-- > 0)
4001 {
c5aa993b
JM
4002 TYPE_FIELD (type, nfields) = fip->list->field;
4003 switch (fip->list->visibility)
c906108c 4004 {
c5aa993b
JM
4005 case VISIBILITY_PRIVATE:
4006 SET_TYPE_FIELD_PRIVATE (type, nfields);
4007 break;
c906108c 4008
c5aa993b
JM
4009 case VISIBILITY_PROTECTED:
4010 SET_TYPE_FIELD_PROTECTED (type, nfields);
4011 break;
c906108c 4012
c5aa993b
JM
4013 case VISIBILITY_IGNORE:
4014 SET_TYPE_FIELD_IGNORE (type, nfields);
4015 break;
c906108c 4016
c5aa993b
JM
4017 case VISIBILITY_PUBLIC:
4018 break;
c906108c 4019
c5aa993b
JM
4020 default:
4021 /* Unknown visibility. Complain and treat it as public. */
4022 {
4023 static struct complaint msg =
c906108c 4024 {
c5aa993b
JM
4025 "Unknown visibility `%c' for field", 0, 0};
4026 complain (&msg, fip->list->visibility);
4027 }
4028 break;
c906108c 4029 }
c5aa993b 4030 fip->list = fip->list->next;
c906108c
SS
4031 }
4032 return 1;
4033}
4034
4035/* Read the description of a structure (or union type) and return an object
4036 describing the type.
4037
4038 PP points to a character pointer that points to the next unconsumed token
4039 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
4040 *PP will point to "4a:1,0,32;;".
4041
4042 TYPE points to an incomplete type that needs to be filled in.
4043
4044 OBJFILE points to the current objfile from which the stabs information is
4045 being read. (Note that it is redundant in that TYPE also contains a pointer
4046 to this same objfile, so it might be a good idea to eliminate it. FIXME).
c5aa993b 4047 */
c906108c
SS
4048
4049static struct type *
fba45db2 4050read_struct_type (char **pp, struct type *type, struct objfile *objfile)
c906108c
SS
4051{
4052 struct cleanup *back_to;
4053 struct field_info fi;
4054
4055 fi.list = NULL;
4056 fi.fnlist = NULL;
4057
4058 back_to = make_cleanup (null_cleanup, 0);
4059
4060 INIT_CPLUS_SPECIFIC (type);
4061 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4062
4063 /* First comes the total size in bytes. */
4064
4065 {
4066 int nbits;
4067 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
4068 if (nbits != 0)
4069 return error_type (pp, objfile);
4070 }
4071
4072 /* Now read the baseclasses, if any, read the regular C struct or C++
4073 class member fields, attach the fields to the type, read the C++
4074 member functions, attach them to the type, and then read any tilde
4075 field (baseclass specifier for the class holding the main vtable). */
4076
4077 if (!read_baseclasses (&fi, pp, type, objfile)
4078 || !read_struct_fields (&fi, pp, type, objfile)
4079 || !attach_fields_to_type (&fi, type, objfile)
4080 || !read_member_functions (&fi, pp, type, objfile)
4081 || !attach_fn_fields_to_type (&fi, type)
4082 || !read_tilde_fields (&fi, pp, type, objfile))
4083 {
4084 type = error_type (pp, objfile);
4085 }
4086
4087 do_cleanups (back_to);
4088 return (type);
4089}
4090
4091/* Read a definition of an array type,
4092 and create and return a suitable type object.
4093 Also creates a range type which represents the bounds of that
4094 array. */
4095
4096static struct type *
fba45db2
KB
4097read_array_type (register char **pp, register struct type *type,
4098 struct objfile *objfile)
c906108c
SS
4099{
4100 struct type *index_type, *element_type, *range_type;
4101 int lower, upper;
4102 int adjustable = 0;
4103 int nbits;
4104
4105 /* Format of an array type:
4106 "ar<index type>;lower;upper;<array_contents_type>".
4107 OS9000: "arlower,upper;<array_contents_type>".
4108
4109 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4110 for these, produce a type like float[][]. */
4111
4112 if (os9k_stabs)
4113 index_type = builtin_type_int;
4114 else
4115 {
4116 index_type = read_type (pp, objfile);
4117 if (**pp != ';')
4118 /* Improper format of array type decl. */
4119 return error_type (pp, objfile);
4120 ++*pp;
4121 }
4122
4123 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4124 {
4125 (*pp)++;
4126 adjustable = 1;
4127 }
4128 lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
4129 if (nbits != 0)
4130 return error_type (pp, objfile);
4131
4132 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
4133 {
4134 (*pp)++;
4135 adjustable = 1;
4136 }
4137 upper = read_huge_number (pp, ';', &nbits);
4138 if (nbits != 0)
4139 return error_type (pp, objfile);
c5aa993b 4140
c906108c
SS
4141 element_type = read_type (pp, objfile);
4142
4143 if (adjustable)
4144 {
4145 lower = 0;
4146 upper = -1;
4147 }
4148
4149 range_type =
4150 create_range_type ((struct type *) NULL, index_type, lower, upper);
4151 type = create_array_type (type, element_type, range_type);
4152
4153 return type;
4154}
4155
4156
4157/* Read a definition of an enumeration type,
4158 and create and return a suitable type object.
4159 Also defines the symbols that represent the values of the type. */
4160
4161static struct type *
fba45db2
KB
4162read_enum_type (register char **pp, register struct type *type,
4163 struct objfile *objfile)
c906108c
SS
4164{
4165 register char *p;
4166 char *name;
4167 register long n;
4168 register struct symbol *sym;
4169 int nsyms = 0;
4170 struct pending **symlist;
4171 struct pending *osyms, *syms;
4172 int o_nsyms;
4173 int nbits;
4174 int unsigned_enum = 1;
4175
4176#if 0
4177 /* FIXME! The stabs produced by Sun CC merrily define things that ought
4178 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
4179 to do? For now, force all enum values to file scope. */
4180 if (within_function)
4181 symlist = &local_symbols;
4182 else
4183#endif
4184 symlist = &file_symbols;
4185 osyms = *symlist;
4186 o_nsyms = osyms ? osyms->nsyms : 0;
4187
4188 if (os9k_stabs)
4189 {
4190 /* Size. Perhaps this does not have to be conditionalized on
c5aa993b
JM
4191 os9k_stabs (assuming the name of an enum constant can't start
4192 with a digit). */
c906108c
SS
4193 read_huge_number (pp, 0, &nbits);
4194 if (nbits != 0)
4195 return error_type (pp, objfile);
4196 }
4197
4198 /* The aix4 compiler emits an extra field before the enum members;
4199 my guess is it's a type of some sort. Just ignore it. */
4200 if (**pp == '-')
4201 {
4202 /* Skip over the type. */
4203 while (**pp != ':')
c5aa993b 4204 (*pp)++;
c906108c
SS
4205
4206 /* Skip over the colon. */
4207 (*pp)++;
4208 }
4209
4210 /* Read the value-names and their values.
4211 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4212 A semicolon or comma instead of a NAME means the end. */
4213 while (**pp && **pp != ';' && **pp != ',')
4214 {
4215 STABS_CONTINUE (pp, objfile);
4216 p = *pp;
c5aa993b
JM
4217 while (*p != ':')
4218 p++;
4219 name = obsavestring (*pp, p - *pp, &objfile->symbol_obstack);
c906108c
SS
4220 *pp = p + 1;
4221 n = read_huge_number (pp, ',', &nbits);
4222 if (nbits != 0)
4223 return error_type (pp, objfile);
4224
4225 sym = (struct symbol *)
c5aa993b 4226 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
c906108c
SS
4227 memset (sym, 0, sizeof (struct symbol));
4228 SYMBOL_NAME (sym) = name;
c5aa993b 4229 SYMBOL_LANGUAGE (sym) = current_subfile->language;
c906108c
SS
4230 SYMBOL_CLASS (sym) = LOC_CONST;
4231 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4232 SYMBOL_VALUE (sym) = n;
4233 if (n < 0)
4234 unsigned_enum = 0;
4235 add_symbol_to_list (sym, symlist);
4236 nsyms++;
4237 }
4238
4239 if (**pp == ';')
4240 (*pp)++; /* Skip the semicolon. */
4241
4242 /* Now fill in the fields of the type-structure. */
4243
4244 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
4245 TYPE_CODE (type) = TYPE_CODE_ENUM;
4246 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
4247 if (unsigned_enum)
4248 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
4249 TYPE_NFIELDS (type) = nsyms;
4250 TYPE_FIELDS (type) = (struct field *)
4251 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
4252 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
4253
4254 /* Find the symbols for the values and put them into the type.
4255 The symbols can be found in the symlist that we put them on
4256 to cause them to be defined. osyms contains the old value
4257 of that symlist; everything up to there was defined by us. */
4258 /* Note that we preserve the order of the enum constants, so
4259 that in something like "enum {FOO, LAST_THING=FOO}" we print
4260 FOO, not LAST_THING. */
4261
4262 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
4263 {
4264 int last = syms == osyms ? o_nsyms : 0;
4265 int j = syms->nsyms;
4266 for (; --j >= last; --n)
4267 {
4268 struct symbol *xsym = syms->symbol[j];
4269 SYMBOL_TYPE (xsym) = type;
4270 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
4271 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
4272 TYPE_FIELD_BITSIZE (type, n) = 0;
4273 }
4274 if (syms == osyms)
4275 break;
4276 }
4277
4278 return type;
4279}
4280
4281/* Sun's ACC uses a somewhat saner method for specifying the builtin
4282 typedefs in every file (for int, long, etc):
4283
c5aa993b
JM
4284 type = b <signed> <width> <format type>; <offset>; <nbits>
4285 signed = u or s.
4286 optional format type = c or b for char or boolean.
4287 offset = offset from high order bit to start bit of type.
4288 width is # bytes in object of this type, nbits is # bits in type.
c906108c
SS
4289
4290 The width/offset stuff appears to be for small objects stored in
4291 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
4292 FIXME. */
4293
4294static struct type *
35a2f538 4295read_sun_builtin_type (char **pp, int typenums[2], struct objfile *objfile)
c906108c
SS
4296{
4297 int type_bits;
4298 int nbits;
4299 int signed_type;
4300 enum type_code code = TYPE_CODE_INT;
4301
4302 switch (**pp)
4303 {
c5aa993b
JM
4304 case 's':
4305 signed_type = 1;
4306 break;
4307 case 'u':
4308 signed_type = 0;
4309 break;
4310 default:
4311 return error_type (pp, objfile);
c906108c
SS
4312 }
4313 (*pp)++;
4314
4315 /* For some odd reason, all forms of char put a c here. This is strange
4316 because no other type has this honor. We can safely ignore this because
4317 we actually determine 'char'acterness by the number of bits specified in
4318 the descriptor.
4319 Boolean forms, e.g Fortran logical*X, put a b here. */
4320
4321 if (**pp == 'c')
4322 (*pp)++;
4323 else if (**pp == 'b')
4324 {
4325 code = TYPE_CODE_BOOL;
4326 (*pp)++;
4327 }
4328
4329 /* The first number appears to be the number of bytes occupied
4330 by this type, except that unsigned short is 4 instead of 2.
4331 Since this information is redundant with the third number,
4332 we will ignore it. */
4333 read_huge_number (pp, ';', &nbits);
4334 if (nbits != 0)
4335 return error_type (pp, objfile);
4336
4337 /* The second number is always 0, so ignore it too. */
4338 read_huge_number (pp, ';', &nbits);
4339 if (nbits != 0)
4340 return error_type (pp, objfile);
4341
4342 /* The third number is the number of bits for this type. */
4343 type_bits = read_huge_number (pp, 0, &nbits);
4344 if (nbits != 0)
4345 return error_type (pp, objfile);
4346 /* The type *should* end with a semicolon. If it are embedded
4347 in a larger type the semicolon may be the only way to know where
4348 the type ends. If this type is at the end of the stabstring we
4349 can deal with the omitted semicolon (but we don't have to like
4350 it). Don't bother to complain(), Sun's compiler omits the semicolon
4351 for "void". */
4352 if (**pp == ';')
4353 ++(*pp);
4354
4355 if (type_bits == 0)
4356 return init_type (TYPE_CODE_VOID, 1,
c5aa993b 4357 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
c906108c
SS
4358 objfile);
4359 else
4360 return init_type (code,
4361 type_bits / TARGET_CHAR_BIT,
c5aa993b 4362 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *) NULL,
c906108c
SS
4363 objfile);
4364}
4365
4366static struct type *
35a2f538 4367read_sun_floating_type (char **pp, int typenums[2], struct objfile *objfile)
c906108c
SS
4368{
4369 int nbits;
4370 int details;
4371 int nbytes;
4372
4373 /* The first number has more details about the type, for example
4374 FN_COMPLEX. */
4375 details = read_huge_number (pp, ';', &nbits);
4376 if (nbits != 0)
4377 return error_type (pp, objfile);
4378
4379 /* The second number is the number of bytes occupied by this type */
4380 nbytes = read_huge_number (pp, ';', &nbits);
4381 if (nbits != 0)
4382 return error_type (pp, objfile);
4383
4384 if (details == NF_COMPLEX || details == NF_COMPLEX16
4385 || details == NF_COMPLEX32)
4386 /* This is a type we can't handle, but we do know the size.
4387 We also will be able to give it a name. */
4388 return init_type (TYPE_CODE_COMPLEX, nbytes, 0, NULL, objfile);
4389
4390 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
4391}
4392
4393/* Read a number from the string pointed to by *PP.
4394 The value of *PP is advanced over the number.
4395 If END is nonzero, the character that ends the
4396 number must match END, or an error happens;
4397 and that character is skipped if it does match.
4398 If END is zero, *PP is left pointing to that character.
4399
4400 If the number fits in a long, set *BITS to 0 and return the value.
4401 If not, set *BITS to be the number of bits in the number and return 0.
4402
4403 If encounter garbage, set *BITS to -1 and return 0. */
4404
c2d11a7d 4405static long
fba45db2 4406read_huge_number (char **pp, int end, int *bits)
c906108c
SS
4407{
4408 char *p = *pp;
4409 int sign = 1;
c2d11a7d 4410 long n = 0;
c906108c
SS
4411 int radix = 10;
4412 char overflow = 0;
4413 int nbits = 0;
4414 int c;
c2d11a7d 4415 long upper_limit;
c5aa993b 4416
c906108c
SS
4417 if (*p == '-')
4418 {
4419 sign = -1;
4420 p++;
4421 }
4422
4423 /* Leading zero means octal. GCC uses this to output values larger
4424 than an int (because that would be hard in decimal). */
4425 if (*p == '0')
4426 {
4427 radix = 8;
4428 p++;
4429 }
4430
4431 if (os9k_stabs)
c2d11a7d 4432 upper_limit = ULONG_MAX / radix;
c906108c 4433 else
c2d11a7d 4434 upper_limit = LONG_MAX / radix;
c906108c
SS
4435
4436 while ((c = *p++) >= '0' && c < ('0' + radix))
4437 {
4438 if (n <= upper_limit)
4439 {
4440 n *= radix;
4441 n += c - '0'; /* FIXME this overflows anyway */
4442 }
4443 else
4444 overflow = 1;
c5aa993b 4445
c906108c 4446 /* This depends on large values being output in octal, which is
c5aa993b 4447 what GCC does. */
c906108c
SS
4448 if (radix == 8)
4449 {
4450 if (nbits == 0)
4451 {
4452 if (c == '0')
4453 /* Ignore leading zeroes. */
4454 ;
4455 else if (c == '1')
4456 nbits = 1;
4457 else if (c == '2' || c == '3')
4458 nbits = 2;
4459 else
4460 nbits = 3;
4461 }
4462 else
4463 nbits += 3;
4464 }
4465 }
4466 if (end)
4467 {
4468 if (c && c != end)
4469 {
4470 if (bits != NULL)
4471 *bits = -1;
4472 return 0;
4473 }
4474 }
4475 else
4476 --p;
4477
4478 *pp = p;
4479 if (overflow)
4480 {
4481 if (nbits == 0)
4482 {
4483 /* Large decimal constants are an error (because it is hard to
4484 count how many bits are in them). */
4485 if (bits != NULL)
4486 *bits = -1;
4487 return 0;
4488 }
c5aa993b 4489
c906108c 4490 /* -0x7f is the same as 0x80. So deal with it by adding one to
c5aa993b 4491 the number of bits. */
c906108c
SS
4492 if (sign == -1)
4493 ++nbits;
4494 if (bits)
4495 *bits = nbits;
4496 }
4497 else
4498 {
4499 if (bits)
4500 *bits = 0;
4501 return n * sign;
4502 }
4503 /* It's *BITS which has the interesting information. */
4504 return 0;
4505}
4506
4507static struct type *
35a2f538 4508read_range_type (char **pp, int typenums[2], struct objfile *objfile)
c906108c
SS
4509{
4510 char *orig_pp = *pp;
4511 int rangenums[2];
c2d11a7d 4512 long n2, n3;
c906108c
SS
4513 int n2bits, n3bits;
4514 int self_subrange;
4515 struct type *result_type;
4516 struct type *index_type = NULL;
4517
4518 /* First comes a type we are a subrange of.
4519 In C it is usually 0, 1 or the type being defined. */
4520 if (read_type_number (pp, rangenums) != 0)
4521 return error_type (pp, objfile);
4522 self_subrange = (rangenums[0] == typenums[0] &&
4523 rangenums[1] == typenums[1]);
4524
4525 if (**pp == '=')
4526 {
4527 *pp = orig_pp;
4528 index_type = read_type (pp, objfile);
4529 }
4530
4531 /* A semicolon should now follow; skip it. */
4532 if (**pp == ';')
4533 (*pp)++;
4534
4535 /* The remaining two operands are usually lower and upper bounds
4536 of the range. But in some special cases they mean something else. */
4537 n2 = read_huge_number (pp, ';', &n2bits);
4538 n3 = read_huge_number (pp, ';', &n3bits);
4539
4540 if (n2bits == -1 || n3bits == -1)
4541 return error_type (pp, objfile);
4542
4543 if (index_type)
4544 goto handle_true_range;
4545
4546 /* If limits are huge, must be large integral type. */
4547 if (n2bits != 0 || n3bits != 0)
4548 {
4549 char got_signed = 0;
4550 char got_unsigned = 0;
4551 /* Number of bits in the type. */
4552 int nbits = 0;
4553
4554 /* Range from 0 to <large number> is an unsigned large integral type. */
4555 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
4556 {
4557 got_unsigned = 1;
4558 nbits = n3bits;
4559 }
4560 /* Range from <large number> to <large number>-1 is a large signed
c5aa993b
JM
4561 integral type. Take care of the case where <large number> doesn't
4562 fit in a long but <large number>-1 does. */
c906108c
SS
4563 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
4564 || (n2bits != 0 && n3bits == 0
c2d11a7d
JM
4565 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
4566 && n3 == LONG_MAX))
c906108c
SS
4567 {
4568 got_signed = 1;
4569 nbits = n2bits;
4570 }
4571
4572 if (got_signed || got_unsigned)
4573 {
4574 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
4575 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
4576 objfile);
4577 }
4578 else
4579 return error_type (pp, objfile);
4580 }
4581
4582 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4583 if (self_subrange && n2 == 0 && n3 == 0)
4584 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
4585
4586 /* If n3 is zero and n2 is positive, we want a floating type, and n2
4587 is the width in bytes.
4588
4589 Fortran programs appear to use this for complex types also. To
4590 distinguish between floats and complex, g77 (and others?) seem
4591 to use self-subranges for the complexes, and subranges of int for
4592 the floats.
4593
4594 Also note that for complexes, g77 sets n2 to the size of one of
4595 the member floats, not the whole complex beast. My guess is that
4596 this was to work well with pre-COMPLEX versions of gdb. */
4597
4598 if (n3 == 0 && n2 > 0)
4599 {
1300f5dd
JB
4600 struct type *float_type
4601 = init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
4602
c906108c
SS
4603 if (self_subrange)
4604 {
1300f5dd
JB
4605 struct type *complex_type =
4606 init_type (TYPE_CODE_COMPLEX, 2 * n2, 0, NULL, objfile);
4607 TYPE_TARGET_TYPE (complex_type) = float_type;
4608 return complex_type;
c906108c
SS
4609 }
4610 else
1300f5dd 4611 return float_type;
c906108c
SS
4612 }
4613
4614 /* If the upper bound is -1, it must really be an unsigned int. */
4615
4616 else if (n2 == 0 && n3 == -1)
4617 {
4618 /* It is unsigned int or unsigned long. */
4619 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
c5aa993b 4620 compatibility hack. */
c906108c
SS
4621 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4622 TYPE_FLAG_UNSIGNED, NULL, objfile);
4623 }
4624
4625 /* Special case: char is defined (Who knows why) as a subrange of
4626 itself with range 0-127. */
4627 else if (self_subrange && n2 == 0 && n3 == 127)
4628 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4629
4630 else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill
4631 && !self_subrange)
4632 goto handle_true_range;
4633
4634 /* We used to do this only for subrange of self or subrange of int. */
4635 else if (n2 == 0)
4636 {
a0b3c4fd
JM
4637 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4638 "unsigned long", and we already checked for that,
4639 so don't need to test for it here. */
4640
c906108c
SS
4641 if (n3 < 0)
4642 /* n3 actually gives the size. */
c5aa993b 4643 return init_type (TYPE_CODE_INT, -n3, TYPE_FLAG_UNSIGNED,
c906108c 4644 NULL, objfile);
c906108c 4645
7be570e7 4646 /* Is n3 == 2**(8n)-1 for some integer n? Then it's an
a0b3c4fd
JM
4647 unsigned n-byte integer. But do require n to be a power of
4648 two; we don't want 3- and 5-byte integers flying around. */
4649 {
4650 int bytes;
4651 unsigned long bits;
4652
4653 bits = n3;
4654 for (bytes = 0; (bits & 0xff) == 0xff; bytes++)
4655 bits >>= 8;
4656 if (bits == 0
4657 && ((bytes - 1) & bytes) == 0) /* "bytes is a power of two" */
4658 return init_type (TYPE_CODE_INT, bytes, TYPE_FLAG_UNSIGNED, NULL,
4659 objfile);
4660 }
c906108c
SS
4661 }
4662 /* I think this is for Convex "long long". Since I don't know whether
4663 Convex sets self_subrange, I also accept that particular size regardless
4664 of self_subrange. */
4665 else if (n3 == 0 && n2 < 0
4666 && (self_subrange
c5aa993b
JM
4667 || n2 == -TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
4668 return init_type (TYPE_CODE_INT, -n2, 0, NULL, objfile);
4669 else if (n2 == -n3 - 1)
c906108c
SS
4670 {
4671 if (n3 == 0x7f)
4672 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4673 if (n3 == 0x7fff)
4674 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
4675 if (n3 == 0x7fffffff)
4676 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
4677 }
4678
4679 /* We have a real range type on our hands. Allocate space and
4680 return a real pointer. */
c5aa993b 4681handle_true_range:
c906108c
SS
4682
4683 if (self_subrange)
4684 index_type = builtin_type_int;
4685 else
4686 index_type = *dbx_lookup_type (rangenums);
4687 if (index_type == NULL)
4688 {
4689 /* Does this actually ever happen? Is that why we are worrying
4690 about dealing with it rather than just calling error_type? */
4691
4692 static struct type *range_type_index;
4693
4694 complain (&range_type_base_complaint, rangenums[1]);
4695 if (range_type_index == NULL)
4696 range_type_index =
4697 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4698 0, "range type index type", NULL);
4699 index_type = range_type_index;
4700 }
4701
4702 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
4703 return (result_type);
4704}
4705
4706/* Read in an argument list. This is a list of types, separated by commas
4707 and terminated with END. Return the list of types read in, or (struct type
4708 **)-1 if there is an error. */
4709
4710static struct type **
fba45db2 4711read_args (char **pp, int end, struct objfile *objfile)
c906108c
SS
4712{
4713 /* FIXME! Remove this arbitrary limit! */
c5aa993b 4714 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
c906108c
SS
4715 int n = 0;
4716
4717 while (**pp != end)
4718 {
4719 if (**pp != ',')
4720 /* Invalid argument list: no ','. */
c5aa993b 4721 return (struct type **) -1;
c906108c
SS
4722 (*pp)++;
4723 STABS_CONTINUE (pp, objfile);
4724 types[n++] = read_type (pp, objfile);
4725 }
4726 (*pp)++; /* get past `end' (the ':' character) */
4727
4728 if (n == 1)
4729 {
4730 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
4731 }
c5aa993b 4732 else if (TYPE_CODE (types[n - 1]) != TYPE_CODE_VOID)
c906108c
SS
4733 {
4734 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
4735 memset (rval + n, 0, sizeof (struct type *));
4736 }
4737 else
4738 {
4739 rval = (struct type **) xmalloc (n * sizeof (struct type *));
4740 }
4741 memcpy (rval, types, n * sizeof (struct type *));
4742 return rval;
4743}
4744\f
4745/* Common block handling. */
4746
4747/* List of symbols declared since the last BCOMM. This list is a tail
4748 of local_symbols. When ECOMM is seen, the symbols on the list
4749 are noted so their proper addresses can be filled in later,
4750 using the common block base address gotten from the assembler
4751 stabs. */
4752
4753static struct pending *common_block;
4754static int common_block_i;
4755
4756/* Name of the current common block. We get it from the BCOMM instead of the
4757 ECOMM to match IBM documentation (even though IBM puts the name both places
4758 like everyone else). */
4759static char *common_block_name;
4760
4761/* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4762 to remain after this function returns. */
4763
4764void
fba45db2 4765common_block_start (char *name, struct objfile *objfile)
c906108c
SS
4766{
4767 if (common_block_name != NULL)
4768 {
c5aa993b
JM
4769 static struct complaint msg =
4770 {
c906108c
SS
4771 "Invalid symbol data: common block within common block",
4772 0, 0};
4773 complain (&msg);
4774 }
4775 common_block = local_symbols;
4776 common_block_i = local_symbols ? local_symbols->nsyms : 0;
4777 common_block_name = obsavestring (name, strlen (name),
c5aa993b 4778 &objfile->symbol_obstack);
c906108c
SS
4779}
4780
4781/* Process a N_ECOMM symbol. */
4782
4783void
fba45db2 4784common_block_end (struct objfile *objfile)
c906108c
SS
4785{
4786 /* Symbols declared since the BCOMM are to have the common block
4787 start address added in when we know it. common_block and
4788 common_block_i point to the first symbol after the BCOMM in
4789 the local_symbols list; copy the list and hang it off the
4790 symbol for the common block name for later fixup. */
4791 int i;
4792 struct symbol *sym;
4793 struct pending *new = 0;
4794 struct pending *next;
4795 int j;
4796
4797 if (common_block_name == NULL)
4798 {
c5aa993b
JM
4799 static struct complaint msg =
4800 {"ECOMM symbol unmatched by BCOMM", 0, 0};
c906108c
SS
4801 complain (&msg);
4802 return;
4803 }
4804
c5aa993b
JM
4805 sym = (struct symbol *)
4806 obstack_alloc (&objfile->symbol_obstack, sizeof (struct symbol));
c906108c
SS
4807 memset (sym, 0, sizeof (struct symbol));
4808 /* Note: common_block_name already saved on symbol_obstack */
4809 SYMBOL_NAME (sym) = common_block_name;
4810 SYMBOL_CLASS (sym) = LOC_BLOCK;
4811
4812 /* Now we copy all the symbols which have been defined since the BCOMM. */
4813
4814 /* Copy all the struct pendings before common_block. */
4815 for (next = local_symbols;
4816 next != NULL && next != common_block;
4817 next = next->next)
4818 {
4819 for (j = 0; j < next->nsyms; j++)
4820 add_symbol_to_list (next->symbol[j], &new);
4821 }
4822
4823 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4824 NULL, it means copy all the local symbols (which we already did
4825 above). */
4826
4827 if (common_block != NULL)
4828 for (j = common_block_i; j < common_block->nsyms; j++)
4829 add_symbol_to_list (common_block->symbol[j], &new);
4830
4831 SYMBOL_TYPE (sym) = (struct type *) new;
4832
4833 /* Should we be putting local_symbols back to what it was?
4834 Does it matter? */
4835
4836 i = hashname (SYMBOL_NAME (sym));
4837 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
4838 global_sym_chain[i] = sym;
4839 common_block_name = NULL;
4840}
4841
4842/* Add a common block's start address to the offset of each symbol
4843 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4844 the common block name). */
4845
4846static void
fba45db2 4847fix_common_block (struct symbol *sym, int valu)
c906108c
SS
4848{
4849 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
c5aa993b 4850 for (; next; next = next->next)
c906108c
SS
4851 {
4852 register int j;
4853 for (j = next->nsyms - 1; j >= 0; j--)
4854 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
4855 }
4856}
c5aa993b 4857\f
c906108c
SS
4858
4859
c906108c
SS
4860/* What about types defined as forward references inside of a small lexical
4861 scope? */
4862/* Add a type to the list of undefined types to be checked through
4863 once this file has been read in. */
4864
4865void
fba45db2 4866add_undefined_type (struct type *type)
c906108c
SS
4867{
4868 if (undef_types_length == undef_types_allocated)
4869 {
4870 undef_types_allocated *= 2;
4871 undef_types = (struct type **)
4872 xrealloc ((char *) undef_types,
4873 undef_types_allocated * sizeof (struct type *));
4874 }
4875 undef_types[undef_types_length++] = type;
4876}
4877
4878/* Go through each undefined type, see if it's still undefined, and fix it
4879 up if possible. We have two kinds of undefined types:
4880
4881 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
c5aa993b
JM
4882 Fix: update array length using the element bounds
4883 and the target type's length.
c906108c 4884 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
c5aa993b
JM
4885 yet defined at the time a pointer to it was made.
4886 Fix: Do a full lookup on the struct/union tag. */
c906108c 4887void
fba45db2 4888cleanup_undefined_types (void)
c906108c
SS
4889{
4890 struct type **type;
4891
4892 for (type = undef_types; type < undef_types + undef_types_length; type++)
4893 {
4894 switch (TYPE_CODE (*type))
4895 {
4896
c5aa993b
JM
4897 case TYPE_CODE_STRUCT:
4898 case TYPE_CODE_UNION:
4899 case TYPE_CODE_ENUM:
c906108c
SS
4900 {
4901 /* Check if it has been defined since. Need to do this here
4902 as well as in check_typedef to deal with the (legitimate in
4903 C though not C++) case of several types with the same name
4904 in different source files. */
4905 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
4906 {
4907 struct pending *ppt;
4908 int i;
4909 /* Name of the type, without "struct" or "union" */
4910 char *typename = TYPE_TAG_NAME (*type);
4911
4912 if (typename == NULL)
4913 {
c5aa993b
JM
4914 static struct complaint msg =
4915 {"need a type name", 0, 0};
c906108c
SS
4916 complain (&msg);
4917 break;
4918 }
4919 for (ppt = file_symbols; ppt; ppt = ppt->next)
4920 {
4921 for (i = 0; i < ppt->nsyms; i++)
4922 {
4923 struct symbol *sym = ppt->symbol[i];
c5aa993b 4924
c906108c
SS
4925 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
4926 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
4927 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
4928 TYPE_CODE (*type))
4929 && STREQ (SYMBOL_NAME (sym), typename))
4930 {
4931 memcpy (*type, SYMBOL_TYPE (sym),
4932 sizeof (struct type));
4933 }
4934 }
4935 }
4936 }
4937 }
4938 break;
4939
4940 default:
4941 {
c5aa993b
JM
4942 static struct complaint msg =
4943 {"\
c906108c
SS
4944GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4945 complain (&msg, TYPE_CODE (*type));
4946 }
4947 break;
4948 }
4949 }
4950
4951 undef_types_length = 0;
4952}
4953
4954/* Scan through all of the global symbols defined in the object file,
4955 assigning values to the debugging symbols that need to be assigned
4956 to. Get these symbols from the minimal symbol table. */
4957
4958void
fba45db2 4959scan_file_globals (struct objfile *objfile)
c906108c
SS
4960{
4961 int hash;
4962 struct minimal_symbol *msymbol;
4963 struct symbol *sym, *prev, *rsym;
4964 struct objfile *resolve_objfile;
4965
4966 /* SVR4 based linkers copy referenced global symbols from shared
4967 libraries to the main executable.
4968 If we are scanning the symbols for a shared library, try to resolve
4969 them from the minimal symbols of the main executable first. */
4970
4971 if (symfile_objfile && objfile != symfile_objfile)
4972 resolve_objfile = symfile_objfile;
4973 else
4974 resolve_objfile = objfile;
4975
4976 while (1)
4977 {
4978 /* Avoid expensive loop through all minimal symbols if there are
c5aa993b 4979 no unresolved symbols. */
c906108c
SS
4980 for (hash = 0; hash < HASHSIZE; hash++)
4981 {
4982 if (global_sym_chain[hash])
4983 break;
4984 }
4985 if (hash >= HASHSIZE)
4986 return;
4987
c5aa993b 4988 for (msymbol = resolve_objfile->msymbols;
c906108c
SS
4989 msymbol && SYMBOL_NAME (msymbol) != NULL;
4990 msymbol++)
4991 {
4992 QUIT;
4993
4994 /* Skip static symbols. */
4995 switch (MSYMBOL_TYPE (msymbol))
4996 {
4997 case mst_file_text:
4998 case mst_file_data:
4999 case mst_file_bss:
5000 continue;
5001 default:
5002 break;
5003 }
5004
5005 prev = NULL;
5006
5007 /* Get the hash index and check all the symbols
5008 under that hash index. */
5009
5010 hash = hashname (SYMBOL_NAME (msymbol));
5011
5012 for (sym = global_sym_chain[hash]; sym;)
5013 {
5014 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
c5aa993b 5015 STREQ (SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
c906108c
SS
5016 {
5017
5018 struct alias_list *aliases;
5019
5020 /* Splice this symbol out of the hash chain and
5021 assign the value we have to it. */
5022 if (prev)
5023 {
5024 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
5025 }
5026 else
5027 {
5028 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
5029 }
c5aa993b 5030
c906108c
SS
5031 /* Check to see whether we need to fix up a common block. */
5032 /* Note: this code might be executed several times for
5033 the same symbol if there are multiple references. */
5034
5035 /* If symbol has aliases, do minimal symbol fixups for each.
5036 These live aliases/references weren't added to
5037 global_sym_chain hash but may also need to be fixed up. */
c5aa993b 5038 /* FIXME: Maybe should have added aliases to the global chain, resolved symbol name, then treated aliases as normal
c906108c
SS
5039 symbols? Still, we wouldn't want to add_to_list. */
5040 /* Now do the same for each alias of this symbol */
5041 rsym = sym;
5042 aliases = SYMBOL_ALIASES (sym);
5043 while (rsym)
5044 {
5045 if (SYMBOL_CLASS (rsym) == LOC_BLOCK)
5046 {
5047 fix_common_block (rsym,
5048 SYMBOL_VALUE_ADDRESS (msymbol));
5049 }
5050 else
5051 {
5052 SYMBOL_VALUE_ADDRESS (rsym)
5053 = SYMBOL_VALUE_ADDRESS (msymbol);
5054 }
5055 SYMBOL_SECTION (rsym) = SYMBOL_SECTION (msymbol);
5056 if (aliases)
5057 {
5058 rsym = aliases->sym;
5059 aliases = aliases->next;
5060 }
5061 else
5062 rsym = NULL;
5063 }
5064
c5aa993b 5065
c906108c
SS
5066 if (prev)
5067 {
5068 sym = SYMBOL_VALUE_CHAIN (prev);
5069 }
5070 else
5071 {
5072 sym = global_sym_chain[hash];
5073 }
5074 }
5075 else
5076 {
5077 prev = sym;
5078 sym = SYMBOL_VALUE_CHAIN (sym);
5079 }
5080 }
5081 }
5082 if (resolve_objfile == objfile)
5083 break;
5084 resolve_objfile = objfile;
5085 }
5086
5087 /* Change the storage class of any remaining unresolved globals to
5088 LOC_UNRESOLVED and remove them from the chain. */
5089 for (hash = 0; hash < HASHSIZE; hash++)
5090 {
5091 sym = global_sym_chain[hash];
5092 while (sym)
5093 {
5094 prev = sym;
5095 sym = SYMBOL_VALUE_CHAIN (sym);
5096
5097 /* Change the symbol address from the misleading chain value
5098 to address zero. */
5099 SYMBOL_VALUE_ADDRESS (prev) = 0;
5100
5101 /* Complain about unresolved common block symbols. */
5102 if (SYMBOL_CLASS (prev) == LOC_STATIC)
5103 SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
5104 else
5105 complain (&unresolved_sym_chain_complaint,
c5aa993b 5106 objfile->name, SYMBOL_NAME (prev));
c906108c
SS
5107 }
5108 }
5109 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5110}
5111
5112/* Initialize anything that needs initializing when starting to read
5113 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
5114 to a psymtab. */
5115
5116void
fba45db2 5117stabsread_init (void)
c906108c
SS
5118{
5119}
5120
5121/* Initialize anything that needs initializing when a completely new
5122 symbol file is specified (not just adding some symbols from another
5123 file, e.g. a shared library). */
5124
5125void
fba45db2 5126stabsread_new_init (void)
c906108c
SS
5127{
5128 /* Empty the hash table of global syms looking for values. */
5129 memset (global_sym_chain, 0, sizeof (global_sym_chain));
5130}
5131
5132/* Initialize anything that needs initializing at the same time as
5133 start_symtab() is called. */
5134
c5aa993b 5135void
fba45db2 5136start_stabs (void)
c906108c
SS
5137{
5138 global_stabs = NULL; /* AIX COFF */
5139 /* Leave FILENUM of 0 free for builtin types and this file's types. */
5140 n_this_object_header_files = 1;
5141 type_vector_length = 0;
5142 type_vector = (struct type **) 0;
5143
5144 /* FIXME: If common_block_name is not already NULL, we should complain(). */
5145 common_block_name = NULL;
5146
5147 os9k_stabs = 0;
5148}
5149
5150/* Call after end_symtab() */
5151
c5aa993b 5152void
fba45db2 5153end_stabs (void)
c906108c
SS
5154{
5155 if (type_vector)
5156 {
b8c9b27d 5157 xfree (type_vector);
c906108c
SS
5158 }
5159 type_vector = 0;
5160 type_vector_length = 0;
5161 previous_stab_code = 0;
5162}
5163
5164void
fba45db2 5165finish_global_stabs (struct objfile *objfile)
c906108c
SS
5166{
5167 if (global_stabs)
5168 {
5169 patch_block_stabs (global_symbols, global_stabs, objfile);
b8c9b27d 5170 xfree (global_stabs);
c906108c
SS
5171 global_stabs = NULL;
5172 }
5173}
5174
5175/* Initializer for this module */
5176
5177void
fba45db2 5178_initialize_stabsread (void)
c906108c
SS
5179{
5180 undef_types_allocated = 20;
5181 undef_types_length = 0;
5182 undef_types = (struct type **)
5183 xmalloc (undef_types_allocated * sizeof (struct type *));
5184}
This page took 0.473364 seconds and 4 git commands to generate.