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