* configure.in (*-*-ose): Remove exclusion of libgloss for this
[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
b607efe7
FF
78static void
79read_one_struct_field PARAMS ((struct field_info *, char **, char *,
80 struct type *, struct objfile *));
81
82static char *
83get_substring PARAMS ((char **, char));
84
d07734e3
FF
85static struct type *
86dbx_alloc_type PARAMS ((int [2], struct objfile *));
87
ea753d03
JK
88static long read_huge_number PARAMS ((char **, int, int *));
89
2dd30c72 90static struct type *error_type PARAMS ((char **, struct objfile *));
d07734e3
FF
91
92static void
93patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
94 struct objfile *));
95
96static void
97fix_common_block PARAMS ((struct symbol *, int));
98
ea753d03
JK
99static int
100read_type_number PARAMS ((char **, int *));
101
d07734e3
FF
102static struct type *
103read_range_type PARAMS ((char **, int [2], struct objfile *));
104
105static struct type *
106read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *));
107
108static struct type *
109read_sun_floating_type PARAMS ((char **, int [2], struct objfile *));
110
111static struct type *
112read_enum_type PARAMS ((char **, struct type *, struct objfile *));
113
dd469789 114static struct type *
a387370d 115rs6000_builtin_type PARAMS ((int));
dd469789 116
e7177cc2
FF
117static int
118read_member_functions PARAMS ((struct field_info *, char **, struct type *,
119 struct objfile *));
120
121static int
122read_struct_fields PARAMS ((struct field_info *, char **, struct type *,
123 struct objfile *));
124
125static int
126read_baseclasses PARAMS ((struct field_info *, char **, struct type *,
127 struct objfile *));
128
129static int
130read_tilde_fields PARAMS ((struct field_info *, char **, struct type *,
131 struct objfile *));
132
133static int
134attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *));
135
136static int
137attach_fields_to_type PARAMS ((struct field_info *, struct type *,
138 struct objfile *));
139
d07734e3
FF
140static struct type *
141read_struct_type PARAMS ((char **, struct type *, struct objfile *));
142
143static struct type *
144read_array_type PARAMS ((char **, struct type *, struct objfile *));
145
146static struct type **
147read_args PARAMS ((char **, int, struct objfile *));
148
ea753d03 149static int
e7177cc2
FF
150read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *,
151 struct objfile *));
152
00d93b6d
DP
153/* new functions added for cfront support */
154
00d93b6d
DP
155static int
156copy_cfront_struct_fields PARAMS ((struct field_info *, struct type *,
157 struct objfile *));
158
159static char *
160get_cfront_method_physname PARAMS ((char *));
161
162static int
163read_cfront_baseclasses PARAMS ((struct field_info *, char **,
164 struct type *, struct objfile *));
165
166static int
167read_cfront_static_fields PARAMS ((struct field_info *, char**,
168 struct type *, struct objfile *));
169static int
170read_cfront_member_functions PARAMS ((struct field_info *, char **,
171 struct type *, struct objfile *));
172
173/* end new functions added for cfront support */
174
175
176
d07734e3
FF
177static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
178static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
179
180/* Define this as 1 if a pcc declaration of a char or short argument
181 gives the correct address. Otherwise assume pcc gives the
182 address of the corresponding int, which is not the same on a
183 big-endian machine. */
184
185#ifndef BELIEVE_PCC_PROMOTION
186#define BELIEVE_PCC_PROMOTION 0
187#endif
188
d07734e3
FF
189struct complaint invalid_cpp_abbrev_complaint =
190 {"invalid C++ abbreviation `%s'", 0, 0};
191
192struct complaint invalid_cpp_type_complaint =
193 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
194
195struct complaint member_fn_complaint =
196 {"member function type missing, got '%c'", 0, 0};
197
198struct complaint const_vol_complaint =
199 {"const/volatile indicator missing, got '%c'", 0, 0};
200
201struct complaint error_type_complaint =
202 {"debug info mismatch between compiler and debugger", 0, 0};
203
204struct complaint invalid_member_complaint =
205 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
206
207struct complaint range_type_base_complaint =
208 {"base type %d of range type is not defined", 0, 0};
209
210struct complaint reg_value_complaint =
0d14c7df 211 {"register number %d too large (max %d) in symbol %s", 0, 0};
d07734e3 212
2a021f21
JG
213struct complaint vtbl_notfound_complaint =
214 {"virtual function table pointer not found when defining class `%s'", 0, 0};
215
216struct complaint unrecognized_cplus_name_complaint =
217 {"Unknown C++ symbol name `%s'", 0, 0};
218
dd469789 219struct complaint rs6000_builtin_complaint =
a387370d 220 {"Unknown builtin type %d", 0, 0};
dd469789 221
02b40a19 222struct complaint unresolved_sym_chain_complaint =
b1027aa4 223 {"%s: common block `%s' from global_sym_chain unresolved", 0, 0};
02b40a19 224
e7177cc2
FF
225struct complaint stabs_general_complaint =
226 {"%s", 0, 0};
227
d07734e3
FF
228/* Make a list of forward references which haven't been defined. */
229
230static struct type **undef_types;
231static int undef_types_allocated;
232static int undef_types_length;
5e548861 233static struct symbol *current_symbol = NULL;
d07734e3 234
e7177cc2 235/* Check for and handle cretinous stabs symbol name continuation! */
2dd30c72 236#define STABS_CONTINUE(pp,objfile) \
e7177cc2 237 do { \
91a0575c 238 if (**(pp) == '\\' || (**(pp) == '?' && (*(pp))[1] == '\0')) \
2dd30c72 239 *(pp) = next_symbol_text (objfile); \
e7177cc2 240 } while (0)
d07734e3 241\f
25200748
JK
242/* FIXME: These probably should be our own types (like rs6000_builtin_type
243 has its own types) rather than builtin_type_*. */
244static struct type **os9k_type_vector[] = {
245 0,
246 &builtin_type_int,
247 &builtin_type_char,
248 &builtin_type_long,
249 &builtin_type_short,
250 &builtin_type_unsigned_char,
251 &builtin_type_unsigned_short,
252 &builtin_type_unsigned_long,
253 &builtin_type_unsigned_int,
254 &builtin_type_float,
255 &builtin_type_double,
256 &builtin_type_void,
257 &builtin_type_long_double
258};
259
260static void os9k_init_type_vector PARAMS ((struct type **));
261
262static void
263os9k_init_type_vector(tv)
264 struct type **tv;
265{
266 int i;
267 for (i=0; i<sizeof(os9k_type_vector)/sizeof(struct type **); i++)
268 tv[i] = (os9k_type_vector[i] == 0 ? 0 : *(os9k_type_vector[i]));
269}
270
d07734e3
FF
271/* Look up a dbx type-number pair. Return the address of the slot
272 where the type for that number-pair is stored.
273 The number-pair is in TYPENUMS.
274
275 This can be used for finding the type associated with that pair
276 or for associating a new type with the pair. */
277
278struct type **
279dbx_lookup_type (typenums)
280 int typenums[2];
281{
282 register int filenum = typenums[0];
283 register int index = typenums[1];
284 unsigned old_len;
285 register int real_filenum;
286 register struct header_file *f;
287 int f_orig_length;
288
289 if (filenum == -1) /* -1,-1 is for temporary types. */
290 return 0;
291
292 if (filenum < 0 || filenum >= n_this_object_header_files)
ea753d03
JK
293 {
294 static struct complaint msg = {"\
295Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
296 0, 0};
297 complain (&msg, filenum, index, symnum);
298 goto error_return;
299 }
d07734e3
FF
300
301 if (filenum == 0)
302 {
a387370d
JG
303 if (index < 0)
304 {
305 /* Caller wants address of address of type. We think
306 that negative (rs6k builtin) types will never appear as
307 "lvalues", (nor should they), so we stuff the real type
308 pointer into a temp, and return its address. If referenced,
309 this will do the right thing. */
310 static struct type *temp_type;
311
312 temp_type = rs6000_builtin_type(index);
313 return &temp_type;
314 }
315
d07734e3
FF
316 /* Type is defined outside of header files.
317 Find it in this object file's type vector. */
318 if (index >= type_vector_length)
319 {
320 old_len = type_vector_length;
321 if (old_len == 0)
322 {
323 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
324 type_vector = (struct type **)
6405302d 325 xmalloc (type_vector_length * sizeof (struct type *));
d07734e3
FF
326 }
327 while (index >= type_vector_length)
328 {
329 type_vector_length *= 2;
330 }
331 type_vector = (struct type **)
332 xrealloc ((char *) type_vector,
333 (type_vector_length * sizeof (struct type *)));
334 memset (&type_vector[old_len], 0,
335 (type_vector_length - old_len) * sizeof (struct type *));
25200748
JK
336
337 if (os9k_stabs)
338 /* Deal with OS9000 fundamental types. */
339 os9k_init_type_vector (type_vector);
d07734e3
FF
340 }
341 return (&type_vector[index]);
342 }
343 else
344 {
345 real_filenum = this_object_header_files[filenum];
346
347 if (real_filenum >= n_header_files)
348 {
ea753d03
JK
349 struct type *temp_type;
350 struct type **temp_type_p;
351
352 warning ("GDB internal error: bad real_filenum");
353
354 error_return:
355 temp_type = init_type (TYPE_CODE_ERROR, 0, 0, NULL, NULL);
356 temp_type_p = (struct type **) xmalloc (sizeof (struct type *));
357 *temp_type_p = temp_type;
358 return temp_type_p;
d07734e3
FF
359 }
360
361 f = &header_files[real_filenum];
362
363 f_orig_length = f->length;
364 if (index >= f_orig_length)
365 {
366 while (index >= f->length)
367 {
368 f->length *= 2;
369 }
370 f->vector = (struct type **)
371 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
372 memset (&f->vector[f_orig_length], 0,
373 (f->length - f_orig_length) * sizeof (struct type *));
374 }
375 return (&f->vector[index]);
376 }
377}
378
379/* Make sure there is a type allocated for type numbers TYPENUMS
380 and return the type object.
381 This can create an empty (zeroed) type object.
382 TYPENUMS may be (-1, -1) to return a new type object that is not
383 put into the type vector, and so may not be referred to by number. */
384
385static struct type *
386dbx_alloc_type (typenums, objfile)
387 int typenums[2];
388 struct objfile *objfile;
389{
390 register struct type **type_addr;
391
392 if (typenums[0] == -1)
393 {
394 return (alloc_type (objfile));
395 }
396
397 type_addr = dbx_lookup_type (typenums);
398
399 /* If we are referring to a type not known at all yet,
400 allocate an empty type for it.
401 We will fill it in later if we find out how. */
402 if (*type_addr == 0)
403 {
404 *type_addr = alloc_type (objfile);
405 }
406
407 return (*type_addr);
408}
409
410/* for all the stabs in a given stab vector, build appropriate types
411 and fix their symbols in given symbol vector. */
412
413static void
414patch_block_stabs (symbols, stabs, objfile)
415 struct pending *symbols;
416 struct pending_stabs *stabs;
417 struct objfile *objfile;
418{
419 int ii;
420 char *name;
421 char *pp;
422 struct symbol *sym;
423
424 if (stabs)
425 {
426
427 /* for all the stab entries, find their corresponding symbols and
428 patch their types! */
429
430 for (ii = 0; ii < stabs->count; ++ii)
431 {
432 name = stabs->stab[ii];
433 pp = (char*) strchr (name, ':');
2fb58b98
KH
434 while (pp[1] == ':')
435 {
436 pp += 2;
437 pp = (char *)strchr(pp, ':');
438 }
d07734e3
FF
439 sym = find_symbol_in_list (symbols, name, pp-name);
440 if (!sym)
441 {
553e1862
JK
442 /* FIXME-maybe: it would be nice if we noticed whether
443 the variable was defined *anywhere*, not just whether
444 it is defined in this compilation unit. But neither
445 xlc or GCC seem to need such a definition, and until
446 we do psymtabs (so that the minimal symbols from all
447 compilation units are available now), I'm not sure
448 how to get the information. */
acdec954 449
0848ad1c
JK
450 /* On xcoff, if a global is defined and never referenced,
451 ld will remove it from the executable. There is then
452 a N_GSYM stab for it, but no regular (C_EXT) symbol. */
453 sym = (struct symbol *)
454 obstack_alloc (&objfile->symbol_obstack,
455 sizeof (struct symbol));
456
457 memset (sym, 0, sizeof (struct symbol));
458 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
459 SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT;
460 SYMBOL_NAME (sym) =
ace4b8d7 461 obsavestring (name, pp - name, &objfile->symbol_obstack);
0848ad1c
JK
462 pp += 2;
463 if (*(pp-1) == 'F' || *(pp-1) == 'f')
464 {
465 /* I don't think the linker does this with functions,
466 so as far as I know this is never executed.
467 But it doesn't hurt to check. */
468 SYMBOL_TYPE (sym) =
469 lookup_function_type (read_type (&pp, objfile));
470 }
471 else
472 {
473 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
474 }
475 add_symbol_to_list (sym, &global_symbols);
d07734e3
FF
476 }
477 else
478 {
479 pp += 2;
480 if (*(pp-1) == 'F' || *(pp-1) == 'f')
481 {
482 SYMBOL_TYPE (sym) =
483 lookup_function_type (read_type (&pp, objfile));
484 }
485 else
486 {
487 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
488 }
489 }
490 }
491 }
492}
493
494\f
495/* Read a number by which a type is referred to in dbx data,
496 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
497 Just a single number N is equivalent to (0,N).
498 Return the two numbers by storing them in the vector TYPENUMS.
ea753d03 499 TYPENUMS will then be used as an argument to dbx_lookup_type.
d07734e3 500
ea753d03
JK
501 Returns 0 for success, -1 for error. */
502
503static int
d07734e3
FF
504read_type_number (pp, typenums)
505 register char **pp;
506 register int *typenums;
507{
ea753d03 508 int nbits;
d07734e3
FF
509 if (**pp == '(')
510 {
511 (*pp)++;
ea753d03
JK
512 typenums[0] = read_huge_number (pp, ',', &nbits);
513 if (nbits != 0) return -1;
514 typenums[1] = read_huge_number (pp, ')', &nbits);
515 if (nbits != 0) return -1;
d07734e3
FF
516 }
517 else
518 {
519 typenums[0] = 0;
ea753d03
JK
520 typenums[1] = read_huge_number (pp, 0, &nbits);
521 if (nbits != 0) return -1;
d07734e3 522 }
ea753d03 523 return 0;
d07734e3
FF
524}
525
526\f
28f851f9 527#if !defined (REG_STRUCT_HAS_ADDR)
84ad95c1 528#define REG_STRUCT_HAS_ADDR(gcc_p,type) 0
28f851f9
JK
529#endif
530
94f5a25f
DP
531#define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
532#define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
533#define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
534#define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
535
536#define CFRONT_VISIBILITY_PRIVATE '2' /* Stabs character for private field */
537#define CFRONT_VISIBILITY_PUBLIC '1' /* Stabs character for public field */
538
539/* This code added to support parsing of ARM/Cfront stabs strings */
540
541/* get substring from string up to char c
542 advance string pointer past suibstring */
543static char *
544get_substring(p, c)
545 char ** p;
546 char c;
547{
548 char * str;
549 str = *p;
550 *p = strchr(*p,c);
551 if (*p)
552 {
553 **p = 0;
554 (*p)++;
555 }
556 else
557 str = 0;
558 return str;
559}
560
561/* Physname gets strcat'd onto sname in order to recreate the mangled name
562 (see funtion gdb_mangle_name in gdbtypes.c). For cfront, make the physname
563 look like that of g++ - take out the initial mangling
564 eg: for sname="a" and fname="foo__1aFPFs_i" return "FPFs_i" */
565static char *
566get_cfront_method_physname(fname)
567 char * fname;
568{
569 int len=0;
570 /* FIXME would like to make this generic for g++ too, but
571 that is already handled in read_member_funcctions */
572 char * p = fname;
573
574 /* search ahead to find the start of the mangled suffix */
575 if (*p == '_' && *(p+1)=='_') /* compiler generated; probably a ctor/dtor */
576 p+=2;
577 while (p && ((p+1) - fname) < strlen(fname) && *(p+1)!='_')
578 p = strchr(p,'_');
579 if (!(p && *p=='_' && *(p+1)=='_'))
580 error("Invalid mangled function name %s",fname);
581 p+=2; /* advance past '__' */
582
583 /* struct name length and name of type should come next; advance past it */
584 while (isdigit(*p))
585 {
586 len = len*10 + (*p - '0');
587 p++;
588 }
589 p+=len;
590
591 return p;
592}
593
594/* Read base classes within cfront class definition.
00d93b6d
DP
595 eg: A:ZcA;1@Bpub v2@Bvirpri;__ct__1AFv func__1AFv *sfunc__1AFv ;as__1A ;;
596 ^^^^^^^^^^^^^^^^^^
597
598 A:ZcA;;foopri__1AFv foopro__1AFv __ct__1AFv __ct__1AFRC1A foopub__1AFv ;;;
599 ^
600 */
94f5a25f
DP
601static int
602read_cfront_baseclasses(fip, pp, type, objfile)
603 struct field_info *fip;
604 struct objfile * objfile;
605 char ** pp;
606 struct type * type;
607{
94f5a25f
DP
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);
3f550b59 622 return 1;
94f5a25f
DP
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);
3f550b59 690 return 1;
94f5a25f
DP
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);
3f550b59 718 return 1;
94f5a25f
DP
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);
3f550b59 730 return 1;
94f5a25f
DP
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
30b9d933 750static int
94f5a25f
DP
751read_cfront_member_functions(fip, pp, type, objfile)
752 struct field_info *fip;
753 char **pp;
754 struct type *type;
755 struct objfile *objfile;
756 {
757 /* This code extracted from read_member_functions
758 so as to do the similar thing for our funcs */
759
760 int nfn_fields = 0;
761 int length = 0;
762 /* Total number of member functions defined in this class. If the class
763 defines two `f' functions, and one `g' function, then this will have
764 the value 3. */
765 int total_length = 0;
766 int i;
767 struct next_fnfield
768 {
769 struct next_fnfield *next;
770 struct fn_field fn_field;
771 } *sublist;
772 struct type *look_ahead_type;
773 struct next_fnfieldlist *new_fnlist;
774 struct next_fnfield *new_sublist;
775 char *main_fn_name;
776 char * fname;
777 struct symbol * ref_func=0;
778
779 /* Process each list until we find something that is not a member function
780 or find the end of the functions. */
781
782 /* eg: p = "__ct__1AFv foo__1AFv ;;;" */
783 STABS_CONTINUE (pp, objfile); /* handle \\ */
784 while (**pp!=';' && (fname = get_substring(pp,' '),fname))
785 {
786 int is_static=0;
787 int sublist_count=0;
788 char * pname;
789 if (fname[0]=='*') /* static member */
790 {
791 is_static=1;
792 sublist_count++;
793 fname++;
794 }
795 ref_func = lookup_symbol (fname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name*/
796 if (!ref_func)
797 {
798 static struct complaint msg = {"\
799 Unable to find function symbol for %s\n",
800 0, 0};
801 complain (&msg, fname);
802 continue;
803 }
804 sublist = NULL;
805 look_ahead_type = NULL;
806 length = 0;
807
808 new_fnlist = (struct next_fnfieldlist *)
809 xmalloc (sizeof (struct next_fnfieldlist));
810 make_cleanup (free, new_fnlist);
811 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
812
813 /* The following is code to work around cfront generated stabs.
814 The stabs contains full mangled name for each field.
815 We try to demangle the name and extract the field name out of it. */
816 {
817 char *dem, *dem_p, *dem_args;
818 int dem_len;
819 dem = cplus_demangle (fname, DMGL_ANSI | DMGL_PARAMS);
820 if (dem != NULL)
821 {
822 dem_p = strrchr (dem, ':');
823 if (dem_p != 0 && *(dem_p-1)==':')
824 dem_p++;
825 /* get rid of args */
826 dem_args = strchr (dem_p, '(');
827 if (dem_args == NULL)
828 dem_len = strlen(dem_p);
829 else
830 dem_len = dem_args - dem_p;
831 main_fn_name =
832 obsavestring (dem_p, dem_len, &objfile -> type_obstack);
833 }
834 else
835 {
836 main_fn_name =
837 obsavestring (fname, strlen(fname), &objfile -> type_obstack);
838 }
839 } /* end of code for cfront work around */
840
841 new_fnlist -> fn_fieldlist.name = main_fn_name;
842
843 /*-------------------------------------------------*/
844 /* Set up the sublists
845 Sublists are stuff like args, static, visibility, etc.
846 so in ARM, we have to set that info some other way.
847 Multiple sublists happen if overloading
848 eg: foo::26=##1;:;2A.;
849 In g++, we'd loop here thru all the sublists... */
850 new_sublist =
851 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
852 make_cleanup (free, new_sublist);
853 memset (new_sublist, 0, sizeof (struct next_fnfield));
854
855 /* eat 1; from :;2A.; */
856 new_sublist -> fn_field.type = SYMBOL_TYPE(ref_func); /* normally takes a read_type */
857 /* make this type look like a method stub for gdb */
858 TYPE_FLAGS (new_sublist -> fn_field.type) |= TYPE_FLAG_STUB;
859 TYPE_CODE (new_sublist -> fn_field.type) = TYPE_CODE_METHOD;
860
861 /* If this is just a stub, then we don't have the real name here. */
862 if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB)
863 {
864 if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type))
865 TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type;
866 new_sublist -> fn_field.is_stub = 1;
867 }
868 /* physname used later in mangling; eg PFs_i,5 for foo__1aFPFs_i
869 physname gets strcat'd in order to recreate the onto mangled name */
870 pname = get_cfront_method_physname(fname);
871 new_sublist -> fn_field.physname = savestring (pname, strlen(pname));
872
873
874 /* Set this member function's visibility fields.
875 Unable to distinguish access from stabs definition!
876 Assuming public for now. FIXME!
877 (for private, set new_sublist->fn_field.is_private = 1,
878 for public, set new_sublist->fn_field.is_protected = 1) */
879
880 /* Unable to distinguish const/volatile from stabs definition!
3f550b59
FF
881 Assuming normal for now. FIXME! */
882
94f5a25f
DP
883 new_sublist -> fn_field.is_const = 0;
884 new_sublist -> fn_field.is_volatile = 0; /* volatile not implemented in cfront */
885
886 /* set virtual/static function info
887 How to get vtable offsets ?
888 Assuming normal for now FIXME!!
889 For vtables, figure out from whence this virtual function came.
890 It may belong to virtual function table of
891 one of its baseclasses.
892 set:
893 new_sublist -> fn_field.voffset = vtable offset,
894 new_sublist -> fn_field.fcontext = look_ahead_type;
895 where look_ahead_type is type of baseclass */
896 if (is_static)
897 new_sublist -> fn_field.voffset = VOFFSET_STATIC;
898 else /* normal member function. */
899 new_sublist -> fn_field.voffset = 0;
900 new_sublist -> fn_field.fcontext = 0;
901
902
903 /* prepare new sublist */
904 new_sublist -> next = sublist;
905 sublist = new_sublist;
906 length++;
907 /* In g++, we loop thu sublists - now we set from function */
908
909 new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *)
910 obstack_alloc (&objfile -> type_obstack,
911 sizeof (struct fn_field) * length);
912 memset (new_fnlist -> fn_fieldlist.fn_fields, 0,
913 sizeof (struct fn_field) * length);
914 for (i = length; (i--, sublist); sublist = sublist -> next)
915 {
916 new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field;
917 }
918
919 new_fnlist -> fn_fieldlist.length = length;
920 new_fnlist -> next = fip -> fnlist;
921 fip -> fnlist = new_fnlist;
922 nfn_fields++;
923 total_length += length;
924 STABS_CONTINUE (pp, objfile); /* handle \\ */
925 } /* end of loop */
926
927 if (nfn_fields)
928 {
929 /* type should already have space */
930 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
931 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
932 memset (TYPE_FN_FIELDLISTS (type), 0,
933 sizeof (struct fn_fieldlist) * nfn_fields);
934 TYPE_NFN_FIELDS (type) = nfn_fields;
935 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
936 }
937
938 /* end of scope for reading member func */
939
940 /* eg: ";;" */
941 /* skip trailing ';' and bump count of number of fields seen */
942 if (**pp == ';')
943 (*pp)++;
944 else
945 return 0;
946 return 1;
947}
948
949/* This routine fixes up partial cfront types that were created
950 while parsing the stabs. The main need for this function is
951 to add information such as methods to classes.
952 Examples of "p": "sA;;__ct__1AFv foo__1AFv ;;;" */
953void
00d93b6d 954resolve_cfront_continuation(objfile, sym, p)
94f5a25f
DP
955 struct objfile * objfile;
956 struct symbol * sym;
957 char * p;
958{
959 struct symbol * ref_sym=0;
960 char * sname;
961 /* snarfed from read_struct_type */
962 struct field_info fi;
94f5a25f
DP
963 struct type *type;
964 struct cleanup *back_to;
965
966 /* need to make sure that fi isn't gunna conflict with struct
967 in case struct already had some fnfs */
968 fi.list = NULL;
969 fi.fnlist = NULL;
970 back_to = make_cleanup (null_cleanup, 0);
971
972 /* we only accept structs, classes and unions at the moment.
973 Other continuation types include t (typedef), r (long dbl), ...
974 We may want to add support for them as well;
975 right now they are handled by duplicating the symbol information
976 into the type information (see define_symbol) */
977 if (*p != 's' /* structs */
978 && *p != 'c' /* class */
979 && *p != 'u') /* union */
980 return; /* only handle C++ types */
981 p++;
982
983 /* get symbol typs name and validate
984 eg: p = "A;;__ct__1AFv foo__1AFv ;;;" */
985 sname = get_substring(&p,';');
986 if (!sname || strcmp(sname,SYMBOL_NAME(sym)))
987 error("Internal error: base symbol type name does not match\n");
988
989 /* find symbol's internal gdb reference */
990 ref_sym = lookup_symbol (SYMBOL_NAME(sym), 0, STRUCT_NAMESPACE, 0, 0); /*demangled_name*/
991 /* This is the real sym that we want;
992 sym was a temp hack to make debugger happy */
993 /* ref_sym should already have space */
994 type = SYMBOL_TYPE(ref_sym);
995
996
997 /* Now read the baseclasses, if any, read the regular C struct or C++
998 class member fields, attach the fields to the type, read the C++
999 member functions, attach them to the type, and then read any tilde
1000 field (baseclass specifier for the class holding the main vtable). */
1001
1002 if (!read_cfront_baseclasses (&fi, &p, type, objfile)
1003 /* g++ does this next, but cfront already did this:
1004 || !read_struct_fields (&fi, &p, type, objfile) */
00d93b6d 1005 || !copy_cfront_struct_fields (&fi, type, objfile)
94f5a25f 1006 || !read_cfront_member_functions (&fi, &p, type, objfile)
00d93b6d
DP
1007 || !read_cfront_static_fields(&fi, &p, type, objfile)
1008 || !attach_fields_to_type (&fi, type, objfile)
94f5a25f
DP
1009 || !attach_fn_fields_to_type (&fi, type)
1010 /* g++ does this next, but cfront doesn't seem to have this:
1011 || !read_tilde_fields (&fi, &p, type, objfile) */
1012 )
1013 {
1014 type = error_type (&p, objfile);
1015 }
1016
1017 do_cleanups (back_to);
1018}
1019/* End of code added to support parsing of ARM/Cfront stabs strings */
1020
1021
d07734e3
FF
1022/* ARGSUSED */
1023struct symbol *
1024define_symbol (valu, string, desc, type, objfile)
cef4c2e7 1025 CORE_ADDR valu;
d07734e3
FF
1026 char *string;
1027 int desc;
1028 int type;
1029 struct objfile *objfile;
1030{
1031 register struct symbol *sym;
1032 char *p = (char *) strchr (string, ':');
1033 int deftype;
1034 int synonym = 0;
1035 register int i;
d07734e3
FF
1036
1037 /* We would like to eliminate nameless symbols, but keep their types.
1038 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
94daba7f 1039 to type 2, but, should not create a symbol to address that type. Since
d07734e3
FF
1040 the symbol will be nameless, there is no way any user can refer to it. */
1041
1042 int nameless;
1043
1044 /* Ignore syms with empty names. */
1045 if (string[0] == 0)
1046 return 0;
1047
1048 /* Ignore old-style symbols from cc -go */
1049 if (p == 0)
1050 return 0;
1051
2fb58b98
KH
1052 while (p[1] == ':')
1053 {
1054 p += 2;
1055 p = strchr(p, ':');
1056 }
1057
d07734e3 1058 /* If a nameless stab entry, all we need is the type, not the symbol.
94daba7f
FF
1059 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
1060 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
d07734e3 1061
5e548861 1062 current_symbol = sym = (struct symbol *)
d07734e3 1063 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
c02a37ea 1064 memset (sym, 0, sizeof (struct symbol));
d07734e3 1065
a66e8382
SG
1066 switch (type & N_TYPE)
1067 {
1068 case N_TEXT:
1069 SYMBOL_SECTION(sym) = SECT_OFF_TEXT;
1070 break;
1071 case N_DATA:
1072 SYMBOL_SECTION(sym) = SECT_OFF_DATA;
1073 break;
1074 case N_BSS:
1075 SYMBOL_SECTION(sym) = SECT_OFF_BSS;
1076 break;
1077 }
1078
d07734e3
FF
1079 if (processing_gcc_compilation)
1080 {
1081 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1082 number of bytes occupied by a type or object, which we ignore. */
1083 SYMBOL_LINE(sym) = desc;
1084 }
1085 else
1086 {
1087 SYMBOL_LINE(sym) = 0; /* unknown */
1088 }
1089
81afee37 1090 if (is_cplus_marker (string[0]))
d07734e3
FF
1091 {
1092 /* Special GNU C++ names. */
1093 switch (string[1])
1094 {
1095 case 't':
1096 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1097 &objfile -> symbol_obstack);
1098 break;
1099
1100 case 'v': /* $vtbl_ptr_type */
1101 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1102 goto normal;
1103
1104 case 'e':
1105 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1106 &objfile -> symbol_obstack);
1107 break;
1108
1109 case '_':
1110 /* This was an anonymous type that was never fixed up. */
1111 goto normal;
1112
b9e58503
PS
1113#ifdef STATIC_TRANSFORM_NAME
1114 case 'X':
1115 /* SunPRO (3.0 at least) static variable encoding. */
1116 goto normal;
1117#endif
1118
d07734e3 1119 default:
b646b438 1120 complain (&unrecognized_cplus_name_complaint, string);
2a021f21 1121 goto normal; /* Do *something* with it */
d07734e3
FF
1122 }
1123 }
1124 else
1125 {
1126 normal:
2e4964ad 1127 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
d07734e3
FF
1128 SYMBOL_NAME (sym) = (char *)
1129 obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
ade40d31 1130 /* Open-coded memcpy--saves function call time. */
2e4964ad
FF
1131 /* FIXME: Does it really? Try replacing with simple strcpy and
1132 try it on an executable with a large symbol table. */
ade40d31
RP
1133 /* FIXME: considering that gcc can open code memcpy anyway, I
1134 doubt it. xoxorich. */
d07734e3
FF
1135 {
1136 register char *p1 = string;
1137 register char *p2 = SYMBOL_NAME (sym);
1138 while (p1 != p)
1139 {
1140 *p2++ = *p1++;
1141 }
1142 *p2++ = '\0';
1143 }
2e4964ad
FF
1144
1145 /* If this symbol is from a C++ compilation, then attempt to cache the
1146 demangled form for future reference. This is a typical time versus
1147 space tradeoff, that was decided in favor of time because it sped up
1148 C++ symbol lookups by a factor of about 20. */
1149
7532cf10 1150 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
d07734e3
FF
1151 }
1152 p++;
9b280a7f 1153
d07734e3 1154 /* Determine the type of name being defined. */
ea753d03
JK
1155#if 0
1156 /* Getting GDB to correctly skip the symbol on an undefined symbol
1157 descriptor and not ever dump core is a very dodgy proposition if
1158 we do things this way. I say the acorn RISC machine can just
1159 fix their compiler. */
d07734e3
FF
1160 /* The Acorn RISC machine's compiler can put out locals that don't
1161 start with "234=" or "(3,4)=", so assume anything other than the
1162 deftypes we know how to handle is a local. */
d07734e3 1163 if (!strchr ("cfFGpPrStTvVXCR", *p))
ea753d03
JK
1164#else
1165 if (isdigit (*p) || *p == '(' || *p == '-')
1166#endif
d07734e3
FF
1167 deftype = 'l';
1168 else
1169 deftype = *p++;
1170
59d69506 1171 switch (deftype)
d07734e3 1172 {
59d69506
JK
1173 case 'c':
1174 /* c is a special case, not followed by a type-number.
1175 SYMBOL:c=iVALUE for an integer constant symbol.
1176 SYMBOL:c=rVALUE for a floating constant symbol.
1177 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1178 e.g. "b:c=e6,0" for "const b = blob1"
1179 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
ea753d03
JK
1180 if (*p != '=')
1181 {
1182 SYMBOL_CLASS (sym) = LOC_CONST;
2dd30c72 1183 SYMBOL_TYPE (sym) = error_type (&p, objfile);
ea753d03
JK
1184 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1185 add_symbol_to_list (sym, &file_symbols);
1186 return sym;
1187 }
1188 ++p;
d07734e3
FF
1189 switch (*p++)
1190 {
1191 case 'r':
1192 {
1193 double d = atof (p);
1194 char *dbl_valu;
1195
bf5c0d64
JK
1196 /* FIXME-if-picky-about-floating-accuracy: Should be using
1197 target arithmetic to get the value. real.c in GCC
1198 probably has the necessary code. */
1199
f52bde21
JK
1200 /* FIXME: lookup_fundamental_type is a hack. We should be
1201 creating a type especially for the type of float constants.
bf5c0d64 1202 Problem is, what type should it be?
f52bde21
JK
1203
1204 Also, what should the name of this type be? Should we
1205 be using 'S' constants (see stabs.texinfo) instead? */
1206
d07734e3
FF
1207 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1208 FT_DBL_PREC_FLOAT);
1209 dbl_valu = (char *)
bf5c0d64
JK
1210 obstack_alloc (&objfile -> symbol_obstack,
1211 TYPE_LENGTH (SYMBOL_TYPE (sym)));
73edb321 1212 store_floating (dbl_valu, TYPE_LENGTH (SYMBOL_TYPE (sym)), d);
d07734e3
FF
1213 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1214 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1215 }
1216 break;
1217 case 'i':
1218 {
f52bde21
JK
1219 /* Defining integer constants this way is kind of silly,
1220 since 'e' constants allows the compiler to give not
1221 only the value, but the type as well. C has at least
1222 int, long, unsigned int, and long long as constant
1223 types; other languages probably should have at least
1224 unsigned as well as signed constants. */
1225
1226 /* We just need one int constant type for all objfiles.
1227 It doesn't depend on languages or anything (arguably its
1228 name should be a language-specific name for a type of
1229 that size, but I'm inclined to say that if the compiler
1230 wants a nice name for the type, it can use 'e'). */
1231 static struct type *int_const_type;
1232
1233 /* Yes, this is as long as a *host* int. That is because we
1234 use atoi. */
1235 if (int_const_type == NULL)
1236 int_const_type =
1237 init_type (TYPE_CODE_INT,
1238 sizeof (int) * HOST_CHAR_BIT / TARGET_CHAR_BIT, 0,
1239 "integer constant",
1240 (struct objfile *)NULL);
1241 SYMBOL_TYPE (sym) = int_const_type;
d07734e3
FF
1242 SYMBOL_VALUE (sym) = atoi (p);
1243 SYMBOL_CLASS (sym) = LOC_CONST;
1244 }
1245 break;
1246 case 'e':
f52bde21
JK
1247 /* SYMBOL:c=eTYPE,INTVALUE for a constant symbol whose value
1248 can be represented as integral.
d07734e3
FF
1249 e.g. "b:c=e6,0" for "const b = blob1"
1250 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1251 {
d07734e3 1252 SYMBOL_CLASS (sym) = LOC_CONST;
f52bde21
JK
1253 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1254
1255 if (*p != ',')
1256 {
2dd30c72 1257 SYMBOL_TYPE (sym) = error_type (&p, objfile);
f52bde21
JK
1258 break;
1259 }
1260 ++p;
1261
1262 /* If the value is too big to fit in an int (perhaps because
1263 it is unsigned), or something like that, we silently get
1264 a bogus value. The type and everything else about it is
1265 correct. Ideally, we should be using whatever we have
1266 available for parsing unsigned and long long values,
1267 however. */
1268 SYMBOL_VALUE (sym) = atoi (p);
d07734e3
FF
1269 }
1270 break;
1271 default:
ff580c7b 1272 {
ff580c7b 1273 SYMBOL_CLASS (sym) = LOC_CONST;
2dd30c72 1274 SYMBOL_TYPE (sym) = error_type (&p, objfile);
ff580c7b 1275 }
d07734e3
FF
1276 }
1277 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1278 add_symbol_to_list (sym, &file_symbols);
1279 return sym;
d07734e3 1280
d07734e3
FF
1281 case 'C':
1282 /* The name of a caught exception. */
59d69506 1283 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1284 SYMBOL_CLASS (sym) = LOC_LABEL;
1285 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1286 SYMBOL_VALUE_ADDRESS (sym) = valu;
1287 add_symbol_to_list (sym, &local_symbols);
1288 break;
1289
1290 case 'f':
1291 /* A static function definition. */
59d69506 1292 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1293 SYMBOL_CLASS (sym) = LOC_BLOCK;
1294 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1295 add_symbol_to_list (sym, &file_symbols);
1296 /* fall into process_function_types. */
1297
1298 process_function_types:
1299 /* Function result types are described as the result type in stabs.
1300 We need to convert this to the function-returning-type-X type
1301 in GDB. E.g. "int" is converted to "function returning int". */
1302 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
7c606261 1303 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
d07734e3
FF
1304 /* fall into process_prototype_types */
1305
1306 process_prototype_types:
1307 /* Sun acc puts declared types of arguments here. We don't care
1308 about their actual types (FIXME -- we should remember the whole
1309 function prototype), but the list may define some new types
1310 that we have to remember, so we must scan it now. */
1311 while (*p == ';') {
1312 p++;
1313 read_type (&p, objfile);
1314 }
1315 break;
1316
1317 case 'F':
1318 /* A global function definition. */
59d69506 1319 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1320 SYMBOL_CLASS (sym) = LOC_BLOCK;
1321 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1322 add_symbol_to_list (sym, &global_symbols);
1323 goto process_function_types;
1324
1325 case 'G':
1326 /* For a class G (global) symbol, it appears that the
1327 value is not correct. It is necessary to search for the
1328 corresponding linker definition to find the value.
1329 These definitions appear at the end of the namelist. */
59d69506 1330 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1331 i = hashname (SYMBOL_NAME (sym));
1332 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1333 global_sym_chain[i] = sym;
1334 SYMBOL_CLASS (sym) = LOC_STATIC;
1335 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1336 add_symbol_to_list (sym, &global_symbols);
1337 break;
1338
1339 /* This case is faked by a conditional above,
1340 when there is no code letter in the dbx data.
1341 Dbx data never actually contains 'l'. */
d9389f37 1342 case 's':
d07734e3 1343 case 'l':
59d69506 1344 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1345 SYMBOL_CLASS (sym) = LOC_LOCAL;
1346 SYMBOL_VALUE (sym) = valu;
1347 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1348 add_symbol_to_list (sym, &local_symbols);
1349 break;
1350
1351 case 'p':
59d69506
JK
1352 if (*p == 'F')
1353 /* pF is a two-letter code that means a function parameter in Fortran.
1354 The type-number specifies the type of the return value.
1355 Translate it into a pointer-to-function type. */
1356 {
1357 p++;
1358 SYMBOL_TYPE (sym)
1359 = lookup_pointer_type
1360 (lookup_function_type (read_type (&p, objfile)));
1361 }
1362 else
1363 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1364
d07734e3
FF
1365 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1366 can also be a LOC_LOCAL_ARG depending on symbol type. */
1367#ifndef DBX_PARM_SYMBOL_CLASS
1368#define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1369#endif
59d69506 1370
d07734e3
FF
1371 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1372 SYMBOL_VALUE (sym) = valu;
1373 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
d07734e3
FF
1374 add_symbol_to_list (sym, &local_symbols);
1375
b8176214
ILT
1376 if (TARGET_BYTE_ORDER != BIG_ENDIAN)
1377 {
1378 /* On little-endian machines, this crud is never necessary,
1379 and, if the extra bytes contain garbage, is harmful. */
1380 break;
1381 }
1382
d07734e3
FF
1383 /* If it's gcc-compiled, if it says `short', believe it. */
1384 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1385 break;
1386
f52bde21
JK
1387#if !BELIEVE_PCC_PROMOTION
1388 {
1389 /* This is the signed type which arguments get promoted to. */
1390 static struct type *pcc_promotion_type;
1391 /* This is the unsigned type which arguments get promoted to. */
1392 static struct type *pcc_unsigned_promotion_type;
1393
1394 /* Call it "int" because this is mainly C lossage. */
1395 if (pcc_promotion_type == NULL)
1396 pcc_promotion_type =
1397 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1398 0, "int", NULL);
1399
1400 if (pcc_unsigned_promotion_type == NULL)
1401 pcc_unsigned_promotion_type =
1402 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
1403 TYPE_FLAG_UNSIGNED, "unsigned int", NULL);
d07734e3 1404
f52bde21
JK
1405#if defined(BELIEVE_PCC_PROMOTION_TYPE)
1406 /* This macro is defined on machines (e.g. sparc) where
1407 we should believe the type of a PCC 'short' argument,
1408 but shouldn't believe the address (the address is
dcb38973 1409 the address of the corresponding int).
f52bde21
JK
1410
1411 My guess is that this correction, as opposed to changing
1412 the parameter to an 'int' (as done below, for PCC
1413 on most machines), is the right thing to do
1414 on all machines, but I don't want to risk breaking
1415 something that already works. On most PCC machines,
1416 the sparc problem doesn't come up because the calling
1417 function has to zero the top bytes (not knowing whether
1418 the called function wants an int or a short), so there
dcb38973 1419 is little practical difference between an int and a short
f52bde21
JK
1420 (except perhaps what happens when the GDB user types
1421 "print short_arg = 0x10000;").
1422
1423 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1424 actually produces the correct address (we don't need to fix it
1425 up). I made this code adapt so that it will offset the symbol
1426 if it was pointing at an int-aligned location and not
1427 otherwise. This way you can use the same gdb for 4.0.x and
1428 4.1 systems.
1429
1430 If the parameter is shorter than an int, and is integral
1431 (e.g. char, short, or unsigned equivalent), and is claimed to
1432 be passed on an integer boundary, don't believe it! Offset the
1433 parameter's address to the tail-end of that integer. */
1434
1435 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1436 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1437 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (pcc_promotion_type))
1438 {
1439 SYMBOL_VALUE (sym) += TYPE_LENGTH (pcc_promotion_type)
1440 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1441 }
1442 break;
1443
d07734e3
FF
1444#else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1445
f52bde21
JK
1446 /* If PCC says a parameter is a short or a char,
1447 it is really an int. */
1448 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (pcc_promotion_type)
1449 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1450 {
1451 SYMBOL_TYPE (sym) =
1452 TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1453 ? pcc_unsigned_promotion_type
1454 : pcc_promotion_type;
1455 }
1456 break;
d07734e3
FF
1457
1458#endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
f52bde21
JK
1459 }
1460#endif /* !BELIEVE_PCC_PROMOTION. */
d07734e3
FF
1461
1462 case 'P':
a97a483c 1463 /* acc seems to use P to declare the prototypes of functions that
d07734e3
FF
1464 are referenced by this file. gdb is not prepared to deal
1465 with this extra information. FIXME, it ought to. */
1466 if (type == N_FUN)
59d69506 1467 {
a97a483c 1468 SYMBOL_TYPE (sym) = read_type (&p, objfile);
59d69506
JK
1469 goto process_prototype_types;
1470 }
f52bde21 1471 /*FALLTHROUGH*/
d07734e3 1472
f52bde21 1473 case 'R':
d07734e3 1474 /* Parameter which is in a register. */
59d69506 1475 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1476 SYMBOL_CLASS (sym) = LOC_REGPARM;
1477 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1478 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1479 {
0d14c7df
FF
1480 complain (&reg_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
1481 SYMBOL_SOURCE_NAME (sym));
d07734e3
FF
1482 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1483 }
1484 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1485 add_symbol_to_list (sym, &local_symbols);
1486 break;
1487
d07734e3
FF
1488 case 'r':
1489 /* Register variable (either global or local). */
59d69506 1490 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1491 SYMBOL_CLASS (sym) = LOC_REGISTER;
1492 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1493 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1494 {
0d14c7df
FF
1495 complain (&reg_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
1496 SYMBOL_SOURCE_NAME (sym));
d07734e3
FF
1497 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1498 }
1499 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
4bfe9e81 1500 if (within_function)
5afa2040
JK
1501 {
1502 /* Sun cc uses a pair of symbols, one 'p' and one 'r' with the same
1503 name to represent an argument passed in a register.
1504 GCC uses 'P' for the same case. So if we find such a symbol pair
649694ea
JK
1505 we combine it into one 'P' symbol. For Sun cc we need to do this
1506 regardless of REG_STRUCT_HAS_ADDR, because the compiler puts out
1507 the 'p' symbol even if it never saves the argument onto the stack.
28f851f9 1508
649694ea 1509 On most machines, we want to preserve both symbols, so that
28f851f9 1510 we can still get information about what is going on with the
4bfe9e81
JK
1511 stack (VAX for computing args_printed, using stack slots instead
1512 of saved registers in backtraces, etc.).
1513
5afa2040 1514 Note that this code illegally combines
28f851f9 1515 main(argc) struct foo argc; { register struct foo argc; }
5afa2040
JK
1516 but this case is considered pathological and causes a warning
1517 from a decent compiler. */
28f851f9 1518
5afa2040 1519 if (local_symbols
4bfe9e81 1520 && local_symbols->nsyms > 0
649694ea 1521#ifndef USE_REGISTER_NOT_ARG
84ad95c1
JL
1522 && REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
1523 SYMBOL_TYPE (sym))
4bfe9e81 1524 && (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1c486a2b
PB
1525 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION
1526 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET
1527 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
649694ea
JK
1528#endif
1529 )
5afa2040
JK
1530 {
1531 struct symbol *prev_sym;
1532 prev_sym = local_symbols->symbol[local_symbols->nsyms - 1];
649694ea
JK
1533 if ((SYMBOL_CLASS (prev_sym) == LOC_REF_ARG
1534 || SYMBOL_CLASS (prev_sym) == LOC_ARG)
5afa2040
JK
1535 && STREQ (SYMBOL_NAME (prev_sym), SYMBOL_NAME(sym)))
1536 {
1537 SYMBOL_CLASS (prev_sym) = LOC_REGPARM;
fc81adb8
JK
1538 /* Use the type from the LOC_REGISTER; that is the type
1539 that is actually in that register. */
1540 SYMBOL_TYPE (prev_sym) = SYMBOL_TYPE (sym);
5afa2040
JK
1541 SYMBOL_VALUE (prev_sym) = SYMBOL_VALUE (sym);
1542 sym = prev_sym;
1543 break;
1544 }
1545 }
1546 add_symbol_to_list (sym, &local_symbols);
1547 }
d07734e3
FF
1548 else
1549 add_symbol_to_list (sym, &file_symbols);
1550 break;
1551
1552 case 'S':
1553 /* Static symbol at top level of file */
59d69506 1554 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1555 SYMBOL_CLASS (sym) = LOC_STATIC;
1556 SYMBOL_VALUE_ADDRESS (sym) = valu;
137a07e6
JK
1557#ifdef STATIC_TRANSFORM_NAME
1558 if (SYMBOL_NAME (sym)[0] == '$')
1559 {
1560 struct minimal_symbol *msym;
1561 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1562 if (msym != NULL)
1563 {
1564 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1565 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1566 }
1567 }
1568#endif
d07734e3
FF
1569 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1570 add_symbol_to_list (sym, &file_symbols);
1571 break;
1572
1573 case 't':
59d69506
JK
1574 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1575
d07734e3
FF
1576 /* For a nameless type, we don't want a create a symbol, thus we
1577 did not use `sym'. Return without further processing. */
1578 if (nameless) return NULL;
1579
1580 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1581 SYMBOL_VALUE (sym) = valu;
1582 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1583 /* C++ vagaries: we may have a type which is derived from
59d69506
JK
1584 a base type which did not have its name defined when the
1585 derived class was output. We fill in the derived class's
1586 base part member's name here in that case. */
d07734e3 1587 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
59d69506
JK
1588 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1589 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1590 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1591 {
1592 int j;
1593 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1594 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1595 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1596 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1597 }
d07734e3 1598
f52bde21 1599 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
59d69506 1600 {
36a2283d
PB
1601 /* gcc-2.6 or later (when using -fvtable-thunks)
1602 emits a unique named type for a vtable entry.
1603 Some gdb code depends on that specific name. */
1604 extern const char vtbl_ptr_name[];
1605
1606 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_PTR
1607 && strcmp (SYMBOL_NAME (sym), vtbl_ptr_name))
5af4f5f6 1608 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_FUNC)
59d69506 1609 {
5af4f5f6
JK
1610 /* If we are giving a name to a type such as "pointer to
1611 foo" or "function returning foo", we better not set
1612 the TYPE_NAME. If the program contains "typedef char
1613 *caddr_t;", we don't want all variables of type char
1614 * to print as caddr_t. This is not just a
1615 consequence of GDB's type management; PCC and GCC (at
1616 least through version 2.4) both output variables of
1617 either type char * or caddr_t with the type number
1618 defined in the 't' symbol for caddr_t. If a future
1619 compiler cleans this up it GDB is not ready for it
1620 yet, but if it becomes ready we somehow need to
1621 disable this check (without breaking the PCC/GCC2.4
1622 case).
59d69506
JK
1623
1624 Sigh.
1625
1626 Fortunately, this check seems not to be necessary
5af4f5f6 1627 for anything except pointers or functions. */
59d69506
JK
1628 }
1629 else
1630 TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_NAME (sym);
1631 }
f52bde21 1632
d07734e3
FF
1633 add_symbol_to_list (sym, &file_symbols);
1634 break;
1635
1636 case 'T':
59d69506
JK
1637 /* Struct, union, or enum tag. For GNU C++, this can be be followed
1638 by 't' which means we are typedef'ing it as well. */
1639 synonym = *p == 't';
1640
1641 if (synonym)
5e548861 1642 p++;
91f87016
JL
1643 /* The semantics of C++ state that "struct foo { ... }" also defines
1644 a typedef for "foo". Unfortunately, cfront never makes the typedef
1645 when translating C++ into C. We make the typedef here so that
1646 "ptype foo" works as expected for cfront translated code. */
1647 else if (current_subfile->language == language_cplus)
5e548861 1648 synonym = 1;
59d69506
JK
1649
1650 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1651
d07734e3
FF
1652 /* For a nameless type, we don't want a create a symbol, thus we
1653 did not use `sym'. Return without further processing. */
1654 if (nameless) return NULL;
1655
1656 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1657 SYMBOL_VALUE (sym) = valu;
1658 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
b2bebdb0
JK
1659 if (TYPE_TAG_NAME (SYMBOL_TYPE (sym)) == 0)
1660 TYPE_TAG_NAME (SYMBOL_TYPE (sym))
1661 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
d07734e3
FF
1662 add_symbol_to_list (sym, &file_symbols);
1663
1664 if (synonym)
1665 {
2e4964ad 1666 /* Clone the sym and then modify it. */
d07734e3 1667 register struct symbol *typedef_sym = (struct symbol *)
dac9734e 1668 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
2e4964ad 1669 *typedef_sym = *sym;
d07734e3
FF
1670 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1671 SYMBOL_VALUE (typedef_sym) = valu;
1672 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
b2bebdb0
JK
1673 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1674 TYPE_NAME (SYMBOL_TYPE (sym))
1675 = obconcat (&objfile -> type_obstack, "", "", SYMBOL_NAME (sym));
d07734e3
FF
1676 add_symbol_to_list (typedef_sym, &file_symbols);
1677 }
1678 break;
1679
1680 case 'V':
1681 /* Static symbol of local scope */
59d69506 1682 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1683 SYMBOL_CLASS (sym) = LOC_STATIC;
1684 SYMBOL_VALUE_ADDRESS (sym) = valu;
137a07e6
JK
1685#ifdef STATIC_TRANSFORM_NAME
1686 if (SYMBOL_NAME (sym)[0] == '$')
1687 {
1688 struct minimal_symbol *msym;
1689 msym = lookup_minimal_symbol (SYMBOL_NAME (sym), NULL, objfile);
1690 if (msym != NULL)
1691 {
1692 SYMBOL_NAME (sym) = STATIC_TRANSFORM_NAME (SYMBOL_NAME (sym));
1693 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msym);
1694 }
1695 }
1696#endif
d07734e3 1697 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
25200748
JK
1698 if (os9k_stabs)
1699 add_symbol_to_list (sym, &global_symbols);
1700 else
1701 add_symbol_to_list (sym, &local_symbols);
d07734e3
FF
1702 break;
1703
1704 case 'v':
1705 /* Reference parameter */
59d69506 1706 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1707 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1708 SYMBOL_VALUE (sym) = valu;
1709 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1710 add_symbol_to_list (sym, &local_symbols);
1711 break;
1712
117a817d
JL
1713 case 'a':
1714 /* Reference parameter which is in a register. */
1715 SYMBOL_TYPE (sym) = read_type (&p, objfile);
1716 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1717 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1718 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1719 {
0d14c7df
FF
1720 complain (&reg_value_complaint, SYMBOL_VALUE (sym), NUM_REGS,
1721 SYMBOL_SOURCE_NAME (sym));
117a817d
JL
1722 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1723 }
1724 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1725 add_symbol_to_list (sym, &local_symbols);
1726 break;
1727
d07734e3
FF
1728 case 'X':
1729 /* This is used by Sun FORTRAN for "function result value".
1730 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1731 that Pascal uses it too, but when I tried it Pascal used
1732 "x:3" (local symbol) instead. */
59d69506 1733 SYMBOL_TYPE (sym) = read_type (&p, objfile);
d07734e3
FF
1734 SYMBOL_CLASS (sym) = LOC_LOCAL;
1735 SYMBOL_VALUE (sym) = valu;
1736 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1737 add_symbol_to_list (sym, &local_symbols);
1738 break;
1739
94f5a25f
DP
1740 /* New code added to support cfront stabs strings */
1741 /* Note: case 'P' already handled above */
1742 case 'Z':
1743 /* Cfront type continuation coming up!
1744 find the original definition and add to it.
1745 We'll have to do this for the typedef too,
1746 since we clloned the symbol to define a type in read_type.
1747 Stabs info examples:
1748 __1C :Ztl
1749 foo__1CFv :ZtF (first def foo__1CFv:F(0,3);(0,24))
1750 C:ZsC;;__ct__1CFv func1__1CFv func2__1CFv ... ;;;
1751 where C is the name of the class. */
1752 /* can't lookup symbol yet 'cuz symbols not read yet
1753 so we save it for processing later */
1754 process_later(sym,p);
1755 SYMBOL_TYPE (sym) = error_type (&p, objfile); /* FIXME! change later */
1756 SYMBOL_CLASS (sym) = LOC_CONST;
1757 SYMBOL_VALUE (sym) = 0;
1758 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1759 /* don't add to list - we'll delete it later when
1760 we add the continuation to the real sym */
1761 return sym;
1762 /* End of new code added to support cfront stabs strings */
1763
d07734e3 1764 default:
2dd30c72 1765 SYMBOL_TYPE (sym) = error_type (&p, objfile);
ea753d03
JK
1766 SYMBOL_CLASS (sym) = LOC_CONST;
1767 SYMBOL_VALUE (sym) = 0;
ea753d03
JK
1768 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1769 add_symbol_to_list (sym, &file_symbols);
1770 break;
d07734e3 1771 }
5afa2040
JK
1772
1773 /* When passing structures to a function, some systems sometimes pass
1c486a2b 1774 the address in a register, not the structure itself. */
5afa2040 1775
1c486a2b 1776 if (REG_STRUCT_HAS_ADDR (processing_gcc_compilation,
84ad95c1 1777 SYMBOL_TYPE (sym))
f2613710 1778 && ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT)
1c486a2b
PB
1779 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1780 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_BITSTRING)
1781 || (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_SET)))
1782 {
1783 /* If REG_STRUCT_HAS_ADDR yields non-zero we have to
1784 convert LOC_REGPARM to LOC_REGPARM_ADDR for structures and unions. */
1785 if (SYMBOL_CLASS (sym) == LOC_REGPARM)
1786 SYMBOL_CLASS (sym) = LOC_REGPARM_ADDR;
1787 /* Likewise for converting LOC_ARG to LOC_REF_ARG (for the 7th and
1788 subsequent arguments on the sparc, for example). */
1789 else if (SYMBOL_CLASS (sym) == LOC_ARG)
1790 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1791 }
f2613710 1792
d07734e3
FF
1793 return sym;
1794}
1795
1796\f
1797/* Skip rest of this symbol and return an error type.
1798
1799 General notes on error recovery: error_type always skips to the
1800 end of the symbol (modulo cretinous dbx symbol name continuation).
1801 Thus code like this:
1802
1803 if (*(*pp)++ != ';')
2dd30c72 1804 return error_type (pp, objfile);
d07734e3
FF
1805
1806 is wrong because if *pp starts out pointing at '\0' (typically as the
1807 result of an earlier error), it will be incremented to point to the
1808 start of the next symbol, which might produce strange results, at least
1809 if you run off the end of the string table. Instead use
1810
1811 if (**pp != ';')
2dd30c72 1812 return error_type (pp, objfile);
d07734e3
FF
1813 ++*pp;
1814
1815 or
1816
1817 if (**pp != ';')
2dd30c72 1818 foo = error_type (pp, objfile);
d07734e3
FF
1819 else
1820 ++*pp;
1821
1822 And in case it isn't obvious, the point of all this hair is so the compiler
1823 can define new types and new syntaxes, and old versions of the
1824 debugger will be able to read the new symbol tables. */
1825
ea753d03 1826static struct type *
2dd30c72 1827error_type (pp, objfile)
d07734e3 1828 char **pp;
2dd30c72 1829 struct objfile *objfile;
d07734e3 1830{
51b80b00 1831 complain (&error_type_complaint);
d07734e3
FF
1832 while (1)
1833 {
1834 /* Skip to end of symbol. */
1835 while (**pp != '\0')
e7177cc2
FF
1836 {
1837 (*pp)++;
1838 }
d07734e3
FF
1839
1840 /* Check for and handle cretinous dbx symbol name continuation! */
91a0575c 1841 if ((*pp)[-1] == '\\' || (*pp)[-1] == '?')
e7177cc2 1842 {
2dd30c72 1843 *pp = next_symbol_text (objfile);
e7177cc2 1844 }
d07734e3 1845 else
e7177cc2
FF
1846 {
1847 break;
1848 }
d07734e3 1849 }
e7177cc2 1850 return (builtin_type_error);
d07734e3
FF
1851}
1852
1853\f
59d69506
JK
1854/* Read type information or a type definition; return the type. Even
1855 though this routine accepts either type information or a type
1856 definition, the distinction is relevant--some parts of stabsread.c
1857 assume that type information starts with a digit, '-', or '(' in
1858 deciding whether to call read_type. */
d07734e3
FF
1859
1860struct type *
1861read_type (pp, objfile)
1862 register char **pp;
1863 struct objfile *objfile;
1864{
1865 register struct type *type = 0;
1866 struct type *type1;
1867 int typenums[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{
00d93b6d
DP
3349 struct nextfield * new;
3350 struct type *stype;
3351 char * sname;
3352 struct symbol * ref_static=0;
3353
3354 if (**pp==';') /* no static data; return */
3355 {
3356 ++(*pp);
3f550b59 3357 return 1;
00d93b6d
DP
3358 }
3359
3360 /* Process each field in the list until we find the terminating ";" */
3361
3362 /* eg: p = "as__1A ;;;" */
3363 STABS_CONTINUE (pp, objfile); /* handle \\ */
3364 while (**pp!=';' && (sname = get_substring(pp,' '),sname))
3365 {
3366 ref_static = lookup_symbol (sname, 0, VAR_NAMESPACE, 0, 0); /*demangled_name*/
3367 if (!ref_static)
3368 {
3369 static struct complaint msg = {"\
3370 Unable to find symbol for static data field %s\n",
3371 0, 0};
3372 complain (&msg, sname);
3373 continue;
3374 }
3375 stype = SYMBOL_TYPE(ref_static);
3376
3377 /* allocate a new fip */
3378 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3379 make_cleanup (free, new);
3380 memset (new, 0, sizeof (struct nextfield));
3381 new -> next = fip -> list;
3382 fip -> list = new;
3383
3384 /* set visibility */
3385 /* FIXME! no way to tell visibility from stabs??? */
3386 new -> visibility = VISIBILITY_PUBLIC;
3387
3388 /* set field info into fip */
3389 fip -> list -> field.type = stype;
3390
3391 /* set bitpos & bitsize */
3392 fip -> list -> field.bitpos = (long) -1; /* -1 signifies a static member */
3393 /* YUK! what a hack! bitsize used for physname when field is static */
3394 fip -> list -> field.bitsize = (long) savestring (sname, strlen(sname));
3395
3396 /* set name field */
3397 /* The following is code to work around cfront generated stabs.
3398 The stabs contains full mangled name for each field.
3399 We try to demangle the name and extract the field name out of it.
3400 */
3401 if (ARM_DEMANGLING)
3402 {
3403 char *dem, *dem_p;
3404 dem = cplus_demangle (sname, DMGL_ANSI | DMGL_PARAMS);
3405 if (dem != NULL)
3406 {
3407 dem_p = strrchr (dem, ':');
3408 if (dem_p != 0 && *(dem_p-1)==':')
3409 dem_p++;
3410 fip->list->field.name =
3411 obsavestring (dem_p, strlen(dem_p), &objfile -> type_obstack);
3412 }
3413 else
3414 {
3415 fip->list->field.name =
3416 obsavestring (sname, strlen(sname), &objfile -> type_obstack);
3417 }
3418 } /* end of code for cfront work around */
3419 } /* loop again for next static field */
3420 return 1;
3421}
3422
3423/* Copy structure fields to fip so attach_fields_to_type will work.
3424 type has already been created with the initial instance data fields.
3425 Now we want to be able to add the other members to the class,
3426 so we want to add them back to the fip and reattach them again
3427 once we have collected all the class members. */
3428
3429static int
3430copy_cfront_struct_fields(fip, type, objfile)
3431 struct field_info *fip;
3432 struct type *type;
3433 struct objfile *objfile;
3434{
3435 int nfields = TYPE_NFIELDS(type);
3436 int i;
3437 struct nextfield * new;
3438
3439 /* Copy the fields into the list of fips and reset the types
3440 to remove the old fields */
3441
3442 for (i=0; i<nfields; i++)
3443 {
3444 /* allocate a new fip */
3445 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
3446 make_cleanup (free, new);
3447 memset (new, 0, sizeof (struct nextfield));
3448 new -> next = fip -> list;
3449 fip -> list = new;
3450
3451 /* copy field info into fip */
3452 new -> field = TYPE_FIELD (type, i);
3453 /* set visibility */
3454 if (TYPE_FIELD_PROTECTED (type, i))
3455 new -> visibility = VISIBILITY_PROTECTED;
3456 else if (TYPE_FIELD_PRIVATE (type, i))
3457 new -> visibility = VISIBILITY_PRIVATE;
3458 else
3459 new -> visibility = VISIBILITY_PUBLIC;
3460 }
3461 /* Now delete the fields from the type since we will be
3462 allocing new space once we get the rest of the fields
3463 in attach_fields_to_type.
3464 The pointer TYPE_FIELDS(type) is left dangling but should
3465 be freed later by objstack_free */
3466 TYPE_FIELDS (type)=0;
3467 TYPE_NFIELDS (type) = 0;
3468
3469 return 1;
3470}
3471
e7177cc2
FF
3472/* Create the vector of fields, and record how big it is.
3473 We need this info to record proper virtual function table information
3474 for this class's virtual functions. */
3475
3476static int
3477attach_fields_to_type (fip, type, objfile)
3478 struct field_info *fip;
3479 register struct type *type;
3480 struct objfile *objfile;
3481{
3482 register int nfields = 0;
3483 register int non_public_fields = 0;
3484 register struct nextfield *scan;
3485
3486 /* Count up the number of fields that we have, as well as taking note of
3487 whether or not there are any non-public fields, which requires us to
3488 allocate and build the private_field_bits and protected_field_bits
3489 bitfields. */
3490
3491 for (scan = fip -> list; scan != NULL; scan = scan -> next)
3492 {
3493 nfields++;
3494 if (scan -> visibility != VISIBILITY_PUBLIC)
3495 {
3496 non_public_fields++;
3497 }
3498 }
3499
3500 /* Now we know how many fields there are, and whether or not there are any
3501 non-public fields. Record the field count, allocate space for the
3502 array of fields, and create blank visibility bitfields if necessary. */
3503
3504 TYPE_NFIELDS (type) = nfields;
3505 TYPE_FIELDS (type) = (struct field *)
3506 TYPE_ALLOC (type, sizeof (struct field) * nfields);
3507 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
3508
3509 if (non_public_fields)
3510 {
3511 ALLOCATE_CPLUS_STRUCT_TYPE (type);
3512
3513 TYPE_FIELD_PRIVATE_BITS (type) =
3514 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3515 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
3516
3517 TYPE_FIELD_PROTECTED_BITS (type) =
3518 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3519 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
024f65b1
KH
3520
3521 TYPE_FIELD_IGNORE_BITS (type) =
3522 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
3523 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
e7177cc2
FF
3524 }
3525
3526 /* Copy the saved-up fields into the field vector. Start from the head
3527 of the list, adding to the tail of the field array, so that they end
3528 up in the same order in the array in which they were added to the list. */
3529
3530 while (nfields-- > 0)
3531 {
3532 TYPE_FIELD (type, nfields) = fip -> list -> field;
3533 switch (fip -> list -> visibility)
3534 {
3535 case VISIBILITY_PRIVATE:
3536 SET_TYPE_FIELD_PRIVATE (type, nfields);
3537 break;
3538
3539 case VISIBILITY_PROTECTED:
3540 SET_TYPE_FIELD_PROTECTED (type, nfields);
3541 break;
3542
024f65b1
KH
3543 case VISIBILITY_IGNORE:
3544 SET_TYPE_FIELD_IGNORE (type, nfields);
1dfaef62 3545 break;
024f65b1 3546
e7177cc2
FF
3547 case VISIBILITY_PUBLIC:
3548 break;
3549
3550 default:
1dfaef62
JK
3551 /* Unknown visibility. Complain and treat it as public. */
3552 {
3553 static struct complaint msg = {
3554 "Unknown visibility `%c' for field", 0, 0};
3555 complain (&msg, fip -> list -> visibility);
3556 }
e7177cc2
FF
3557 break;
3558 }
3559 fip -> list = fip -> list -> next;
3560 }
2a021f21 3561 return 1;
e7177cc2
FF
3562}
3563
3564/* Read the description of a structure (or union type) and return an object
3565 describing the type.
3566
3567 PP points to a character pointer that points to the next unconsumed token
3568 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
3569 *PP will point to "4a:1,0,32;;".
3570
3571 TYPE points to an incomplete type that needs to be filled in.
3572
3573 OBJFILE points to the current objfile from which the stabs information is
3574 being read. (Note that it is redundant in that TYPE also contains a pointer
3575 to this same objfile, so it might be a good idea to eliminate it. FIXME).
3576 */
3577
3578static struct type *
3579read_struct_type (pp, type, objfile)
3580 char **pp;
3581 struct type *type;
3582 struct objfile *objfile;
3583{
3584 struct cleanup *back_to;
3585 struct field_info fi;
3586
3587 fi.list = NULL;
3588 fi.fnlist = NULL;
3589
3590 back_to = make_cleanup (null_cleanup, 0);
3591
3592 INIT_CPLUS_SPECIFIC (type);
3593 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
3594
3595 /* First comes the total size in bytes. */
3596
ea753d03
JK
3597 {
3598 int nbits;
3599 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
3600 if (nbits != 0)
2dd30c72 3601 return error_type (pp, objfile);
ea753d03 3602 }
e7177cc2
FF
3603
3604 /* Now read the baseclasses, if any, read the regular C struct or C++
3605 class member fields, attach the fields to the type, read the C++
3606 member functions, attach them to the type, and then read any tilde
dd469789
JG
3607 field (baseclass specifier for the class holding the main vtable). */
3608
8a177da6
PB
3609 if (!read_baseclasses (&fi, pp, type, objfile)
3610 || !read_struct_fields (&fi, pp, type, objfile)
3611 || !attach_fields_to_type (&fi, type, objfile)
3612 || !read_member_functions (&fi, pp, type, objfile)
3613 || !attach_fn_fields_to_type (&fi, type)
3614 || !read_tilde_fields (&fi, pp, type, objfile))
e7177cc2 3615 {
34cfa2da 3616 type = error_type (pp, objfile);
e7177cc2
FF
3617 }
3618
3619 do_cleanups (back_to);
3620 return (type);
d07734e3
FF
3621}
3622
3623/* Read a definition of an array type,
3624 and create and return a suitable type object.
3625 Also creates a range type which represents the bounds of that
3626 array. */
3627
3628static struct type *
3629read_array_type (pp, type, objfile)
3630 register char **pp;
3631 register struct type *type;
3632 struct objfile *objfile;
3633{
3634 struct type *index_type, *element_type, *range_type;
3635 int lower, upper;
3636 int adjustable = 0;
ea753d03 3637 int nbits;
d07734e3
FF
3638
3639 /* Format of an array type:
25200748
JK
3640 "ar<index type>;lower;upper;<array_contents_type>".
3641 OS9000: "arlower,upper;<array_contents_type>".
d07734e3
FF
3642
3643 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
3644 for these, produce a type like float[][]. */
3645
25200748
JK
3646 if (os9k_stabs)
3647 index_type = builtin_type_int;
3648 else
3649 {
3650 index_type = read_type (pp, objfile);
3651 if (**pp != ';')
3652 /* Improper format of array type decl. */
2dd30c72 3653 return error_type (pp, objfile);
25200748
JK
3654 ++*pp;
3655 }
d07734e3 3656
11b959da 3657 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
d07734e3 3658 {
e7177cc2 3659 (*pp)++;
d07734e3
FF
3660 adjustable = 1;
3661 }
25200748 3662 lower = read_huge_number (pp, os9k_stabs ? ',' : ';', &nbits);
ea753d03 3663 if (nbits != 0)
2dd30c72 3664 return error_type (pp, objfile);
d07734e3 3665
11b959da 3666 if (!(**pp >= '0' && **pp <= '9') && **pp != '-')
d07734e3 3667 {
e7177cc2 3668 (*pp)++;
d07734e3
FF
3669 adjustable = 1;
3670 }
ea753d03
JK
3671 upper = read_huge_number (pp, ';', &nbits);
3672 if (nbits != 0)
2dd30c72 3673 return error_type (pp, objfile);
d07734e3
FF
3674
3675 element_type = read_type (pp, objfile);
3676
3677 if (adjustable)
3678 {
3679 lower = 0;
3680 upper = -1;
3681 }
3682
a8a69e63
FF
3683 range_type =
3684 create_range_type ((struct type *) NULL, index_type, lower, upper);
3685 type = create_array_type (type, element_type, range_type);
d07734e3 3686
d07734e3
FF
3687 return type;
3688}
3689
3690
3691/* Read a definition of an enumeration type,
3692 and create and return a suitable type object.
3693 Also defines the symbols that represent the values of the type. */
3694
3695static struct type *
3696read_enum_type (pp, type, objfile)
3697 register char **pp;
3698 register struct type *type;
3699 struct objfile *objfile;
3700{
3701 register char *p;
3702 char *name;
3703 register long n;
3704 register struct symbol *sym;
3705 int nsyms = 0;
3706 struct pending **symlist;
3707 struct pending *osyms, *syms;
3708 int o_nsyms;
25200748 3709 int nbits;
080868b4 3710 int unsigned_enum = 1;
d07734e3
FF
3711
3712#if 0
3713 /* FIXME! The stabs produced by Sun CC merrily define things that ought
3714 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
3715 to do? For now, force all enum values to file scope. */
3716 if (within_function)
3717 symlist = &local_symbols;
3718 else
3719#endif
3720 symlist = &file_symbols;
3721 osyms = *symlist;
3722 o_nsyms = osyms ? osyms->nsyms : 0;
3723
25200748
JK
3724 if (os9k_stabs)
3725 {
3726 /* Size. Perhaps this does not have to be conditionalized on
3727 os9k_stabs (assuming the name of an enum constant can't start
3728 with a digit). */
3729 read_huge_number (pp, 0, &nbits);
3730 if (nbits != 0)
2dd30c72 3731 return error_type (pp, objfile);
25200748
JK
3732 }
3733
65eaea27
JL
3734 /* The aix4 compiler emits an extra field before the enum members;
3735 my guess is it's a type of some sort. Just ignore it. */
3736 if (**pp == '-')
3737 {
3738 /* Skip over the type. */
3739 while (**pp != ':')
3740 (*pp)++;
3741
3742 /* Skip over the colon. */
3743 (*pp)++;
3744 }
3745
d07734e3
FF
3746 /* Read the value-names and their values.
3747 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
3748 A semicolon or comma instead of a NAME means the end. */
3749 while (**pp && **pp != ';' && **pp != ',')
3750 {
2dd30c72 3751 STABS_CONTINUE (pp, objfile);
d07734e3
FF
3752 p = *pp;
3753 while (*p != ':') p++;
3754 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
3755 *pp = p + 1;
ea753d03
JK
3756 n = read_huge_number (pp, ',', &nbits);
3757 if (nbits != 0)
2dd30c72 3758 return error_type (pp, objfile);
d07734e3 3759
c02a37ea
FF
3760 sym = (struct symbol *)
3761 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
d07734e3
FF
3762 memset (sym, 0, sizeof (struct symbol));
3763 SYMBOL_NAME (sym) = name;
2e4964ad 3764 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
d07734e3
FF
3765 SYMBOL_CLASS (sym) = LOC_CONST;
3766 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
3767 SYMBOL_VALUE (sym) = n;
080868b4
PS
3768 if (n < 0)
3769 unsigned_enum = 0;
d07734e3
FF
3770 add_symbol_to_list (sym, symlist);
3771 nsyms++;
3772 }
3773
3774 if (**pp == ';')
3775 (*pp)++; /* Skip the semicolon. */
3776
3777 /* Now fill in the fields of the type-structure. */
3778
eaba7fae 3779 TYPE_LENGTH (type) = TARGET_INT_BIT / HOST_CHAR_BIT;
d07734e3
FF
3780 TYPE_CODE (type) = TYPE_CODE_ENUM;
3781 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
080868b4
PS
3782 if (unsigned_enum)
3783 TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED;
d07734e3
FF
3784 TYPE_NFIELDS (type) = nsyms;
3785 TYPE_FIELDS (type) = (struct field *)
dac9734e 3786 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
c02a37ea 3787 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
d07734e3
FF
3788
3789 /* Find the symbols for the values and put them into the type.
3790 The symbols can be found in the symlist that we put them on
3791 to cause them to be defined. osyms contains the old value
3792 of that symlist; everything up to there was defined by us. */
3793 /* Note that we preserve the order of the enum constants, so
3794 that in something like "enum {FOO, LAST_THING=FOO}" we print
3795 FOO, not LAST_THING. */
3796
b6a40d0c 3797 for (syms = *symlist, n = nsyms - 1; syms; syms = syms->next)
d07734e3 3798 {
0f8631fb
PB
3799 int last = syms == osyms ? o_nsyms : 0;
3800 int j = syms->nsyms;
3801 for (; --j >= last; --n)
d07734e3
FF
3802 {
3803 struct symbol *xsym = syms->symbol[j];
3804 SYMBOL_TYPE (xsym) = type;
3805 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
3806 TYPE_FIELD_VALUE (type, n) = 0;
3807 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
3808 TYPE_FIELD_BITSIZE (type, n) = 0;
3809 }
3810 if (syms == osyms)
3811 break;
3812 }
3813
d07734e3
FF
3814 return type;
3815}
3816
3817/* Sun's ACC uses a somewhat saner method for specifying the builtin
3818 typedefs in every file (for int, long, etc):
3819
3820 type = b <signed> <width>; <offset>; <nbits>
3821 signed = u or s. Possible c in addition to u or s (for char?).
3822 offset = offset from high order bit to start bit of type.
3823 width is # bytes in object of this type, nbits is # bits in type.
3824
3825 The width/offset stuff appears to be for small objects stored in
3826 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
3827 FIXME. */
3828
3829static struct type *
3830read_sun_builtin_type (pp, typenums, objfile)
3831 char **pp;
3832 int typenums[2];
3833 struct objfile *objfile;
3834{
ea753d03 3835 int type_bits;
d07734e3
FF
3836 int nbits;
3837 int signed_type;
3838
3839 switch (**pp)
3840 {
3841 case 's':
3842 signed_type = 1;
3843 break;
3844 case 'u':
3845 signed_type = 0;
3846 break;
3847 default:
2dd30c72 3848 return error_type (pp, objfile);
d07734e3
FF
3849 }
3850 (*pp)++;
3851
3852 /* For some odd reason, all forms of char put a c here. This is strange
3853 because no other type has this honor. We can safely ignore this because
3854 we actually determine 'char'acterness by the number of bits specified in
3855 the descriptor. */
3856
3857 if (**pp == 'c')
3858 (*pp)++;
3859
3860 /* The first number appears to be the number of bytes occupied
3861 by this type, except that unsigned short is 4 instead of 2.
3862 Since this information is redundant with the third number,
3863 we will ignore it. */
ea753d03
JK
3864 read_huge_number (pp, ';', &nbits);
3865 if (nbits != 0)
2dd30c72 3866 return error_type (pp, objfile);
d07734e3
FF
3867
3868 /* The second number is always 0, so ignore it too. */
ea753d03
JK
3869 read_huge_number (pp, ';', &nbits);
3870 if (nbits != 0)
2dd30c72 3871 return error_type (pp, objfile);
d07734e3
FF
3872
3873 /* The third number is the number of bits for this type. */
ea753d03
JK
3874 type_bits = read_huge_number (pp, 0, &nbits);
3875 if (nbits != 0)
2dd30c72 3876 return error_type (pp, objfile);
159ada02
JK
3877 /* The type *should* end with a semicolon. If it are embedded
3878 in a larger type the semicolon may be the only way to know where
3879 the type ends. If this type is at the end of the stabstring we
3880 can deal with the omitted semicolon (but we don't have to like
3881 it). Don't bother to complain(), Sun's compiler omits the semicolon
3882 for "void". */
3883 if (**pp == ';')
3884 ++(*pp);
d07734e3 3885
2f3b7d8e
JK
3886 if (type_bits == 0)
3887 return init_type (TYPE_CODE_VOID, 1,
3888 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
3889 objfile);
3890 else
3891 return init_type (TYPE_CODE_INT,
3892 type_bits / TARGET_CHAR_BIT,
3893 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
3894 objfile);
d07734e3
FF
3895}
3896
3897static struct type *
3898read_sun_floating_type (pp, typenums, objfile)
3899 char **pp;
3900 int typenums[2];
3901 struct objfile *objfile;
3902{
ea753d03 3903 int nbits;
f52bde21 3904 int details;
d07734e3
FF
3905 int nbytes;
3906
3907 /* The first number has more details about the type, for example
f52bde21 3908 FN_COMPLEX. */
ea753d03
JK
3909 details = read_huge_number (pp, ';', &nbits);
3910 if (nbits != 0)
2dd30c72 3911 return error_type (pp, objfile);
d07734e3
FF
3912
3913 /* The second number is the number of bytes occupied by this type */
ea753d03
JK
3914 nbytes = read_huge_number (pp, ';', &nbits);
3915 if (nbits != 0)
2dd30c72 3916 return error_type (pp, objfile);
d07734e3 3917
ea753d03 3918 if (details == NF_COMPLEX || details == NF_COMPLEX16
f52bde21
JK
3919 || details == NF_COMPLEX32)
3920 /* This is a type we can't handle, but we do know the size.
3921 We also will be able to give it a name. */
3922 return init_type (TYPE_CODE_ERROR, nbytes, 0, NULL, objfile);
d07734e3 3923
f52bde21 3924 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
d07734e3
FF
3925}
3926
3927/* Read a number from the string pointed to by *PP.
3928 The value of *PP is advanced over the number.
3929 If END is nonzero, the character that ends the
3930 number must match END, or an error happens;
3931 and that character is skipped if it does match.
3932 If END is zero, *PP is left pointing to that character.
3933
ea753d03
JK
3934 If the number fits in a long, set *BITS to 0 and return the value.
3935 If not, set *BITS to be the number of bits in the number and return 0.
d07734e3 3936
ea753d03 3937 If encounter garbage, set *BITS to -1 and return 0. */
d07734e3 3938
ea753d03
JK
3939static long
3940read_huge_number (pp, end, bits)
d07734e3
FF
3941 char **pp;
3942 int end;
d07734e3
FF
3943 int *bits;
3944{
3945 char *p = *pp;
3946 int sign = 1;
3947 long n = 0;
3948 int radix = 10;
3949 char overflow = 0;
3950 int nbits = 0;
3951 int c;
3952 long upper_limit;
3953
3954 if (*p == '-')
3955 {
3956 sign = -1;
3957 p++;
3958 }
3959
3960 /* Leading zero means octal. GCC uses this to output values larger
3961 than an int (because that would be hard in decimal). */
3962 if (*p == '0')
3963 {
3964 radix = 8;
3965 p++;
3966 }
3967
8dbe58d8
KH
3968 if (os9k_stabs)
3969 upper_limit = ULONG_MAX / radix;
3970 else
3971 upper_limit = LONG_MAX / radix;
3972
574a2a49 3973 while ((c = *p++) >= '0' && c < ('0' + radix))
d07734e3
FF
3974 {
3975 if (n <= upper_limit)
3976 {
3977 n *= radix;
3978 n += c - '0'; /* FIXME this overflows anyway */
3979 }
3980 else
3981 overflow = 1;
3982
3983 /* This depends on large values being output in octal, which is
3984 what GCC does. */
3985 if (radix == 8)
3986 {
3987 if (nbits == 0)
3988 {
3989 if (c == '0')
3990 /* Ignore leading zeroes. */
3991 ;
3992 else if (c == '1')
3993 nbits = 1;
3994 else if (c == '2' || c == '3')
3995 nbits = 2;
3996 else
3997 nbits = 3;
3998 }
3999 else
4000 nbits += 3;
4001 }
4002 }
4003 if (end)
4004 {
4005 if (c && c != end)
4006 {
4007 if (bits != NULL)
4008 *bits = -1;
996ccb30 4009 return 0;
d07734e3
FF
4010 }
4011 }
4012 else
4013 --p;
4014
4015 *pp = p;
4016 if (overflow)
4017 {
4018 if (nbits == 0)
4019 {
4020 /* Large decimal constants are an error (because it is hard to
4021 count how many bits are in them). */
4022 if (bits != NULL)
4023 *bits = -1;
996ccb30 4024 return 0;
d07734e3
FF
4025 }
4026
4027 /* -0x7f is the same as 0x80. So deal with it by adding one to
4028 the number of bits. */
4029 if (sign == -1)
4030 ++nbits;
4031 if (bits)
4032 *bits = nbits;
4033 }
4034 else
4035 {
d07734e3
FF
4036 if (bits)
4037 *bits = 0;
ea753d03 4038 return n * sign;
d07734e3 4039 }
ea753d03
JK
4040 /* It's *BITS which has the interesting information. */
4041 return 0;
d07734e3
FF
4042}
4043
4044static struct type *
4045read_range_type (pp, typenums, objfile)
4046 char **pp;
4047 int typenums[2];
4048 struct objfile *objfile;
4049{
e55a5796 4050 char *orig_pp = *pp;
d07734e3
FF
4051 int rangenums[2];
4052 long n2, n3;
4053 int n2bits, n3bits;
4054 int self_subrange;
4055 struct type *result_type;
e55a5796 4056 struct type *index_type = NULL;
d07734e3
FF
4057
4058 /* First comes a type we are a subrange of.
4059 In C it is usually 0, 1 or the type being defined. */
ea753d03 4060 if (read_type_number (pp, rangenums) != 0)
2dd30c72 4061 return error_type (pp, objfile);
d07734e3
FF
4062 self_subrange = (rangenums[0] == typenums[0] &&
4063 rangenums[1] == typenums[1]);
4064
e55a5796
PB
4065 if (**pp == '=')
4066 {
4067 *pp = orig_pp;
4068 index_type = read_type (pp, objfile);
4069 }
4070
d07734e3
FF
4071 /* A semicolon should now follow; skip it. */
4072 if (**pp == ';')
4073 (*pp)++;
4074
4075 /* The remaining two operands are usually lower and upper bounds
4076 of the range. But in some special cases they mean something else. */
ea753d03
JK
4077 n2 = read_huge_number (pp, ';', &n2bits);
4078 n3 = read_huge_number (pp, ';', &n3bits);
d07734e3
FF
4079
4080 if (n2bits == -1 || n3bits == -1)
2dd30c72 4081 return error_type (pp, objfile);
e55a5796
PB
4082
4083 if (index_type)
4084 goto handle_true_range;
4085
d07734e3
FF
4086 /* If limits are huge, must be large integral type. */
4087 if (n2bits != 0 || n3bits != 0)
4088 {
4089 char got_signed = 0;
4090 char got_unsigned = 0;
4091 /* Number of bits in the type. */
46c28185 4092 int nbits = 0;
d07734e3
FF
4093
4094 /* Range from 0 to <large number> is an unsigned large integral type. */
4095 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
4096 {
4097 got_unsigned = 1;
4098 nbits = n3bits;
4099 }
4100 /* Range from <large number> to <large number>-1 is a large signed
cef4c2e7
PS
4101 integral type. Take care of the case where <large number> doesn't
4102 fit in a long but <large number>-1 does. */
4103 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
4104 || (n2bits != 0 && n3bits == 0
4105 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
4106 && n3 == LONG_MAX))
d07734e3
FF
4107 {
4108 got_signed = 1;
4109 nbits = n2bits;
4110 }
4111
d07734e3
FF
4112 if (got_signed || got_unsigned)
4113 {
f52bde21
JK
4114 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
4115 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
4116 objfile);
d07734e3
FF
4117 }
4118 else
2dd30c72 4119 return error_type (pp, objfile);
d07734e3
FF
4120 }
4121
4122 /* A type defined as a subrange of itself, with bounds both 0, is void. */
4123 if (self_subrange && n2 == 0 && n3 == 0)
2f3b7d8e 4124 return init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile);
d07734e3 4125
5e548861 4126 /* If n3 is zero and n2 is positive, we want a floating type,
d07734e3
FF
4127 and n2 is the width in bytes.
4128
4129 Fortran programs appear to use this for complex types also,
4130 and they give no way to distinguish between double and single-complex!
f52bde21
JK
4131
4132 GDB does not have complex types.
4133
4134 Just return the complex as a float of that size. It won't work right
ebccb10b 4135 for the complex values, but at least it makes the file loadable. */
d07734e3
FF
4136
4137 if (n3 == 0 && n2 > 0)
4138 {
f52bde21 4139 return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
d07734e3
FF
4140 }
4141
4142 /* If the upper bound is -1, it must really be an unsigned int. */
4143
4144 else if (n2 == 0 && n3 == -1)
4145 {
f52bde21 4146 /* It is unsigned int or unsigned long. */
78934ba8
JK
4147 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
4148 compatibility hack. */
f52bde21
JK
4149 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4150 TYPE_FLAG_UNSIGNED, NULL, objfile);
d07734e3
FF
4151 }
4152
4153 /* Special case: char is defined (Who knows why) as a subrange of
4154 itself with range 0-127. */
4155 else if (self_subrange && n2 == 0 && n3 == 127)
f52bde21
JK
4156 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4157
5e548861 4158 else if (current_symbol && SYMBOL_LANGUAGE (current_symbol) == language_chill
ec49fc98 4159 && !self_subrange)
5e548861
PB
4160 goto handle_true_range;
4161
f52bde21
JK
4162 /* We used to do this only for subrange of self or subrange of int. */
4163 else if (n2 == 0)
4164 {
4165 if (n3 < 0)
4166 /* n3 actually gives the size. */
4167 return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED,
4168 NULL, objfile);
4169 if (n3 == 0xff)
4170 return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile);
4171 if (n3 == 0xffff)
4172 return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile);
4173
4174 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
4175 "unsigned long", and we already checked for that,
4176 so don't need to test for it here. */
4177 }
4178 /* I think this is for Convex "long long". Since I don't know whether
4179 Convex sets self_subrange, I also accept that particular size regardless
4180 of self_subrange. */
4181 else if (n3 == 0 && n2 < 0
4182 && (self_subrange
4183 || n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
4184 return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile);
d07734e3
FF
4185 else if (n2 == -n3 -1)
4186 {
f52bde21
JK
4187 if (n3 == 0x7f)
4188 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
4189 if (n3 == 0x7fff)
4190 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
4191 if (n3 == 0x7fffffff)
4192 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
d07734e3
FF
4193 }
4194
4195 /* We have a real range type on our hands. Allocate space and
4196 return a real pointer. */
e55a5796 4197 handle_true_range:
d07734e3 4198
d07734e3 4199 if (self_subrange)
ec49fc98
PB
4200 index_type = builtin_type_int;
4201 else
4202 index_type = *dbx_lookup_type (rangenums);
a8a69e63
FF
4203 if (index_type == NULL)
4204 {
f52bde21
JK
4205 /* Does this actually ever happen? Is that why we are worrying
4206 about dealing with it rather than just calling error_type? */
4207
4208 static struct type *range_type_index;
4209
a8a69e63 4210 complain (&range_type_base_complaint, rangenums[1]);
f52bde21
JK
4211 if (range_type_index == NULL)
4212 range_type_index =
4213 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
4214 0, "range type index type", NULL);
4215 index_type = range_type_index;
a8a69e63 4216 }
d07734e3 4217
a8a69e63
FF
4218 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
4219 return (result_type);
d07734e3
FF
4220}
4221
d07734e3
FF
4222/* Read in an argument list. This is a list of types, separated by commas
4223 and terminated with END. Return the list of types read in, or (struct type
4224 **)-1 if there is an error. */
4225
4226static struct type **
4227read_args (pp, end, objfile)
4228 char **pp;
4229 int end;
4230 struct objfile *objfile;
4231{
4232 /* FIXME! Remove this arbitrary limit! */
4233 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
4234 int n = 0;
4235
4236 while (**pp != end)
4237 {
4238 if (**pp != ',')
4239 /* Invalid argument list: no ','. */
4240 return (struct type **)-1;
e7177cc2 4241 (*pp)++;
2dd30c72 4242 STABS_CONTINUE (pp, objfile);
d07734e3
FF
4243 types[n++] = read_type (pp, objfile);
4244 }
e7177cc2 4245 (*pp)++; /* get past `end' (the ':' character) */
d07734e3
FF
4246
4247 if (n == 1)
4248 {
4249 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
4250 }
4251 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
4252 {
4253 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
4254 memset (rval + n, 0, sizeof (struct type *));
4255 }
4256 else
4257 {
4258 rval = (struct type **) xmalloc (n * sizeof (struct type *));
4259 }
4260 memcpy (rval, types, n * sizeof (struct type *));
4261 return rval;
4262}
9438d642
JK
4263\f
4264/* Common block handling. */
4265
4266/* List of symbols declared since the last BCOMM. This list is a tail
4267 of local_symbols. When ECOMM is seen, the symbols on the list
4268 are noted so their proper addresses can be filled in later,
4269 using the common block base address gotten from the assembler
4270 stabs. */
4271
4272static struct pending *common_block;
4273static int common_block_i;
4274
4275/* Name of the current common block. We get it from the BCOMM instead of the
4276 ECOMM to match IBM documentation (even though IBM puts the name both places
4277 like everyone else). */
4278static char *common_block_name;
4279
4280/* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
4281 to remain after this function returns. */
4282
4283void
4284common_block_start (name, objfile)
4285 char *name;
4286 struct objfile *objfile;
4287{
4288 if (common_block_name != NULL)
4289 {
4290 static struct complaint msg = {
4291 "Invalid symbol data: common block within common block",
4292 0, 0};
4293 complain (&msg);
4294 }
4295 common_block = local_symbols;
4296 common_block_i = local_symbols ? local_symbols->nsyms : 0;
4297 common_block_name = obsavestring (name, strlen (name),
4298 &objfile -> symbol_obstack);
4299}
4300
4301/* Process a N_ECOMM symbol. */
4302
4303void
4304common_block_end (objfile)
4305 struct objfile *objfile;
4306{
4307 /* Symbols declared since the BCOMM are to have the common block
4308 start address added in when we know it. common_block and
4309 common_block_i point to the first symbol after the BCOMM in
4310 the local_symbols list; copy the list and hang it off the
4311 symbol for the common block name for later fixup. */
4312 int i;
4313 struct symbol *sym;
4314 struct pending *new = 0;
4315 struct pending *next;
4316 int j;
4317
4318 if (common_block_name == NULL)
4319 {
4320 static struct complaint msg = {"ECOMM symbol unmatched by BCOMM", 0, 0};
4321 complain (&msg);
4322 return;
4323 }
4324
4325 sym = (struct symbol *)
4326 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
4327 memset (sym, 0, sizeof (struct symbol));
ace4b8d7 4328 /* Note: common_block_name already saved on symbol_obstack */
9438d642
JK
4329 SYMBOL_NAME (sym) = common_block_name;
4330 SYMBOL_CLASS (sym) = LOC_BLOCK;
4331
4332 /* Now we copy all the symbols which have been defined since the BCOMM. */
4333
4334 /* Copy all the struct pendings before common_block. */
4335 for (next = local_symbols;
4336 next != NULL && next != common_block;
4337 next = next->next)
4338 {
4339 for (j = 0; j < next->nsyms; j++)
4340 add_symbol_to_list (next->symbol[j], &new);
4341 }
4342
4343 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
4344 NULL, it means copy all the local symbols (which we already did
4345 above). */
4346
4347 if (common_block != NULL)
4348 for (j = common_block_i; j < common_block->nsyms; j++)
4349 add_symbol_to_list (common_block->symbol[j], &new);
4350
fddb9bda 4351 SYMBOL_TYPE (sym) = (struct type *) new;
9438d642
JK
4352
4353 /* Should we be putting local_symbols back to what it was?
4354 Does it matter? */
4355
4356 i = hashname (SYMBOL_NAME (sym));
4357 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
4358 global_sym_chain[i] = sym;
4359 common_block_name = NULL;
4360}
d07734e3
FF
4361
4362/* Add a common block's start address to the offset of each symbol
4363 declared to be in it (by being between a BCOMM/ECOMM pair that uses
4364 the common block name). */
4365
4366static void
4367fix_common_block (sym, valu)
4368 struct symbol *sym;
4369 int valu;
4370{
fddb9bda 4371 struct pending *next = (struct pending *) SYMBOL_TYPE (sym);
d07734e3
FF
4372 for ( ; next; next = next->next)
4373 {
4374 register int j;
4375 for (j = next->nsyms - 1; j >= 0; j--)
4376 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
4377 }
4378}
4379
4380
4381\f
4382/* What about types defined as forward references inside of a small lexical
4383 scope? */
4384/* Add a type to the list of undefined types to be checked through
4385 once this file has been read in. */
4386
4387void
4388add_undefined_type (type)
4389 struct type *type;
4390{
4391 if (undef_types_length == undef_types_allocated)
4392 {
4393 undef_types_allocated *= 2;
4394 undef_types = (struct type **)
4395 xrealloc ((char *) undef_types,
4396 undef_types_allocated * sizeof (struct type *));
4397 }
4398 undef_types[undef_types_length++] = type;
4399}
4400
4401/* Go through each undefined type, see if it's still undefined, and fix it
4402 up if possible. We have two kinds of undefined types:
4403
4404 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
4405 Fix: update array length using the element bounds
4406 and the target type's length.
4407 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
4408 yet defined at the time a pointer to it was made.
4409 Fix: Do a full lookup on the struct/union tag. */
4410void
4411cleanup_undefined_types ()
4412{
4413 struct type **type;
4414
4415 for (type = undef_types; type < undef_types + undef_types_length; type++)
4416 {
4417 switch (TYPE_CODE (*type))
4418 {
4419
4420 case TYPE_CODE_STRUCT:
4421 case TYPE_CODE_UNION:
4422 case TYPE_CODE_ENUM:
4423 {
dda398c3 4424 /* Check if it has been defined since. Need to do this here
5e548861 4425 as well as in check_typedef to deal with the (legitimate in
dda398c3
JK
4426 C though not C++) case of several types with the same name
4427 in different source files. */
d07734e3
FF
4428 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
4429 {
4430 struct pending *ppt;
4431 int i;
4432 /* Name of the type, without "struct" or "union" */
b2bebdb0 4433 char *typename = TYPE_TAG_NAME (*type);
d07734e3 4434
ea753d03
JK
4435 if (typename == NULL)
4436 {
4437 static struct complaint msg = {"need a type name", 0, 0};
4438 complain (&msg);
4439 break;
4440 }
d07734e3
FF
4441 for (ppt = file_symbols; ppt; ppt = ppt->next)
4442 {
4443 for (i = 0; i < ppt->nsyms; i++)
4444 {
4445 struct symbol *sym = ppt->symbol[i];
4446
4447 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
4448 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
4449 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
4450 TYPE_CODE (*type))
2e4964ad 4451 && STREQ (SYMBOL_NAME (sym), typename))
d07734e3
FF
4452 {
4453 memcpy (*type, SYMBOL_TYPE (sym),
4454 sizeof (struct type));
4455 }
4456 }
4457 }
4458 }
4459 }
4460 break;
4461
ea753d03 4462 default:
ea753d03
JK
4463 {
4464 static struct complaint msg = {"\
4465GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
4466 complain (&msg, TYPE_CODE (*type));
4467 }
d07734e3
FF
4468 break;
4469 }
4470 }
dda398c3 4471
d07734e3
FF
4472 undef_types_length = 0;
4473}
4474
4475/* Scan through all of the global symbols defined in the object file,
4476 assigning values to the debugging symbols that need to be assigned
b1027aa4 4477 to. Get these symbols from the minimal symbol table. */
d07734e3 4478
b1027aa4
PS
4479void
4480scan_file_globals (objfile)
d07734e3
FF
4481 struct objfile *objfile;
4482{
4483 int hash;
4484 struct minimal_symbol *msymbol;
4485 struct symbol *sym, *prev;
4486
02b40a19
PS
4487 /* Avoid expensive loop through all minimal symbols if there are
4488 no unresolved symbols. */
4489 for (hash = 0; hash < HASHSIZE; hash++)
4490 {
4491 if (global_sym_chain[hash])
4492 break;
4493 }
4494 if (hash >= HASHSIZE)
b1027aa4 4495 return;
d07734e3 4496
b1027aa4
PS
4497 for (msymbol = objfile -> msymbols;
4498 msymbol && SYMBOL_NAME (msymbol) != NULL;
4499 msymbol++)
d07734e3
FF
4500 {
4501 QUIT;
4502
f3806e3b
PS
4503 /* Skip static symbols. */
4504 switch (MSYMBOL_TYPE (msymbol))
4505 {
4506 case mst_file_text:
4507 case mst_file_data:
4508 case mst_file_bss:
4509 continue;
9ed8604f
PS
4510 default:
4511 break;
f3806e3b
PS
4512 }
4513
d07734e3
FF
4514 prev = NULL;
4515
4516 /* Get the hash index and check all the symbols
4517 under that hash index. */
4518
2e4964ad 4519 hash = hashname (SYMBOL_NAME (msymbol));
d07734e3
FF
4520
4521 for (sym = global_sym_chain[hash]; sym;)
4522 {
2e4964ad
FF
4523 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
4524 STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
d07734e3
FF
4525 {
4526 /* Splice this symbol out of the hash chain and
4527 assign the value we have to it. */
4528 if (prev)
4529 {
4530 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
4531 }
4532 else
4533 {
4534 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
4535 }
4536
4537 /* Check to see whether we need to fix up a common block. */
4538 /* Note: this code might be executed several times for
4539 the same symbol if there are multiple references. */
4540
4541 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
4542 {
2e4964ad 4543 fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol));
d07734e3
FF
4544 }
4545 else
4546 {
2e4964ad 4547 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol);
d07734e3 4548 }
a66e8382
SG
4549
4550 SYMBOL_SECTION (sym) = SYMBOL_SECTION (msymbol);
d07734e3
FF
4551
4552 if (prev)
4553 {
4554 sym = SYMBOL_VALUE_CHAIN (prev);
4555 }
4556 else
4557 {
4558 sym = global_sym_chain[hash];
4559 }
4560 }
4561 else
4562 {
4563 prev = sym;
4564 sym = SYMBOL_VALUE_CHAIN (sym);
4565 }
4566 }
4567 }
02b40a19 4568
b1027aa4
PS
4569 /* Change the storage class of any remaining unresolved globals to
4570 LOC_UNRESOLVED and remove them from the chain. */
02b40a19
PS
4571 for (hash = 0; hash < HASHSIZE; hash++)
4572 {
4573 sym = global_sym_chain[hash];
4574 while (sym)
4575 {
b1027aa4
PS
4576 prev = sym;
4577 sym = SYMBOL_VALUE_CHAIN (sym);
02b40a19
PS
4578
4579 /* Change the symbol address from the misleading chain value
4580 to address zero. */
02b40a19 4581 SYMBOL_VALUE_ADDRESS (prev) = 0;
b1027aa4
PS
4582
4583 /* Complain about unresolved common block symbols. */
4584 if (SYMBOL_CLASS (prev) == LOC_STATIC)
4585 SYMBOL_CLASS (prev) = LOC_UNRESOLVED;
4586 else
4587 complain (&unresolved_sym_chain_complaint,
4588 objfile->name, SYMBOL_NAME (prev));
02b40a19
PS
4589 }
4590 }
4591 memset (global_sym_chain, 0, sizeof (global_sym_chain));
d07734e3
FF
4592}
4593
4594/* Initialize anything that needs initializing when starting to read
4595 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
4596 to a psymtab. */
4597
4598void
4599stabsread_init ()
4600{
4601}
4602
4603/* Initialize anything that needs initializing when a completely new
4604 symbol file is specified (not just adding some symbols from another
4605 file, e.g. a shared library). */
4606
4607void
4608stabsread_new_init ()
4609{
4610 /* Empty the hash table of global syms looking for values. */
4611 memset (global_sym_chain, 0, sizeof (global_sym_chain));
4612}
4613
4614/* Initialize anything that needs initializing at the same time as
4615 start_symtab() is called. */
4616
4617void start_stabs ()
4618{
4619 global_stabs = NULL; /* AIX COFF */
4620 /* Leave FILENUM of 0 free for builtin types and this file's types. */
4621 n_this_object_header_files = 1;
4622 type_vector_length = 0;
4623 type_vector = (struct type **) 0;
9438d642
JK
4624
4625 /* FIXME: If common_block_name is not already NULL, we should complain(). */
4626 common_block_name = NULL;
25200748
JK
4627
4628 os9k_stabs = 0;
d07734e3
FF
4629}
4630
4631/* Call after end_symtab() */
4632
4633void end_stabs ()
4634{
4635 if (type_vector)
4636 {
4637 free ((char *) type_vector);
4638 }
4639 type_vector = 0;
4640 type_vector_length = 0;
4641 previous_stab_code = 0;
4642}
4643
4644void
4645finish_global_stabs (objfile)
d07734e3
FF
4646 struct objfile *objfile;
4647{
4648 if (global_stabs)
4649 {
4650 patch_block_stabs (global_symbols, global_stabs, objfile);
4651 free ((PTR) global_stabs);
4652 global_stabs = NULL;
4653 }
4654}
4655
4656/* Initializer for this module */
4657
4658void
4659_initialize_stabsread ()
4660{
4661 undef_types_allocated = 20;
4662 undef_types_length = 0;
4663 undef_types = (struct type **)
4664 xmalloc (undef_types_allocated * sizeof (struct type *));
4665}
This page took 0.521474 seconds and 4 git commands to generate.