OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [gdb/] [stabsread.c] - Blame information for rev 578

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.