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