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