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