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