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