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