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