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