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