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