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