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