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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gdb-6.8/] [gdb/] [stabsread.c] - Blame information for rev 827

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

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

powered by: WebSVN 2.1.0

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