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