* stabsread.c (rs6000_builtin_type): Move function from
[deliverable/binutils-gdb.git] / gdb / stabsread.c
1 /* Support routines for decoding "stabs" debugging information format.
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993
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., 675 Mass Ave, Cambridge, MA 02139, 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 "bfd.h"
29 #include "obstack.h"
30 #include "symtab.h"
31 #include "gdbtypes.h"
32 #include "symfile.h"
33 #include "objfiles.h"
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
35 #include "buildsym.h"
36 #include "complaints.h"
37 #include "demangle.h"
38
39 /* Ask stabsread.h to define the vars it normally declares `extern'. */
40 #define EXTERN /**/
41 #include "stabsread.h" /* Our own declarations */
42 #undef EXTERN
43
44 /* The routines that read and process a complete stabs for a C struct or
45 C++ class pass lists of data member fields and lists of member function
46 fields in an instance of a field_info structure, as defined below.
47 This is part of some reorganization of low level C++ support and is
48 expected to eventually go away... (FIXME) */
49
50 struct field_info
51 {
52 struct nextfield
53 {
54 struct nextfield *next;
55 int visibility;
56 struct field field;
57 } *list;
58 struct next_fnfieldlist
59 {
60 struct next_fnfieldlist *next;
61 struct fn_fieldlist fn_fieldlist;
62 } *fnlist;
63 };
64
65 static struct type *
66 dbx_alloc_type PARAMS ((int [2], struct objfile *));
67
68 static void
69 read_huge_number PARAMS ((char **, int, long *, int *));
70
71 static void
72 patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
73 struct objfile *));
74
75 static void
76 fix_common_block PARAMS ((struct symbol *, int));
77
78 static struct type *
79 read_range_type PARAMS ((char **, int [2], struct objfile *));
80
81 static struct type *
82 read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *));
83
84 static struct type *
85 read_sun_floating_type PARAMS ((char **, int [2], struct objfile *));
86
87 static struct type *
88 read_enum_type PARAMS ((char **, struct type *, struct objfile *));
89
90 static struct type *
91 rs6000_builtin_type PARAMS ((char **pp));
92
93 static int
94 read_member_functions PARAMS ((struct field_info *, char **, struct type *,
95 struct objfile *));
96
97 static int
98 read_struct_fields PARAMS ((struct field_info *, char **, struct type *,
99 struct objfile *));
100
101 static int
102 read_baseclasses PARAMS ((struct field_info *, char **, struct type *,
103 struct objfile *));
104
105 static int
106 read_tilde_fields PARAMS ((struct field_info *, char **, struct type *,
107 struct objfile *));
108
109 static int
110 attach_fn_fields_to_type PARAMS ((struct field_info *, struct type *));
111
112 static int
113 attach_fields_to_type PARAMS ((struct field_info *, struct type *,
114 struct objfile *));
115
116 static struct type *
117 read_struct_type PARAMS ((char **, struct type *, struct objfile *));
118
119 static struct type *
120 read_array_type PARAMS ((char **, struct type *, struct objfile *));
121
122 static struct type **
123 read_args PARAMS ((char **, int, struct objfile *));
124
125 static void
126 read_cpp_abbrev PARAMS ((struct field_info *, char **, struct type *,
127 struct objfile *));
128
129 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
130 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
131
132 /* Define this as 1 if a pcc declaration of a char or short argument
133 gives the correct address. Otherwise assume pcc gives the
134 address of the corresponding int, which is not the same on a
135 big-endian machine. */
136
137 #ifndef BELIEVE_PCC_PROMOTION
138 #define BELIEVE_PCC_PROMOTION 0
139 #endif
140
141 /* During some calls to read_type (and thus to read_range_type), this
142 contains the name of the type being defined. Range types are only
143 used in C as basic types. We use the name to distinguish the otherwise
144 identical basic types "int" and "long" and their unsigned versions.
145 FIXME, this should disappear with better type management. */
146
147 static char *long_kludge_name;
148
149 #if 0
150 struct complaint dbx_class_complaint =
151 {
152 "encountered DBX-style class variable debugging information.\n\
153 You seem to have compiled your program with \
154 \"g++ -g0\" instead of \"g++ -g\".\n\
155 Therefore GDB will not know about your class variables", 0, 0
156 };
157 #endif
158
159 struct complaint invalid_cpp_abbrev_complaint =
160 {"invalid C++ abbreviation `%s'", 0, 0};
161
162 struct complaint invalid_cpp_type_complaint =
163 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
164
165 struct complaint member_fn_complaint =
166 {"member function type missing, got '%c'", 0, 0};
167
168 struct complaint const_vol_complaint =
169 {"const/volatile indicator missing, got '%c'", 0, 0};
170
171 struct complaint error_type_complaint =
172 {"debug info mismatch between compiler and debugger", 0, 0};
173
174 struct complaint invalid_member_complaint =
175 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
176
177 struct complaint range_type_base_complaint =
178 {"base type %d of range type is not defined", 0, 0};
179
180 struct complaint reg_value_complaint =
181 {"register number too large in symbol %s", 0, 0};
182
183 struct complaint vtbl_notfound_complaint =
184 {"virtual function table pointer not found when defining class `%s'", 0, 0};
185
186 struct complaint unrecognized_cplus_name_complaint =
187 {"Unknown C++ symbol name `%s'", 0, 0};
188
189 struct complaint rs6000_builtin_complaint =
190 {"Unknown builtin type -%d", 0, 0};
191
192 struct complaint stabs_general_complaint =
193 {"%s", 0, 0};
194
195 /* Make a list of forward references which haven't been defined. */
196
197 static struct type **undef_types;
198 static int undef_types_allocated;
199 static int undef_types_length;
200
201 /* Check for and handle cretinous stabs symbol name continuation! */
202 #define STABS_CONTINUE(pp) \
203 do { \
204 if (**(pp) == '\\') *(pp) = next_symbol_text (); \
205 } while (0)
206
207 \f
208 int
209 hashname (name)
210 char *name;
211 {
212 register char *p = name;
213 register int total = p[0];
214 register int c;
215
216 c = p[1];
217 total += c << 2;
218 if (c)
219 {
220 c = p[2];
221 total += c << 4;
222 if (c)
223 {
224 total += p[3] << 6;
225 }
226 }
227
228 /* Ensure result is positive. */
229 if (total < 0)
230 {
231 total += (1000 << 6);
232 }
233 return (total % HASHSIZE);
234 }
235
236 \f
237 /* Look up a dbx type-number pair. Return the address of the slot
238 where the type for that number-pair is stored.
239 The number-pair is in TYPENUMS.
240
241 This can be used for finding the type associated with that pair
242 or for associating a new type with the pair. */
243
244 struct type **
245 dbx_lookup_type (typenums)
246 int typenums[2];
247 {
248 register int filenum = typenums[0];
249 register int index = typenums[1];
250 unsigned old_len;
251 register int real_filenum;
252 register struct header_file *f;
253 int f_orig_length;
254
255 if (filenum == -1) /* -1,-1 is for temporary types. */
256 return 0;
257
258 if (filenum < 0 || filenum >= n_this_object_header_files)
259 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
260 filenum, index, symnum);
261
262 if (filenum == 0)
263 {
264 /* Type is defined outside of header files.
265 Find it in this object file's type vector. */
266 if (index >= type_vector_length)
267 {
268 old_len = type_vector_length;
269 if (old_len == 0)
270 {
271 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
272 type_vector = (struct type **)
273 malloc (type_vector_length * sizeof (struct type *));
274 }
275 while (index >= type_vector_length)
276 {
277 type_vector_length *= 2;
278 }
279 type_vector = (struct type **)
280 xrealloc ((char *) type_vector,
281 (type_vector_length * sizeof (struct type *)));
282 memset (&type_vector[old_len], 0,
283 (type_vector_length - old_len) * sizeof (struct type *));
284 }
285 return (&type_vector[index]);
286 }
287 else
288 {
289 real_filenum = this_object_header_files[filenum];
290
291 if (real_filenum >= n_header_files)
292 {
293 abort ();
294 }
295
296 f = &header_files[real_filenum];
297
298 f_orig_length = f->length;
299 if (index >= f_orig_length)
300 {
301 while (index >= f->length)
302 {
303 f->length *= 2;
304 }
305 f->vector = (struct type **)
306 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
307 memset (&f->vector[f_orig_length], 0,
308 (f->length - f_orig_length) * sizeof (struct type *));
309 }
310 return (&f->vector[index]);
311 }
312 }
313
314 /* Make sure there is a type allocated for type numbers TYPENUMS
315 and return the type object.
316 This can create an empty (zeroed) type object.
317 TYPENUMS may be (-1, -1) to return a new type object that is not
318 put into the type vector, and so may not be referred to by number. */
319
320 static struct type *
321 dbx_alloc_type (typenums, objfile)
322 int typenums[2];
323 struct objfile *objfile;
324 {
325 register struct type **type_addr;
326
327 if (typenums[0] == -1)
328 {
329 return (alloc_type (objfile));
330 }
331
332 type_addr = dbx_lookup_type (typenums);
333
334 /* If we are referring to a type not known at all yet,
335 allocate an empty type for it.
336 We will fill it in later if we find out how. */
337 if (*type_addr == 0)
338 {
339 *type_addr = alloc_type (objfile);
340 }
341
342 return (*type_addr);
343 }
344
345 /* for all the stabs in a given stab vector, build appropriate types
346 and fix their symbols in given symbol vector. */
347
348 static void
349 patch_block_stabs (symbols, stabs, objfile)
350 struct pending *symbols;
351 struct pending_stabs *stabs;
352 struct objfile *objfile;
353 {
354 int ii;
355 char *name;
356 char *pp;
357 struct symbol *sym;
358
359 if (stabs)
360 {
361
362 /* for all the stab entries, find their corresponding symbols and
363 patch their types! */
364
365 for (ii = 0; ii < stabs->count; ++ii)
366 {
367 name = stabs->stab[ii];
368 pp = (char*) strchr (name, ':');
369 sym = find_symbol_in_list (symbols, name, pp-name);
370 if (!sym)
371 {
372 #ifndef IBM6000_TARGET
373 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
374 #endif
375 }
376 else
377 {
378 pp += 2;
379 if (*(pp-1) == 'F' || *(pp-1) == 'f')
380 {
381 SYMBOL_TYPE (sym) =
382 lookup_function_type (read_type (&pp, objfile));
383 }
384 else
385 {
386 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
387 }
388 }
389 }
390 }
391 }
392
393 \f
394 /* Read a number by which a type is referred to in dbx data,
395 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
396 Just a single number N is equivalent to (0,N).
397 Return the two numbers by storing them in the vector TYPENUMS.
398 TYPENUMS will then be used as an argument to dbx_lookup_type. */
399
400 void
401 read_type_number (pp, typenums)
402 register char **pp;
403 register int *typenums;
404 {
405 if (**pp == '(')
406 {
407 (*pp)++;
408 typenums[0] = read_number (pp, ',');
409 typenums[1] = read_number (pp, ')');
410 }
411 else
412 {
413 typenums[0] = 0;
414 typenums[1] = read_number (pp, 0);
415 }
416 }
417
418 \f
419 /* To handle GNU C++ typename abbreviation, we need to be able to
420 fill in a type's name as soon as space for that type is allocated.
421 `type_synonym_name' is the name of the type being allocated.
422 It is cleared as soon as it is used (lest all allocated types
423 get this name). */
424
425 static char *type_synonym_name;
426
427 /* ARGSUSED */
428 struct symbol *
429 define_symbol (valu, string, desc, type, objfile)
430 unsigned int valu;
431 char *string;
432 int desc;
433 int type;
434 struct objfile *objfile;
435 {
436 register struct symbol *sym;
437 char *p = (char *) strchr (string, ':');
438 int deftype;
439 int synonym = 0;
440 register int i;
441 struct type *temptype;
442
443 /* We would like to eliminate nameless symbols, but keep their types.
444 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
445 to type 2, but, should not create a symbol to address that type. Since
446 the symbol will be nameless, there is no way any user can refer to it. */
447
448 int nameless;
449
450 /* Ignore syms with empty names. */
451 if (string[0] == 0)
452 return 0;
453
454 /* Ignore old-style symbols from cc -go */
455 if (p == 0)
456 return 0;
457
458 /* If a nameless stab entry, all we need is the type, not the symbol.
459 e.g. ":t10=*2" or a nameless enum like " :T16=ered:0,green:1,blue:2,;" */
460 nameless = (p == string || ((string[0] == ' ') && (string[1] == ':')));
461
462 sym = (struct symbol *)
463 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
464 memset (sym, 0, sizeof (struct symbol));
465
466 if (processing_gcc_compilation)
467 {
468 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
469 number of bytes occupied by a type or object, which we ignore. */
470 SYMBOL_LINE(sym) = desc;
471 }
472 else
473 {
474 SYMBOL_LINE(sym) = 0; /* unknown */
475 }
476
477 if (string[0] == CPLUS_MARKER)
478 {
479 /* Special GNU C++ names. */
480 switch (string[1])
481 {
482 case 't':
483 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
484 &objfile -> symbol_obstack);
485 break;
486
487 case 'v': /* $vtbl_ptr_type */
488 /* Was: SYMBOL_NAME (sym) = "vptr"; */
489 goto normal;
490
491 case 'e':
492 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
493 &objfile -> symbol_obstack);
494 break;
495
496 case '_':
497 /* This was an anonymous type that was never fixed up. */
498 goto normal;
499
500 default:
501 complain (unrecognized_cplus_name_complaint, string);
502 goto normal; /* Do *something* with it */
503 }
504 }
505 else
506 {
507 normal:
508 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
509 SYMBOL_NAME (sym) = (char *)
510 obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
511 /* Open-coded bcopy--saves function call time. */
512 /* FIXME: Does it really? Try replacing with simple strcpy and
513 try it on an executable with a large symbol table. */
514 {
515 register char *p1 = string;
516 register char *p2 = SYMBOL_NAME (sym);
517 while (p1 != p)
518 {
519 *p2++ = *p1++;
520 }
521 *p2++ = '\0';
522 }
523
524 /* If this symbol is from a C++ compilation, then attempt to cache the
525 demangled form for future reference. This is a typical time versus
526 space tradeoff, that was decided in favor of time because it sped up
527 C++ symbol lookups by a factor of about 20. */
528
529 SYMBOL_INIT_DEMANGLED_NAME (sym, &objfile->symbol_obstack);
530 }
531 p++;
532
533 /* Determine the type of name being defined. */
534 /* The Acorn RISC machine's compiler can put out locals that don't
535 start with "234=" or "(3,4)=", so assume anything other than the
536 deftypes we know how to handle is a local. */
537 if (!strchr ("cfFGpPrStTvVXCR", *p))
538 deftype = 'l';
539 else
540 deftype = *p++;
541
542 /* c is a special case, not followed by a type-number.
543 SYMBOL:c=iVALUE for an integer constant symbol.
544 SYMBOL:c=rVALUE for a floating constant symbol.
545 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
546 e.g. "b:c=e6,0" for "const b = blob1"
547 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
548 if (deftype == 'c')
549 {
550 if (*p++ != '=')
551 error ("Invalid symbol data at symtab pos %d.", symnum);
552 switch (*p++)
553 {
554 case 'r':
555 {
556 double d = atof (p);
557 char *dbl_valu;
558
559 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
560 FT_DBL_PREC_FLOAT);
561 dbl_valu = (char *)
562 obstack_alloc (&objfile -> symbol_obstack, sizeof (double));
563 memcpy (dbl_valu, &d, sizeof (double));
564 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
565 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
566 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
567 }
568 break;
569 case 'i':
570 {
571 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
572 FT_INTEGER);
573 SYMBOL_VALUE (sym) = atoi (p);
574 SYMBOL_CLASS (sym) = LOC_CONST;
575 }
576 break;
577 case 'e':
578 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
579 e.g. "b:c=e6,0" for "const b = blob1"
580 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
581 {
582 int typenums[2];
583
584 read_type_number (&p, typenums);
585 if (*p++ != ',')
586 error ("Invalid symbol data: no comma in enum const symbol");
587
588 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
589 SYMBOL_VALUE (sym) = atoi (p);
590 SYMBOL_CLASS (sym) = LOC_CONST;
591 }
592 break;
593 default:
594 error ("Invalid symbol data at symtab pos %d.", symnum);
595 }
596 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
597 add_symbol_to_list (sym, &file_symbols);
598 return sym;
599 }
600
601 /* Now usually comes a number that says which data type,
602 and possibly more stuff to define the type
603 (all of which is handled by read_type) */
604
605 if (deftype == 'p' && *p == 'F')
606 /* pF is a two-letter code that means a function parameter in Fortran.
607 The type-number specifies the type of the return value.
608 Translate it into a pointer-to-function type. */
609 {
610 p++;
611 SYMBOL_TYPE (sym)
612 = lookup_pointer_type (lookup_function_type (read_type (&p, objfile)));
613 }
614 else
615 {
616 /* The symbol class letter is followed by a type (typically the
617 type of the symbol, or its return-type, or etc). Read it. */
618
619 synonym = *p == 't';
620
621 if (synonym)
622 {
623 p++;
624 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
625 strlen (SYMBOL_NAME (sym)),
626 &objfile -> symbol_obstack);
627 }
628
629 /* Here we save the name of the symbol for read_range_type, which
630 ends up reading in the basic types. In stabs, unfortunately there
631 is no distinction between "int" and "long" types except their
632 names. Until we work out a saner type policy (eliminating most
633 builtin types and using the names specified in the files), we
634 save away the name so that far away from here in read_range_type,
635 we can examine it to decide between "int" and "long". FIXME. */
636 long_kludge_name = SYMBOL_NAME (sym);
637
638 SYMBOL_TYPE (sym) = read_type (&p, objfile);
639 }
640
641 switch (deftype)
642 {
643 case 'C':
644 /* The name of a caught exception. */
645 SYMBOL_CLASS (sym) = LOC_LABEL;
646 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
647 SYMBOL_VALUE_ADDRESS (sym) = valu;
648 add_symbol_to_list (sym, &local_symbols);
649 break;
650
651 case 'f':
652 /* A static function definition. */
653 SYMBOL_CLASS (sym) = LOC_BLOCK;
654 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
655 add_symbol_to_list (sym, &file_symbols);
656 /* fall into process_function_types. */
657
658 process_function_types:
659 /* Function result types are described as the result type in stabs.
660 We need to convert this to the function-returning-type-X type
661 in GDB. E.g. "int" is converted to "function returning int". */
662 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
663 {
664 #if 0
665 /* This code doesn't work -- it needs to realloc and can't. */
666 /* Attempt to set up to record a function prototype... */
667 struct type *new = alloc_type (objfile);
668
669 /* Generate a template for the type of this function. The
670 types of the arguments will be added as we read the symbol
671 table. */
672 *new = *lookup_function_type (SYMBOL_TYPE(sym));
673 SYMBOL_TYPE(sym) = new;
674 TYPE_OBJFILE (new) = objfile;
675 in_function_type = new;
676 #else
677 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
678 #endif
679 }
680 /* fall into process_prototype_types */
681
682 process_prototype_types:
683 /* Sun acc puts declared types of arguments here. We don't care
684 about their actual types (FIXME -- we should remember the whole
685 function prototype), but the list may define some new types
686 that we have to remember, so we must scan it now. */
687 while (*p == ';') {
688 p++;
689 read_type (&p, objfile);
690 }
691 break;
692
693 case 'F':
694 /* A global function definition. */
695 SYMBOL_CLASS (sym) = LOC_BLOCK;
696 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
697 add_symbol_to_list (sym, &global_symbols);
698 goto process_function_types;
699
700 case 'G':
701 /* For a class G (global) symbol, it appears that the
702 value is not correct. It is necessary to search for the
703 corresponding linker definition to find the value.
704 These definitions appear at the end of the namelist. */
705 i = hashname (SYMBOL_NAME (sym));
706 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
707 global_sym_chain[i] = sym;
708 SYMBOL_CLASS (sym) = LOC_STATIC;
709 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
710 add_symbol_to_list (sym, &global_symbols);
711 break;
712
713 /* This case is faked by a conditional above,
714 when there is no code letter in the dbx data.
715 Dbx data never actually contains 'l'. */
716 case 'l':
717 SYMBOL_CLASS (sym) = LOC_LOCAL;
718 SYMBOL_VALUE (sym) = valu;
719 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
720 add_symbol_to_list (sym, &local_symbols);
721 break;
722
723 case 'p':
724 /* Normally this is a parameter, a LOC_ARG. On the i960, it
725 can also be a LOC_LOCAL_ARG depending on symbol type. */
726 #ifndef DBX_PARM_SYMBOL_CLASS
727 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
728 #endif
729 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
730 SYMBOL_VALUE (sym) = valu;
731 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
732 #if 0
733 /* This doesn't work yet. */
734 add_param_to_type (&in_function_type, sym);
735 #endif
736 add_symbol_to_list (sym, &local_symbols);
737
738 /* If it's gcc-compiled, if it says `short', believe it. */
739 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
740 break;
741
742 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
743 /* This macro is defined on machines (e.g. sparc) where
744 we should believe the type of a PCC 'short' argument,
745 but shouldn't believe the address (the address is
746 the address of the corresponding int). Note that
747 this is only different from the BELIEVE_PCC_PROMOTION
748 case on big-endian machines.
749
750 My guess is that this correction, as opposed to changing
751 the parameter to an 'int' (as done below, for PCC
752 on most machines), is the right thing to do
753 on all machines, but I don't want to risk breaking
754 something that already works. On most PCC machines,
755 the sparc problem doesn't come up because the calling
756 function has to zero the top bytes (not knowing whether
757 the called function wants an int or a short), so there
758 is no practical difference between an int and a short
759 (except perhaps what happens when the GDB user types
760 "print short_arg = 0x10000;").
761
762 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
763 actually produces the correct address (we don't need to fix it
764 up). I made this code adapt so that it will offset the symbol
765 if it was pointing at an int-aligned location and not
766 otherwise. This way you can use the same gdb for 4.0.x and
767 4.1 systems.
768
769 If the parameter is shorter than an int, and is integral
770 (e.g. char, short, or unsigned equivalent), and is claimed to
771 be passed on an integer boundary, don't believe it! Offset the
772 parameter's address to the tail-end of that integer. */
773
774 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
775 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
776 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
777 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
778 {
779 SYMBOL_VALUE (sym) += TYPE_LENGTH (temptype)
780 - TYPE_LENGTH (SYMBOL_TYPE (sym));
781 }
782 break;
783
784 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
785
786 /* If PCC says a parameter is a short or a char,
787 it is really an int. */
788 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
789 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
790 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
791 {
792 SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym))
793 ? lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER)
794 : temptype;
795 }
796 break;
797
798 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
799
800 case 'P':
801 /* acc seems to use P to delare the prototypes of functions that
802 are referenced by this file. gdb is not prepared to deal
803 with this extra information. FIXME, it ought to. */
804 if (type == N_FUN)
805 goto process_prototype_types;
806
807 /* Parameter which is in a register. */
808 SYMBOL_CLASS (sym) = LOC_REGPARM;
809 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
810 if (SYMBOL_VALUE (sym) >= NUM_REGS)
811 {
812 complain (&reg_value_complaint, SYMBOL_SOURCE_NAME (sym));
813 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
814 }
815 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
816 add_symbol_to_list (sym, &local_symbols);
817 break;
818
819 case 'R':
820 case 'r':
821 /* Register variable (either global or local). */
822 SYMBOL_CLASS (sym) = LOC_REGISTER;
823 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
824 if (SYMBOL_VALUE (sym) >= NUM_REGS)
825 {
826 complain (&reg_value_complaint, SYMBOL_SOURCE_NAME (sym));
827 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
828 }
829 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
830 if (within_function)
831 add_symbol_to_list (sym, &local_symbols);
832 else
833 add_symbol_to_list (sym, &file_symbols);
834 break;
835
836 case 'S':
837 /* Static symbol at top level of file */
838 SYMBOL_CLASS (sym) = LOC_STATIC;
839 SYMBOL_VALUE_ADDRESS (sym) = valu;
840 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
841 add_symbol_to_list (sym, &file_symbols);
842 break;
843
844 case 't':
845 /* For a nameless type, we don't want a create a symbol, thus we
846 did not use `sym'. Return without further processing. */
847 if (nameless) return NULL;
848
849 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
850 SYMBOL_VALUE (sym) = valu;
851 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
852 /* C++ vagaries: we may have a type which is derived from
853 a base type which did not have its name defined when the
854 derived class was output. We fill in the derived class's
855 base part member's name here in that case. */
856 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
857 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
858 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
859 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
860 {
861 int j;
862 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
863 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
864 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
865 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
866 }
867
868 add_symbol_to_list (sym, &file_symbols);
869 break;
870
871 case 'T':
872 /* For a nameless type, we don't want a create a symbol, thus we
873 did not use `sym'. Return without further processing. */
874 if (nameless) return NULL;
875
876 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
877 SYMBOL_VALUE (sym) = valu;
878 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
879 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
880 TYPE_NAME (SYMBOL_TYPE (sym))
881 = obconcat (&objfile -> type_obstack, "",
882 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
883 ? "enum "
884 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
885 ? "struct " : "union ")),
886 SYMBOL_NAME (sym));
887 add_symbol_to_list (sym, &file_symbols);
888
889 if (synonym)
890 {
891 /* Clone the sym and then modify it. */
892 register struct symbol *typedef_sym = (struct symbol *)
893 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
894 *typedef_sym = *sym;
895 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
896 SYMBOL_VALUE (typedef_sym) = valu;
897 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
898 add_symbol_to_list (typedef_sym, &file_symbols);
899 }
900 break;
901
902 case 'V':
903 /* Static symbol of local scope */
904 SYMBOL_CLASS (sym) = LOC_STATIC;
905 SYMBOL_VALUE_ADDRESS (sym) = valu;
906 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
907 add_symbol_to_list (sym, &local_symbols);
908 break;
909
910 case 'v':
911 /* Reference parameter */
912 SYMBOL_CLASS (sym) = LOC_REF_ARG;
913 SYMBOL_VALUE (sym) = valu;
914 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
915 add_symbol_to_list (sym, &local_symbols);
916 break;
917
918 case 'X':
919 /* This is used by Sun FORTRAN for "function result value".
920 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
921 that Pascal uses it too, but when I tried it Pascal used
922 "x:3" (local symbol) instead. */
923 SYMBOL_CLASS (sym) = LOC_LOCAL;
924 SYMBOL_VALUE (sym) = valu;
925 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
926 add_symbol_to_list (sym, &local_symbols);
927 break;
928
929 default:
930 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
931 }
932 return sym;
933 }
934
935 \f
936 /* Skip rest of this symbol and return an error type.
937
938 General notes on error recovery: error_type always skips to the
939 end of the symbol (modulo cretinous dbx symbol name continuation).
940 Thus code like this:
941
942 if (*(*pp)++ != ';')
943 return error_type (pp);
944
945 is wrong because if *pp starts out pointing at '\0' (typically as the
946 result of an earlier error), it will be incremented to point to the
947 start of the next symbol, which might produce strange results, at least
948 if you run off the end of the string table. Instead use
949
950 if (**pp != ';')
951 return error_type (pp);
952 ++*pp;
953
954 or
955
956 if (**pp != ';')
957 foo = error_type (pp);
958 else
959 ++*pp;
960
961 And in case it isn't obvious, the point of all this hair is so the compiler
962 can define new types and new syntaxes, and old versions of the
963 debugger will be able to read the new symbol tables. */
964
965 struct type *
966 error_type (pp)
967 char **pp;
968 {
969 complain (&error_type_complaint);
970 while (1)
971 {
972 /* Skip to end of symbol. */
973 while (**pp != '\0')
974 {
975 (*pp)++;
976 }
977
978 /* Check for and handle cretinous dbx symbol name continuation! */
979 if ((*pp)[-1] == '\\')
980 {
981 *pp = next_symbol_text ();
982 }
983 else
984 {
985 break;
986 }
987 }
988 return (builtin_type_error);
989 }
990
991 \f
992 /* Read a dbx type reference or definition;
993 return the type that is meant.
994 This can be just a number, in which case it references
995 a type already defined and placed in type_vector.
996 Or the number can be followed by an =, in which case
997 it means to define a new type according to the text that
998 follows the =. */
999
1000 struct type *
1001 read_type (pp, objfile)
1002 register char **pp;
1003 struct objfile *objfile;
1004 {
1005 register struct type *type = 0;
1006 struct type *type1;
1007 int typenums[2];
1008 int xtypenums[2];
1009 char type_descriptor;
1010
1011 /* Read type number if present. The type number may be omitted.
1012 for instance in a two-dimensional array declared with type
1013 "ar1;1;10;ar1;1;10;4". */
1014 if ((**pp >= '0' && **pp <= '9')
1015 || **pp == '(')
1016 {
1017 read_type_number (pp, typenums);
1018
1019 /* Type is not being defined here. Either it already exists,
1020 or this is a forward reference to it. dbx_alloc_type handles
1021 both cases. */
1022 if (**pp != '=')
1023 return dbx_alloc_type (typenums, objfile);
1024
1025 /* Type is being defined here. */
1026 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1027 {
1028 struct type *tt;
1029
1030 /* if such a type already exists, this is an unnecessary duplication
1031 of the stab string, which is common in (RS/6000) xlc generated
1032 objects. In that case, simply return NULL and let the caller take
1033 care of it. */
1034
1035 tt = *dbx_lookup_type (typenums);
1036 if (tt && tt->length && tt->code)
1037 return NULL;
1038 }
1039 #endif
1040
1041 *pp += 2;
1042 }
1043 else
1044 {
1045 /* 'typenums=' not present, type is anonymous. Read and return
1046 the definition, but don't put it in the type vector. */
1047 typenums[0] = typenums[1] = -1;
1048 (*pp)++;
1049 }
1050
1051 type_descriptor = (*pp)[-1];
1052 switch (type_descriptor)
1053 {
1054 case 'x':
1055 {
1056 enum type_code code;
1057
1058 /* Used to index through file_symbols. */
1059 struct pending *ppt;
1060 int i;
1061
1062 /* Name including "struct", etc. */
1063 char *type_name;
1064
1065 /* Name without "struct", etc. */
1066 char *type_name_only;
1067
1068 {
1069 char *prefix;
1070 char *from, *to;
1071
1072 /* Set the type code according to the following letter. */
1073 switch ((*pp)[0])
1074 {
1075 case 's':
1076 code = TYPE_CODE_STRUCT;
1077 prefix = "struct ";
1078 break;
1079 case 'u':
1080 code = TYPE_CODE_UNION;
1081 prefix = "union ";
1082 break;
1083 case 'e':
1084 code = TYPE_CODE_ENUM;
1085 prefix = "enum ";
1086 break;
1087 default:
1088 return error_type (pp);
1089 }
1090
1091 to = type_name = (char *)
1092 obstack_alloc (&objfile -> type_obstack,
1093 (strlen (prefix) +
1094 ((char *) strchr (*pp, ':') - (*pp)) + 1));
1095
1096 /* Copy the prefix. */
1097 from = prefix;
1098 while ((*to++ = *from++) != '\0')
1099 ;
1100 to--;
1101
1102 type_name_only = to;
1103
1104 /* Copy the name. */
1105 from = *pp + 1;
1106 while ((*to++ = *from++) != ':')
1107 ;
1108 *--to = '\0';
1109
1110 /* Set the pointer ahead of the name which we just read. */
1111 *pp = from;
1112
1113 #if 0
1114 /* The following hack is clearly wrong, because it doesn't
1115 check whether we are in a baseclass. I tried to reproduce
1116 the case that it is trying to fix, but I couldn't get
1117 g++ to put out a cross reference to a basetype. Perhaps
1118 it doesn't do it anymore. */
1119 /* Note: for C++, the cross reference may be to a base type which
1120 has not yet been seen. In this case, we skip to the comma,
1121 which will mark the end of the base class name. (The ':'
1122 at the end of the base class name will be skipped as well.)
1123 But sometimes (ie. when the cross ref is the last thing on
1124 the line) there will be no ','. */
1125 from = (char *) strchr (*pp, ',');
1126 if (from)
1127 *pp = from;
1128 #endif /* 0 */
1129 }
1130
1131 /* Now check to see whether the type has already been declared. */
1132 /* This is necessary at least in the case where the
1133 program says something like
1134 struct foo bar[5];
1135 The compiler puts out a cross-reference; we better find
1136 set the length of the structure correctly so we can
1137 set the length of the array. */
1138 for (ppt = file_symbols; ppt; ppt = ppt->next)
1139 for (i = 0; i < ppt->nsyms; i++)
1140 {
1141 struct symbol *sym = ppt->symbol[i];
1142
1143 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1144 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1145 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1146 && STREQ (SYMBOL_NAME (sym), type_name_only))
1147 {
1148 obstack_free (&objfile -> type_obstack, type_name);
1149 type = SYMBOL_TYPE (sym);
1150 return type;
1151 }
1152 }
1153
1154 /* Didn't find the type to which this refers, so we must
1155 be dealing with a forward reference. Allocate a type
1156 structure for it, and keep track of it so we can
1157 fill in the rest of the fields when we get the full
1158 type. */
1159 type = dbx_alloc_type (typenums, objfile);
1160 TYPE_CODE (type) = code;
1161 TYPE_NAME (type) = type_name;
1162 INIT_CPLUS_SPECIFIC(type);
1163 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1164
1165 add_undefined_type (type);
1166 return type;
1167 }
1168
1169 case '-': /* RS/6000 built-in type */
1170 type = rs6000_builtin_type (pp);
1171 goto after_digits;
1172
1173 case '0':
1174 case '1':
1175 case '2':
1176 case '3':
1177 case '4':
1178 case '5':
1179 case '6':
1180 case '7':
1181 case '8':
1182 case '9':
1183 case '(':
1184 (*pp)--;
1185 read_type_number (pp, xtypenums);
1186 type = *dbx_lookup_type (xtypenums);
1187 /* fall through */
1188
1189 after_digits:
1190 if (type == 0)
1191 type = lookup_fundamental_type (objfile, FT_VOID);
1192 if (typenums[0] != -1)
1193 *dbx_lookup_type (typenums) = type;
1194 break;
1195
1196 /* In the following types, we must be sure to overwrite any existing
1197 type that the typenums refer to, rather than allocating a new one
1198 and making the typenums point to the new one. This is because there
1199 may already be pointers to the existing type (if it had been
1200 forward-referenced), and we must change it to a pointer, function,
1201 reference, or whatever, *in-place*. */
1202
1203 case '*':
1204 type1 = read_type (pp, objfile);
1205 type = make_pointer_type (type1, dbx_lookup_type (typenums));
1206 break;
1207
1208 case '&': /* Reference to another type */
1209 type1 = read_type (pp, objfile);
1210 type = make_reference_type (type1, dbx_lookup_type (typenums));
1211 break;
1212
1213 case 'f': /* Function returning another type */
1214 type1 = read_type (pp, objfile);
1215 type = make_function_type (type1, dbx_lookup_type (typenums));
1216 break;
1217
1218 case 'k': /* Const qualifier on some type (Sun) */
1219 type = read_type (pp, objfile);
1220 /* FIXME! For now, we ignore const and volatile qualifiers. */
1221 break;
1222
1223 case 'B': /* Volatile qual on some type (Sun) */
1224 type = read_type (pp, objfile);
1225 /* FIXME! For now, we ignore const and volatile qualifiers. */
1226 break;
1227
1228 /* FIXME -- we should be doing smash_to_XXX types here. */
1229 case '@': /* Member (class & variable) type */
1230 {
1231 struct type *domain = read_type (pp, objfile);
1232 struct type *memtype;
1233
1234 if (**pp != ',')
1235 /* Invalid member type data format. */
1236 return error_type (pp);
1237 ++*pp;
1238
1239 memtype = read_type (pp, objfile);
1240 type = dbx_alloc_type (typenums, objfile);
1241 smash_to_member_type (type, domain, memtype);
1242 }
1243 break;
1244
1245 case '#': /* Method (class & fn) type */
1246 if ((*pp)[0] == '#')
1247 {
1248 /* We'll get the parameter types from the name. */
1249 struct type *return_type;
1250
1251 (*pp)++;
1252 return_type = read_type (pp, objfile);
1253 if (*(*pp)++ != ';')
1254 complain (&invalid_member_complaint, symnum);
1255 type = allocate_stub_method (return_type);
1256 if (typenums[0] != -1)
1257 *dbx_lookup_type (typenums) = type;
1258 }
1259 else
1260 {
1261 struct type *domain = read_type (pp, objfile);
1262 struct type *return_type;
1263 struct type **args;
1264
1265 if (*(*pp)++ != ',')
1266 error ("invalid member type data format, at symtab pos %d.",
1267 symnum);
1268
1269 return_type = read_type (pp, objfile);
1270 args = read_args (pp, ';', objfile);
1271 type = dbx_alloc_type (typenums, objfile);
1272 smash_to_method_type (type, domain, return_type, args);
1273 }
1274 break;
1275
1276 case 'r': /* Range type */
1277 type = read_range_type (pp, typenums, objfile);
1278 if (typenums[0] != -1)
1279 *dbx_lookup_type (typenums) = type;
1280 break;
1281
1282 case 'b': /* Sun ACC builtin int type */
1283 type = read_sun_builtin_type (pp, typenums, objfile);
1284 if (typenums[0] != -1)
1285 *dbx_lookup_type (typenums) = type;
1286 break;
1287
1288 case 'R': /* Sun ACC builtin float type */
1289 type = read_sun_floating_type (pp, typenums, objfile);
1290 if (typenums[0] != -1)
1291 *dbx_lookup_type (typenums) = type;
1292 break;
1293
1294 case 'e': /* Enumeration type */
1295 type = dbx_alloc_type (typenums, objfile);
1296 type = read_enum_type (pp, type, objfile);
1297 *dbx_lookup_type (typenums) = type;
1298 break;
1299
1300 case 's': /* Struct type */
1301 case 'u': /* Union type */
1302 type = dbx_alloc_type (typenums, objfile);
1303 if (!TYPE_NAME (type))
1304 {
1305 TYPE_NAME (type) = type_synonym_name;
1306 }
1307 type_synonym_name = NULL;
1308 switch (type_descriptor)
1309 {
1310 case 's':
1311 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1312 break;
1313 case 'u':
1314 TYPE_CODE (type) = TYPE_CODE_UNION;
1315 break;
1316 }
1317 type = read_struct_type (pp, type, objfile);
1318 break;
1319
1320 case 'a': /* Array type */
1321 if (**pp != 'r')
1322 return error_type (pp);
1323 ++*pp;
1324
1325 type = dbx_alloc_type (typenums, objfile);
1326 type = read_array_type (pp, type, objfile);
1327 break;
1328
1329 default:
1330 --*pp; /* Go back to the symbol in error */
1331 /* Particularly important if it was \0! */
1332 return error_type (pp);
1333 }
1334
1335 if (type == 0)
1336 abort ();
1337
1338 return type;
1339 }
1340 \f
1341 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1342 Return the proper type node for a given builtin type number. */
1343
1344 static struct type *
1345 rs6000_builtin_type (pp)
1346 char **pp;
1347 {
1348 int typenums[2];
1349
1350 read_type_number (pp, typenums);
1351
1352 /* default types are defined in dbxstclass.h. */
1353 switch ( typenums[1] ) {
1354 case 1:
1355 return lookup_fundamental_type (current_objfile, FT_INTEGER);
1356 case 2:
1357 return lookup_fundamental_type (current_objfile, FT_CHAR);
1358 case 3:
1359 return lookup_fundamental_type (current_objfile, FT_SHORT);
1360 case 4:
1361 return lookup_fundamental_type (current_objfile, FT_LONG);
1362 case 5:
1363 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_CHAR);
1364 case 6:
1365 return lookup_fundamental_type (current_objfile, FT_SIGNED_CHAR);
1366 case 7:
1367 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_SHORT);
1368 case 8:
1369 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
1370 case 9:
1371 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_INTEGER);
1372 case 10:
1373 return lookup_fundamental_type (current_objfile, FT_UNSIGNED_LONG);
1374 case 11:
1375 return lookup_fundamental_type (current_objfile, FT_VOID);
1376 case 12:
1377 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1378 case 13:
1379 return lookup_fundamental_type (current_objfile, FT_DBL_PREC_FLOAT);
1380 case 14:
1381 return lookup_fundamental_type (current_objfile, FT_EXT_PREC_FLOAT);
1382 case 15:
1383 /* requires a builtin `integer' */
1384 return lookup_fundamental_type (current_objfile, FT_INTEGER);
1385 case 16:
1386 return lookup_fundamental_type (current_objfile, FT_BOOLEAN);
1387 case 17:
1388 /* requires builtin `short real' */
1389 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1390 case 18:
1391 /* requires builtin `real' */
1392 return lookup_fundamental_type (current_objfile, FT_FLOAT);
1393 default:
1394 complain (rs6000_builtin_complaint, typenums[1]);
1395 return NULL;
1396 }
1397 }
1398 \f
1399 /* This page contains subroutines of read_type. */
1400
1401 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1402 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1403 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1404
1405 /* Read member function stabs info for C++ classes. The form of each member
1406 function data is:
1407
1408 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1409
1410 An example with two member functions is:
1411
1412 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1413
1414 For the case of overloaded operators, the format is op$::*.funcs, where
1415 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1416 name (such as `+=') and `.' marks the end of the operator name. */
1417
1418 static int
1419 read_member_functions (fip, pp, type, objfile)
1420 struct field_info *fip;
1421 char **pp;
1422 struct type *type;
1423 struct objfile *objfile;
1424 {
1425 int nfn_fields = 0;
1426 int length = 0;
1427 /* Total number of member functions defined in this class. If the class
1428 defines two `f' functions, and one `g' function, then this will have
1429 the value 3. */
1430 int total_length = 0;
1431 int i;
1432 struct next_fnfield
1433 {
1434 struct next_fnfield *next;
1435 struct fn_field fn_field;
1436 } *sublist;
1437 struct type *look_ahead_type;
1438 struct next_fnfieldlist *new_fnlist;
1439 struct next_fnfield *new_sublist;
1440 char *main_fn_name;
1441 register char *p;
1442
1443 /* Process each list until we find something that is not a member function
1444 or find the end of the functions. */
1445
1446 while (**pp != ';')
1447 {
1448 /* We should be positioned at the start of the function name.
1449 Scan forward to find the first ':' and if it is not the
1450 first of a "::" delimiter, then this is not a member function. */
1451 p = *pp;
1452 while (*p != ':')
1453 {
1454 p++;
1455 }
1456 if (p[1] != ':')
1457 {
1458 break;
1459 }
1460
1461 sublist = NULL;
1462 look_ahead_type = NULL;
1463 length = 0;
1464
1465 new_fnlist = (struct next_fnfieldlist *)
1466 xmalloc (sizeof (struct next_fnfieldlist));
1467 make_cleanup (free, new_fnlist);
1468 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
1469
1470 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
1471 {
1472 /* This is a completely wierd case. In order to stuff in the
1473 names that might contain colons (the usual name delimiter),
1474 Mike Tiemann defined a different name format which is
1475 signalled if the identifier is "op$". In that case, the
1476 format is "op$::XXXX." where XXXX is the name. This is
1477 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1478 /* This lets the user type "break operator+".
1479 We could just put in "+" as the name, but that wouldn't
1480 work for "*". */
1481 static char opname[32] = {'o', 'p', CPLUS_MARKER};
1482 char *o = opname + 3;
1483
1484 /* Skip past '::'. */
1485 *pp = p + 2;
1486
1487 STABS_CONTINUE (pp);
1488 p = *pp;
1489 while (*p != '.')
1490 {
1491 *o++ = *p++;
1492 }
1493 main_fn_name = savestring (opname, o - opname);
1494 /* Skip past '.' */
1495 *pp = p + 1;
1496 }
1497 else
1498 {
1499 main_fn_name = savestring (*pp, p - *pp);
1500 /* Skip past '::'. */
1501 *pp = p + 2;
1502 }
1503 new_fnlist -> fn_fieldlist.name = main_fn_name;
1504
1505 do
1506 {
1507 new_sublist =
1508 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
1509 make_cleanup (free, new_sublist);
1510 memset (new_sublist, 0, sizeof (struct next_fnfield));
1511
1512 /* Check for and handle cretinous dbx symbol name continuation! */
1513 if (look_ahead_type == NULL)
1514 {
1515 /* Normal case. */
1516 STABS_CONTINUE (pp);
1517
1518 new_sublist -> fn_field.type = read_type (pp, objfile);
1519 if (**pp != ':')
1520 {
1521 /* Invalid symtab info for member function. */
1522 return 0;
1523 }
1524 }
1525 else
1526 {
1527 /* g++ version 1 kludge */
1528 new_sublist -> fn_field.type = look_ahead_type;
1529 look_ahead_type = NULL;
1530 }
1531
1532 (*pp)++;
1533 p = *pp;
1534 while (*p != ';')
1535 {
1536 p++;
1537 }
1538
1539 /* If this is just a stub, then we don't have the real name here. */
1540
1541 if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB)
1542 {
1543 new_sublist -> fn_field.is_stub = 1;
1544 }
1545 new_sublist -> fn_field.physname = savestring (*pp, p - *pp);
1546 *pp = p + 1;
1547
1548 /* Set this member function's visibility fields. */
1549 switch (*(*pp)++)
1550 {
1551 case VISIBILITY_PRIVATE:
1552 new_sublist -> fn_field.is_private = 1;
1553 break;
1554 case VISIBILITY_PROTECTED:
1555 new_sublist -> fn_field.is_protected = 1;
1556 break;
1557 }
1558
1559 STABS_CONTINUE (pp);
1560 switch (**pp)
1561 {
1562 case 'A': /* Normal functions. */
1563 new_sublist -> fn_field.is_const = 0;
1564 new_sublist -> fn_field.is_volatile = 0;
1565 (*pp)++;
1566 break;
1567 case 'B': /* `const' member functions. */
1568 new_sublist -> fn_field.is_const = 1;
1569 new_sublist -> fn_field.is_volatile = 0;
1570 (*pp)++;
1571 break;
1572 case 'C': /* `volatile' member function. */
1573 new_sublist -> fn_field.is_const = 0;
1574 new_sublist -> fn_field.is_volatile = 1;
1575 (*pp)++;
1576 break;
1577 case 'D': /* `const volatile' member function. */
1578 new_sublist -> fn_field.is_const = 1;
1579 new_sublist -> fn_field.is_volatile = 1;
1580 (*pp)++;
1581 break;
1582 case '*': /* File compiled with g++ version 1 -- no info */
1583 case '?':
1584 case '.':
1585 break;
1586 default:
1587 complain (&const_vol_complaint, **pp);
1588 break;
1589 }
1590
1591 switch (*(*pp)++)
1592 {
1593 case '*':
1594 /* virtual member function, followed by index.
1595 The sign bit is set to distinguish pointers-to-methods
1596 from virtual function indicies. Since the array is
1597 in words, the quantity must be shifted left by 1
1598 on 16 bit machine, and by 2 on 32 bit machine, forcing
1599 the sign bit out, and usable as a valid index into
1600 the array. Remove the sign bit here. */
1601 new_sublist -> fn_field.voffset =
1602 (0x7fffffff & read_number (pp, ';')) + 2;
1603
1604 STABS_CONTINUE (pp);
1605 if (**pp == ';' || **pp == '\0')
1606 {
1607 /* Must be g++ version 1. */
1608 new_sublist -> fn_field.fcontext = 0;
1609 }
1610 else
1611 {
1612 /* Figure out from whence this virtual function came.
1613 It may belong to virtual function table of
1614 one of its baseclasses. */
1615 look_ahead_type = read_type (pp, objfile);
1616 if (**pp == ':')
1617 {
1618 /* g++ version 1 overloaded methods. */
1619 }
1620 else
1621 {
1622 new_sublist -> fn_field.fcontext = look_ahead_type;
1623 if (**pp != ';')
1624 {
1625 return 0;
1626 }
1627 else
1628 {
1629 ++*pp;
1630 }
1631 look_ahead_type = NULL;
1632 }
1633 }
1634 break;
1635
1636 case '?':
1637 /* static member function. */
1638 new_sublist -> fn_field.voffset = VOFFSET_STATIC;
1639 if (strncmp (new_sublist -> fn_field.physname,
1640 main_fn_name, strlen (main_fn_name)))
1641 {
1642 new_sublist -> fn_field.is_stub = 1;
1643 }
1644 break;
1645
1646 default:
1647 /* error */
1648 complain (&member_fn_complaint, (*pp)[-1]);
1649 /* Fall through into normal member function. */
1650
1651 case '.':
1652 /* normal member function. */
1653 new_sublist -> fn_field.voffset = 0;
1654 new_sublist -> fn_field.fcontext = 0;
1655 break;
1656 }
1657
1658 new_sublist -> next = sublist;
1659 sublist = new_sublist;
1660 length++;
1661 STABS_CONTINUE (pp);
1662 }
1663 while (**pp != ';' && **pp != '\0');
1664
1665 (*pp)++;
1666
1667 new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *)
1668 obstack_alloc (&objfile -> type_obstack,
1669 sizeof (struct fn_field) * length);
1670 memset (new_fnlist -> fn_fieldlist.fn_fields, 0,
1671 sizeof (struct fn_field) * length);
1672 for (i = length; (i--, sublist); sublist = sublist -> next)
1673 {
1674 new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field;
1675 }
1676
1677 new_fnlist -> fn_fieldlist.length = length;
1678 new_fnlist -> next = fip -> fnlist;
1679 fip -> fnlist = new_fnlist;
1680 nfn_fields++;
1681 total_length += length;
1682 STABS_CONTINUE (pp);
1683 }
1684
1685 if (nfn_fields)
1686 {
1687 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1688 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
1689 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
1690 memset (TYPE_FN_FIELDLISTS (type), 0,
1691 sizeof (struct fn_fieldlist) * nfn_fields);
1692 TYPE_NFN_FIELDS (type) = nfn_fields;
1693 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
1694 }
1695
1696 return 1;
1697 }
1698
1699 /* Special GNU C++ name.
1700 FIXME: Still need to properly handle parse error conditions. */
1701
1702 static void
1703 read_cpp_abbrev (fip, pp, type, objfile)
1704 struct field_info *fip;
1705 char **pp;
1706 struct type *type;
1707 struct objfile *objfile;
1708 {
1709 register char *p;
1710 const char *prefix;
1711 char *name;
1712 char cpp_abbrev;
1713 struct type *context;
1714
1715 p = *pp;
1716 if (*++p == 'v')
1717 {
1718 name = NULL;
1719 cpp_abbrev = *++p;
1720
1721 *pp = p + 1;
1722
1723 /* At this point, *pp points to something like "22:23=*22...",
1724 where the type number before the ':' is the "context" and
1725 everything after is a regular type definition. Lookup the
1726 type, find it's name, and construct the field name. */
1727
1728 context = read_type (pp, objfile);
1729
1730 switch (cpp_abbrev)
1731 {
1732 case 'f': /* $vf -- a virtual function table pointer */
1733 fip->list->field.name =
1734 obconcat (&objfile->type_obstack, vptr_name, "", "");
1735 break;
1736
1737 case 'b': /* $vb -- a virtual bsomethingorother */
1738 name = type_name_no_tag (context);
1739 if (name == NULL)
1740 {
1741 complain (&invalid_cpp_type_complaint, symnum);
1742 name = "FOO";
1743 }
1744 fip->list->field.name =
1745 obconcat (&objfile->type_obstack, vb_name, name, "");
1746 break;
1747
1748 default:
1749 complain (&invalid_cpp_abbrev_complaint, *pp);
1750 fip->list->field.name =
1751 obconcat (&objfile->type_obstack,
1752 "INVALID_CPLUSPLUS_ABBREV", "", "");
1753 break;
1754 }
1755
1756 /* At this point, *pp points to the ':'. Skip it and read the
1757 field type. */
1758
1759 p = ++(*pp);
1760 if (p[-1] != ':')
1761 {
1762 complain (&invalid_cpp_abbrev_complaint, *pp);
1763 }
1764 fip->list->field.type = read_type (pp, objfile);
1765 (*pp)++; /* Skip the comma. */
1766 fip->list->field.bitpos = read_number (pp, ';');
1767 /* This field is unpacked. */
1768 fip->list->field.bitsize = 0;
1769 fip->list->visibility = VISIBILITY_PRIVATE;
1770 }
1771 else if (*p == '_')
1772 {
1773 /* GNU C++ anonymous type. */
1774 complain (&stabs_general_complaint, "g++ anonymous type $_ not handled");
1775 }
1776 else
1777 {
1778 complain (&invalid_cpp_abbrev_complaint, *pp);
1779 }
1780 }
1781
1782 static void
1783 read_one_struct_field (fip, pp, p, type, objfile)
1784 struct field_info *fip;
1785 char **pp;
1786 char *p;
1787 struct type *type;
1788 struct objfile *objfile;
1789 {
1790 fip -> list -> field.name =
1791 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
1792 *pp = p + 1;
1793
1794 /* This means we have a visibility for a field coming. */
1795 if (**pp == '/')
1796 {
1797 (*pp)++;
1798 fip -> list -> visibility = *(*pp)++;
1799 switch (fip -> list -> visibility)
1800 {
1801 case VISIBILITY_PRIVATE:
1802 case VISIBILITY_PROTECTED:
1803 break;
1804
1805 case VISIBILITY_PUBLIC:
1806 /* Nothing to do */
1807 break;
1808
1809 default:
1810 /* Unknown visibility specifier. */
1811 complain (&stabs_general_complaint,
1812 "unknown visibility specifier");
1813 return;
1814 break;
1815 }
1816 }
1817 else
1818 {
1819 /* normal dbx-style format, no explicit visibility */
1820 fip -> list -> visibility = VISIBILITY_PUBLIC;
1821 }
1822
1823 fip -> list -> field.type = read_type (pp, objfile);
1824 if (**pp == ':')
1825 {
1826 p = ++(*pp);
1827 #if 0
1828 /* Possible future hook for nested types. */
1829 if (**pp == '!')
1830 {
1831 fip -> list -> field.bitpos = (long)-2; /* nested type */
1832 p = ++(*pp);
1833 }
1834 else
1835 #endif
1836 {
1837 /* Static class member. */
1838 fip -> list -> field.bitpos = (long) -1;
1839 }
1840 while (*p != ';')
1841 {
1842 p++;
1843 }
1844 fip -> list -> field.bitsize = (long) savestring (*pp, p - *pp);
1845 *pp = p + 1;
1846 return;
1847 }
1848 else if (**pp != ',')
1849 {
1850 /* Bad structure-type format. */
1851 complain (&stabs_general_complaint, "bad structure-type format");
1852 return;
1853 }
1854
1855 (*pp)++; /* Skip the comma. */
1856 fip -> list -> field.bitpos = read_number (pp, ',');
1857 fip -> list -> field.bitsize = read_number (pp, ';');
1858
1859 #if 0
1860 /* FIXME-tiemann: Can't the compiler put out something which
1861 lets us distinguish these? (or maybe just not put out anything
1862 for the field). What is the story here? What does the compiler
1863 really do? Also, patch gdb.texinfo for this case; I document
1864 it as a possible problem there. Search for "DBX-style". */
1865
1866 /* This is wrong because this is identical to the symbols
1867 produced for GCC 0-size arrays. For example:
1868 typedef union {
1869 int num;
1870 char str[0];
1871 } foo;
1872 The code which dumped core in such circumstances should be
1873 fixed not to dump core. */
1874
1875 /* g++ -g0 can put out bitpos & bitsize zero for a static
1876 field. This does not give us any way of getting its
1877 class, so we can't know its name. But we can just
1878 ignore the field so we don't dump core and other nasty
1879 stuff. */
1880 if (fip -> list -> field.bitpos == 0 && fip -> list -> field.bitsize == 0)
1881 {
1882 complain (&dbx_class_complaint);
1883 /* Ignore this field. */
1884 fip -> list = fip -> list -> next;
1885 }
1886 else
1887 #endif /* 0 */
1888 {
1889 /* Detect an unpacked field and mark it as such.
1890 dbx gives a bit size for all fields.
1891 Note that forward refs cannot be packed,
1892 and treat enums as if they had the width of ints. */
1893
1894 if (TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_INT
1895 && TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_ENUM)
1896 {
1897 fip -> list -> field.bitsize = 0;
1898 }
1899 if ((fip -> list -> field.bitsize
1900 == 8 * TYPE_LENGTH (fip -> list -> field.type)
1901 || (TYPE_CODE (fip -> list -> field.type) == TYPE_CODE_ENUM
1902 && (fip -> list -> field.bitsize
1903 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile, FT_INTEGER)))
1904 )
1905 )
1906 &&
1907 fip -> list -> field.bitpos % 8 == 0)
1908 {
1909 fip -> list -> field.bitsize = 0;
1910 }
1911 }
1912 }
1913
1914
1915 /* Read struct or class data fields. They have the form:
1916
1917 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
1918
1919 At the end, we see a semicolon instead of a field.
1920
1921 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1922 a static field.
1923
1924 The optional VISIBILITY is one of:
1925
1926 '/0' (VISIBILITY_PRIVATE)
1927 '/1' (VISIBILITY_PROTECTED)
1928 '/2' (VISIBILITY_PUBLIC)
1929
1930 or nothing, for C style fields with public visibility. */
1931
1932 static int
1933 read_struct_fields (fip, pp, type, objfile)
1934 struct field_info *fip;
1935 char **pp;
1936 struct type *type;
1937 struct objfile *objfile;
1938 {
1939 register char *p;
1940 struct nextfield *new;
1941
1942 /* We better set p right now, in case there are no fields at all... */
1943
1944 p = *pp;
1945
1946 /* Read each data member type until we find the terminating ';' at the end of
1947 the data member list, or break for some other reason such as finding the
1948 start of the member function list. */
1949
1950 while (**pp != ';')
1951 {
1952 STABS_CONTINUE (pp);
1953 /* Get space to record the next field's data. */
1954 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
1955 make_cleanup (free, new);
1956 memset (new, 0, sizeof (struct nextfield));
1957 new -> next = fip -> list;
1958 fip -> list = new;
1959
1960 /* Get the field name. */
1961 p = *pp;
1962 if (*p == CPLUS_MARKER)
1963 {
1964 read_cpp_abbrev (fip, pp, type, objfile);
1965 continue;
1966 }
1967
1968 /* Look for the ':' that separates the field name from the field
1969 values. Data members are delimited by a single ':', while member
1970 functions are delimited by a pair of ':'s. When we hit the member
1971 functions (if any), terminate scan loop and return. */
1972
1973 while (*p != ':')
1974 {
1975 p++;
1976 }
1977
1978 /* Check to see if we have hit the member functions yet. */
1979 if (p[1] == ':')
1980 {
1981 break;
1982 }
1983 read_one_struct_field (fip, pp, p, type, objfile);
1984 }
1985 if (p[1] == ':')
1986 {
1987 /* chill the list of fields: the last entry (at the head) is a
1988 partially constructed entry which we now scrub. */
1989 fip -> list = fip -> list -> next;
1990 }
1991 return 1;
1992 }
1993
1994 /* The stabs for C++ derived classes contain baseclass information which
1995 is marked by a '!' character after the total size. This function is
1996 called when we encounter the baseclass marker, and slurps up all the
1997 baseclass information.
1998
1999 Immediately following the '!' marker is the number of base classes that
2000 the class is derived from, followed by information for each base class.
2001 For each base class, there are two visibility specifiers, a bit offset
2002 to the base class information within the derived class, a reference to
2003 the type for the base class, and a terminating semicolon.
2004
2005 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2006 ^^ ^ ^ ^ ^ ^ ^
2007 Baseclass information marker __________________|| | | | | | |
2008 Number of baseclasses __________________________| | | | | | |
2009 Visibility specifiers (2) ________________________| | | | | |
2010 Offset in bits from start of class _________________| | | | |
2011 Type number for base class ___________________________| | | |
2012 Visibility specifiers (2) _______________________________| | |
2013 Offset in bits from start of class ________________________| |
2014 Type number of base class ____________________________________|
2015 */
2016
2017 static int
2018 read_baseclasses (fip, pp, type, objfile)
2019 struct field_info *fip;
2020 char **pp;
2021 struct type *type;
2022 struct objfile *objfile;
2023 {
2024 int i;
2025 struct nextfield *new;
2026
2027 if (**pp != '!')
2028 {
2029 return 1;
2030 }
2031 else
2032 {
2033 /* Skip the '!' baseclass information marker. */
2034 (*pp)++;
2035 }
2036
2037 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2038 TYPE_N_BASECLASSES (type) = read_number (pp, ',');
2039
2040 #if 0
2041 /* Some stupid compilers have trouble with the following, so break
2042 it up into simpler expressions. */
2043 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
2044 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
2045 #else
2046 {
2047 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
2048 char *pointer;
2049
2050 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2051 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2052 }
2053 #endif /* 0 */
2054
2055 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
2056
2057 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
2058 {
2059 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2060 make_cleanup (free, new);
2061 memset (new, 0, sizeof (struct nextfield));
2062 new -> next = fip -> list;
2063 fip -> list = new;
2064 new -> field.bitsize = 0; /* this should be an unpacked field! */
2065
2066 STABS_CONTINUE (pp);
2067 switch (*(*pp)++)
2068 {
2069 case '0':
2070 /* Nothing to do. */
2071 break;
2072 case '1':
2073 SET_TYPE_FIELD_VIRTUAL (type, i);
2074 break;
2075 default:
2076 /* Bad visibility format. */
2077 return 0;
2078 }
2079
2080 new -> visibility = *(*pp)++;
2081 switch (new -> visibility)
2082 {
2083 case VISIBILITY_PRIVATE:
2084 case VISIBILITY_PROTECTED:
2085 case VISIBILITY_PUBLIC:
2086 break;
2087 default:
2088 /* Bad visibility format. */
2089 return 0;
2090 }
2091
2092 /* The remaining value is the bit offset of the portion of the object
2093 corresponding to this baseclass. Always zero in the absence of
2094 multiple inheritance. */
2095
2096 new -> field.bitpos = read_number (pp, ',');
2097
2098 /* The last piece of baseclass information is the type of the base
2099 class. Read it, and remember it's type name as this field's name. */
2100
2101 new -> field.type = read_type (pp, objfile);
2102 new -> field.name = type_name_no_tag (new -> field.type);
2103
2104 /* skip trailing ';' and bump count of number of fields seen */
2105 (*pp)++;
2106 }
2107 return 1;
2108 }
2109
2110 /* The tail end of stabs for C++ classes that contain a virtual function
2111 pointer contains a tilde, a %, and a type number.
2112 The type number refers to the base class (possibly this class itself) which
2113 contains the vtable pointer for the current class.
2114
2115 This function is called when we have parsed all the method declarations,
2116 so we can look for the vptr base class info. */
2117
2118 static int
2119 read_tilde_fields (fip, pp, type, objfile)
2120 struct field_info *fip;
2121 char **pp;
2122 struct type *type;
2123 struct objfile *objfile;
2124 {
2125 register char *p;
2126
2127 STABS_CONTINUE (pp);
2128
2129 /* If we are positioned at a ';', then skip it. */
2130 if (**pp == ';')
2131 {
2132 (*pp)++;
2133 }
2134
2135 if (**pp == '~')
2136 {
2137 (*pp)++;
2138
2139 if (**pp == '=' || **pp == '+' || **pp == '-')
2140 {
2141 /* Obsolete flags that used to indicate the presence
2142 of constructors and/or destructors. */
2143 (*pp)++;
2144 }
2145
2146 /* Read either a '%' or the final ';'. */
2147 if (*(*pp)++ == '%')
2148 {
2149 /* The next number is the type number of the base class
2150 (possibly our own class) which supplies the vtable for
2151 this class. Parse it out, and search that class to find
2152 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2153 and TYPE_VPTR_FIELDNO. */
2154
2155 struct type *t;
2156 int i;
2157
2158 t = read_type (pp, objfile);
2159 p = (*pp)++;
2160 while (*p != '\0' && *p != ';')
2161 {
2162 p++;
2163 }
2164 if (*p == '\0')
2165 {
2166 /* Premature end of symbol. */
2167 return 0;
2168 }
2169
2170 TYPE_VPTR_BASETYPE (type) = t;
2171 if (type == t) /* Our own class provides vtbl ptr */
2172 {
2173 for (i = TYPE_NFIELDS (t) - 1;
2174 i >= TYPE_N_BASECLASSES (t);
2175 --i)
2176 {
2177 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2178 sizeof (vptr_name) - 1))
2179 {
2180 TYPE_VPTR_FIELDNO (type) = i;
2181 goto gotit;
2182 }
2183 }
2184 /* Virtual function table field not found. */
2185 complain (vtbl_notfound_complaint, TYPE_NAME (type));
2186 return 0;
2187 }
2188 else
2189 {
2190 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2191 }
2192
2193 gotit:
2194 *pp = p + 1;
2195 }
2196 }
2197 return 1;
2198 }
2199
2200 static int
2201 attach_fn_fields_to_type (fip, type)
2202 struct field_info *fip;
2203 register struct type *type;
2204 {
2205 register int n;
2206
2207 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2208 {
2209 if (TYPE_CODE (TYPE_BASECLASS (type, n)) == TYPE_CODE_UNDEF)
2210 {
2211 /* @@ Memory leak on objfile -> type_obstack? */
2212 return 0;
2213 }
2214 TYPE_NFN_FIELDS_TOTAL (type) +=
2215 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, n));
2216 }
2217
2218 for (n = TYPE_NFN_FIELDS (type);
2219 fip -> fnlist != NULL;
2220 fip -> fnlist = fip -> fnlist -> next)
2221 {
2222 --n; /* Circumvent Sun3 compiler bug */
2223 TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist;
2224 }
2225 return 1;
2226 }
2227
2228 /* Create the vector of fields, and record how big it is.
2229 We need this info to record proper virtual function table information
2230 for this class's virtual functions. */
2231
2232 static int
2233 attach_fields_to_type (fip, type, objfile)
2234 struct field_info *fip;
2235 register struct type *type;
2236 struct objfile *objfile;
2237 {
2238 register int nfields = 0;
2239 register int non_public_fields = 0;
2240 register struct nextfield *scan;
2241
2242 /* Count up the number of fields that we have, as well as taking note of
2243 whether or not there are any non-public fields, which requires us to
2244 allocate and build the private_field_bits and protected_field_bits
2245 bitfields. */
2246
2247 for (scan = fip -> list; scan != NULL; scan = scan -> next)
2248 {
2249 nfields++;
2250 if (scan -> visibility != VISIBILITY_PUBLIC)
2251 {
2252 non_public_fields++;
2253 }
2254 }
2255
2256 /* Now we know how many fields there are, and whether or not there are any
2257 non-public fields. Record the field count, allocate space for the
2258 array of fields, and create blank visibility bitfields if necessary. */
2259
2260 TYPE_NFIELDS (type) = nfields;
2261 TYPE_FIELDS (type) = (struct field *)
2262 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2263 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2264
2265 if (non_public_fields)
2266 {
2267 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2268
2269 TYPE_FIELD_PRIVATE_BITS (type) =
2270 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2271 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2272
2273 TYPE_FIELD_PROTECTED_BITS (type) =
2274 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2275 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2276 }
2277
2278 /* Copy the saved-up fields into the field vector. Start from the head
2279 of the list, adding to the tail of the field array, so that they end
2280 up in the same order in the array in which they were added to the list. */
2281
2282 while (nfields-- > 0)
2283 {
2284 TYPE_FIELD (type, nfields) = fip -> list -> field;
2285 switch (fip -> list -> visibility)
2286 {
2287 case VISIBILITY_PRIVATE:
2288 SET_TYPE_FIELD_PRIVATE (type, nfields);
2289 break;
2290
2291 case VISIBILITY_PROTECTED:
2292 SET_TYPE_FIELD_PROTECTED (type, nfields);
2293 break;
2294
2295 case VISIBILITY_PUBLIC:
2296 break;
2297
2298 default:
2299 /* Should warn about this unknown visibility? */
2300 break;
2301 }
2302 fip -> list = fip -> list -> next;
2303 }
2304 return 1;
2305 }
2306
2307 /* Read the description of a structure (or union type) and return an object
2308 describing the type.
2309
2310 PP points to a character pointer that points to the next unconsumed token
2311 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2312 *PP will point to "4a:1,0,32;;".
2313
2314 TYPE points to an incomplete type that needs to be filled in.
2315
2316 OBJFILE points to the current objfile from which the stabs information is
2317 being read. (Note that it is redundant in that TYPE also contains a pointer
2318 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2319 */
2320
2321 static struct type *
2322 read_struct_type (pp, type, objfile)
2323 char **pp;
2324 struct type *type;
2325 struct objfile *objfile;
2326 {
2327 struct cleanup *back_to;
2328 struct field_info fi;
2329
2330 fi.list = NULL;
2331 fi.fnlist = NULL;
2332
2333 back_to = make_cleanup (null_cleanup, 0);
2334
2335 INIT_CPLUS_SPECIFIC (type);
2336 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2337
2338 /* First comes the total size in bytes. */
2339
2340 TYPE_LENGTH (type) = read_number (pp, 0);
2341
2342 /* Now read the baseclasses, if any, read the regular C struct or C++
2343 class member fields, attach the fields to the type, read the C++
2344 member functions, attach them to the type, and then read any tilde
2345 field (baseclass specifier for the class holding the main vtable). */
2346
2347 if (!read_baseclasses (&fi, pp, type, objfile))
2348 {
2349 do_cleanups (back_to);
2350 return (error_type (pp));
2351 }
2352 if (!read_struct_fields (&fi, pp, type, objfile))
2353 {
2354 do_cleanups (back_to);
2355 return (error_type (pp));
2356 }
2357 if (!attach_fields_to_type (&fi, type, objfile))
2358 {
2359 do_cleanups (back_to);
2360 return (error_type (pp));
2361 }
2362 if (!read_member_functions (&fi, pp, type, objfile))
2363 {
2364 do_cleanups (back_to);
2365 return (error_type (pp));
2366 }
2367 if (!attach_fn_fields_to_type (&fi, type))
2368 {
2369 do_cleanups (back_to);
2370 return (error_type (pp));
2371 }
2372 if (!read_tilde_fields (&fi, pp, type, objfile))
2373 {
2374 do_cleanups (back_to);
2375 return (error_type (pp));
2376 }
2377
2378 do_cleanups (back_to);
2379 return (type);
2380 }
2381
2382 /* Read a definition of an array type,
2383 and create and return a suitable type object.
2384 Also creates a range type which represents the bounds of that
2385 array. */
2386
2387 static struct type *
2388 read_array_type (pp, type, objfile)
2389 register char **pp;
2390 register struct type *type;
2391 struct objfile *objfile;
2392 {
2393 struct type *index_type, *element_type, *range_type;
2394 int lower, upper;
2395 int adjustable = 0;
2396
2397 /* Format of an array type:
2398 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2399 to handle this.
2400
2401 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2402 for these, produce a type like float[][]. */
2403
2404 index_type = read_type (pp, objfile);
2405 if (**pp != ';')
2406 /* Improper format of array type decl. */
2407 return error_type (pp);
2408 ++*pp;
2409
2410 if (!(**pp >= '0' && **pp <= '9'))
2411 {
2412 (*pp)++;
2413 adjustable = 1;
2414 }
2415 lower = read_number (pp, ';');
2416
2417 if (!(**pp >= '0' && **pp <= '9'))
2418 {
2419 (*pp)++;
2420 adjustable = 1;
2421 }
2422 upper = read_number (pp, ';');
2423
2424 element_type = read_type (pp, objfile);
2425
2426 if (adjustable)
2427 {
2428 lower = 0;
2429 upper = -1;
2430 }
2431
2432 range_type =
2433 create_range_type ((struct type *) NULL, index_type, lower, upper);
2434 type = create_array_type (type, element_type, range_type);
2435
2436 /* If we have an array whose element type is not yet known, but whose
2437 bounds *are* known, record it to be adjusted at the end of the file. */
2438
2439 if (TYPE_LENGTH (element_type) == 0 && !adjustable)
2440 {
2441 add_undefined_type (type);
2442 }
2443
2444 return type;
2445 }
2446
2447
2448 /* Read a definition of an enumeration type,
2449 and create and return a suitable type object.
2450 Also defines the symbols that represent the values of the type. */
2451
2452 static struct type *
2453 read_enum_type (pp, type, objfile)
2454 register char **pp;
2455 register struct type *type;
2456 struct objfile *objfile;
2457 {
2458 register char *p;
2459 char *name;
2460 register long n;
2461 register struct symbol *sym;
2462 int nsyms = 0;
2463 struct pending **symlist;
2464 struct pending *osyms, *syms;
2465 int o_nsyms;
2466
2467 #if 0
2468 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2469 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2470 to do? For now, force all enum values to file scope. */
2471 if (within_function)
2472 symlist = &local_symbols;
2473 else
2474 #endif
2475 symlist = &file_symbols;
2476 osyms = *symlist;
2477 o_nsyms = osyms ? osyms->nsyms : 0;
2478
2479 /* Read the value-names and their values.
2480 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2481 A semicolon or comma instead of a NAME means the end. */
2482 while (**pp && **pp != ';' && **pp != ',')
2483 {
2484 STABS_CONTINUE (pp);
2485 p = *pp;
2486 while (*p != ':') p++;
2487 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
2488 *pp = p + 1;
2489 n = read_number (pp, ',');
2490
2491 sym = (struct symbol *)
2492 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
2493 memset (sym, 0, sizeof (struct symbol));
2494 SYMBOL_NAME (sym) = name;
2495 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
2496 SYMBOL_CLASS (sym) = LOC_CONST;
2497 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2498 SYMBOL_VALUE (sym) = n;
2499 add_symbol_to_list (sym, symlist);
2500 nsyms++;
2501 }
2502
2503 if (**pp == ';')
2504 (*pp)++; /* Skip the semicolon. */
2505
2506 /* Now fill in the fields of the type-structure. */
2507
2508 TYPE_LENGTH (type) = sizeof (int);
2509 TYPE_CODE (type) = TYPE_CODE_ENUM;
2510 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2511 TYPE_NFIELDS (type) = nsyms;
2512 TYPE_FIELDS (type) = (struct field *)
2513 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
2514 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
2515
2516 /* Find the symbols for the values and put them into the type.
2517 The symbols can be found in the symlist that we put them on
2518 to cause them to be defined. osyms contains the old value
2519 of that symlist; everything up to there was defined by us. */
2520 /* Note that we preserve the order of the enum constants, so
2521 that in something like "enum {FOO, LAST_THING=FOO}" we print
2522 FOO, not LAST_THING. */
2523
2524 for (syms = *symlist, n = 0; syms; syms = syms->next)
2525 {
2526 int j = 0;
2527 if (syms == osyms)
2528 j = o_nsyms;
2529 for (; j < syms->nsyms; j++,n++)
2530 {
2531 struct symbol *xsym = syms->symbol[j];
2532 SYMBOL_TYPE (xsym) = type;
2533 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2534 TYPE_FIELD_VALUE (type, n) = 0;
2535 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2536 TYPE_FIELD_BITSIZE (type, n) = 0;
2537 }
2538 if (syms == osyms)
2539 break;
2540 }
2541
2542 #if 0
2543 /* This screws up perfectly good C programs with enums. FIXME. */
2544 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2545 if(TYPE_NFIELDS(type) == 2 &&
2546 ((STREQ(TYPE_FIELD_NAME(type,0),"TRUE") &&
2547 STREQ(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2548 (STREQ(TYPE_FIELD_NAME(type,1),"TRUE") &&
2549 STREQ(TYPE_FIELD_NAME(type,0),"FALSE"))))
2550 TYPE_CODE(type) = TYPE_CODE_BOOL;
2551 #endif
2552
2553 return type;
2554 }
2555
2556 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2557 typedefs in every file (for int, long, etc):
2558
2559 type = b <signed> <width>; <offset>; <nbits>
2560 signed = u or s. Possible c in addition to u or s (for char?).
2561 offset = offset from high order bit to start bit of type.
2562 width is # bytes in object of this type, nbits is # bits in type.
2563
2564 The width/offset stuff appears to be for small objects stored in
2565 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2566 FIXME. */
2567
2568 static struct type *
2569 read_sun_builtin_type (pp, typenums, objfile)
2570 char **pp;
2571 int typenums[2];
2572 struct objfile *objfile;
2573 {
2574 int nbits;
2575 int signed_type;
2576
2577 switch (**pp)
2578 {
2579 case 's':
2580 signed_type = 1;
2581 break;
2582 case 'u':
2583 signed_type = 0;
2584 break;
2585 default:
2586 return error_type (pp);
2587 }
2588 (*pp)++;
2589
2590 /* For some odd reason, all forms of char put a c here. This is strange
2591 because no other type has this honor. We can safely ignore this because
2592 we actually determine 'char'acterness by the number of bits specified in
2593 the descriptor. */
2594
2595 if (**pp == 'c')
2596 (*pp)++;
2597
2598 /* The first number appears to be the number of bytes occupied
2599 by this type, except that unsigned short is 4 instead of 2.
2600 Since this information is redundant with the third number,
2601 we will ignore it. */
2602 read_number (pp, ';');
2603
2604 /* The second number is always 0, so ignore it too. */
2605 read_number (pp, ';');
2606
2607 /* The third number is the number of bits for this type. */
2608 nbits = read_number (pp, 0);
2609
2610 /* FIXME. Here we should just be able to make a type of the right
2611 number of bits and signedness. FIXME. */
2612
2613 if (nbits == TARGET_LONG_LONG_BIT)
2614 return (lookup_fundamental_type (objfile,
2615 signed_type? FT_LONG_LONG: FT_UNSIGNED_LONG_LONG));
2616
2617 if (nbits == TARGET_INT_BIT)
2618 {
2619 /* FIXME -- the only way to distinguish `int' from `long'
2620 is to look at its name! */
2621 if (signed_type)
2622 {
2623 if (long_kludge_name && long_kludge_name[0] == 'l' /* long */)
2624 return lookup_fundamental_type (objfile, FT_LONG);
2625 else
2626 return lookup_fundamental_type (objfile, FT_INTEGER);
2627 }
2628 else
2629 {
2630 if (long_kludge_name
2631 && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2632 long_kludge_name[9] == 'l' /* long */)
2633 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2634 return lookup_fundamental_type (objfile, FT_UNSIGNED_LONG);
2635 else
2636 return lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
2637 }
2638 }
2639
2640 if (nbits == TARGET_SHORT_BIT)
2641 return (lookup_fundamental_type (objfile,
2642 signed_type? FT_SHORT: FT_UNSIGNED_SHORT));
2643
2644 if (nbits == TARGET_CHAR_BIT)
2645 return (lookup_fundamental_type (objfile,
2646 signed_type? FT_CHAR: FT_UNSIGNED_CHAR));
2647
2648 if (nbits == 0)
2649 return lookup_fundamental_type (objfile, FT_VOID);
2650
2651 return error_type (pp);
2652 }
2653
2654 static struct type *
2655 read_sun_floating_type (pp, typenums, objfile)
2656 char **pp;
2657 int typenums[2];
2658 struct objfile *objfile;
2659 {
2660 int nbytes;
2661
2662 /* The first number has more details about the type, for example
2663 FN_COMPLEX. See the sun stab.h. */
2664 read_number (pp, ';');
2665
2666 /* The second number is the number of bytes occupied by this type */
2667 nbytes = read_number (pp, ';');
2668
2669 if (**pp != 0)
2670 return error_type (pp);
2671
2672 if (nbytes == TARGET_FLOAT_BIT / TARGET_CHAR_BIT)
2673 return lookup_fundamental_type (objfile, FT_FLOAT);
2674
2675 if (nbytes == TARGET_DOUBLE_BIT / TARGET_CHAR_BIT)
2676 return lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
2677
2678 if (nbytes == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT)
2679 return lookup_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
2680
2681 return error_type (pp);
2682 }
2683
2684 /* Read a number from the string pointed to by *PP.
2685 The value of *PP is advanced over the number.
2686 If END is nonzero, the character that ends the
2687 number must match END, or an error happens;
2688 and that character is skipped if it does match.
2689 If END is zero, *PP is left pointing to that character.
2690
2691 If the number fits in a long, set *VALUE and set *BITS to 0.
2692 If not, set *BITS to be the number of bits in the number.
2693
2694 If encounter garbage, set *BITS to -1. */
2695
2696 static void
2697 read_huge_number (pp, end, valu, bits)
2698 char **pp;
2699 int end;
2700 long *valu;
2701 int *bits;
2702 {
2703 char *p = *pp;
2704 int sign = 1;
2705 long n = 0;
2706 int radix = 10;
2707 char overflow = 0;
2708 int nbits = 0;
2709 int c;
2710 long upper_limit;
2711
2712 if (*p == '-')
2713 {
2714 sign = -1;
2715 p++;
2716 }
2717
2718 /* Leading zero means octal. GCC uses this to output values larger
2719 than an int (because that would be hard in decimal). */
2720 if (*p == '0')
2721 {
2722 radix = 8;
2723 p++;
2724 }
2725
2726 upper_limit = LONG_MAX / radix;
2727 while ((c = *p++) >= '0' && c <= ('0' + radix))
2728 {
2729 if (n <= upper_limit)
2730 {
2731 n *= radix;
2732 n += c - '0'; /* FIXME this overflows anyway */
2733 }
2734 else
2735 overflow = 1;
2736
2737 /* This depends on large values being output in octal, which is
2738 what GCC does. */
2739 if (radix == 8)
2740 {
2741 if (nbits == 0)
2742 {
2743 if (c == '0')
2744 /* Ignore leading zeroes. */
2745 ;
2746 else if (c == '1')
2747 nbits = 1;
2748 else if (c == '2' || c == '3')
2749 nbits = 2;
2750 else
2751 nbits = 3;
2752 }
2753 else
2754 nbits += 3;
2755 }
2756 }
2757 if (end)
2758 {
2759 if (c && c != end)
2760 {
2761 if (bits != NULL)
2762 *bits = -1;
2763 return;
2764 }
2765 }
2766 else
2767 --p;
2768
2769 *pp = p;
2770 if (overflow)
2771 {
2772 if (nbits == 0)
2773 {
2774 /* Large decimal constants are an error (because it is hard to
2775 count how many bits are in them). */
2776 if (bits != NULL)
2777 *bits = -1;
2778 return;
2779 }
2780
2781 /* -0x7f is the same as 0x80. So deal with it by adding one to
2782 the number of bits. */
2783 if (sign == -1)
2784 ++nbits;
2785 if (bits)
2786 *bits = nbits;
2787 }
2788 else
2789 {
2790 if (valu)
2791 *valu = n * sign;
2792 if (bits)
2793 *bits = 0;
2794 }
2795 }
2796
2797 static struct type *
2798 read_range_type (pp, typenums, objfile)
2799 char **pp;
2800 int typenums[2];
2801 struct objfile *objfile;
2802 {
2803 int rangenums[2];
2804 long n2, n3;
2805 int n2bits, n3bits;
2806 int self_subrange;
2807 struct type *result_type;
2808 struct type *index_type;
2809
2810 /* First comes a type we are a subrange of.
2811 In C it is usually 0, 1 or the type being defined. */
2812 read_type_number (pp, rangenums);
2813 self_subrange = (rangenums[0] == typenums[0] &&
2814 rangenums[1] == typenums[1]);
2815
2816 /* A semicolon should now follow; skip it. */
2817 if (**pp == ';')
2818 (*pp)++;
2819
2820 /* The remaining two operands are usually lower and upper bounds
2821 of the range. But in some special cases they mean something else. */
2822 read_huge_number (pp, ';', &n2, &n2bits);
2823 read_huge_number (pp, ';', &n3, &n3bits);
2824
2825 if (n2bits == -1 || n3bits == -1)
2826 return error_type (pp);
2827
2828 /* If limits are huge, must be large integral type. */
2829 if (n2bits != 0 || n3bits != 0)
2830 {
2831 char got_signed = 0;
2832 char got_unsigned = 0;
2833 /* Number of bits in the type. */
2834 int nbits;
2835
2836 /* Range from 0 to <large number> is an unsigned large integral type. */
2837 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
2838 {
2839 got_unsigned = 1;
2840 nbits = n3bits;
2841 }
2842 /* Range from <large number> to <large number>-1 is a large signed
2843 integral type. */
2844 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
2845 {
2846 got_signed = 1;
2847 nbits = n2bits;
2848 }
2849
2850 /* Check for "long long". */
2851 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
2852 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
2853 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
2854 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
2855
2856 if (got_signed || got_unsigned)
2857 {
2858 result_type = alloc_type (objfile);
2859 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
2860 TYPE_CODE (result_type) = TYPE_CODE_INT;
2861 if (got_unsigned)
2862 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
2863 return result_type;
2864 }
2865 else
2866 return error_type (pp);
2867 }
2868
2869 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2870 if (self_subrange && n2 == 0 && n3 == 0)
2871 return (lookup_fundamental_type (objfile, FT_VOID));
2872
2873 /* If n3 is zero and n2 is not, we want a floating type,
2874 and n2 is the width in bytes.
2875
2876 Fortran programs appear to use this for complex types also,
2877 and they give no way to distinguish between double and single-complex!
2878 We don't have complex types, so we would lose on all fortran files!
2879 So return type `double' for all of those. It won't work right
2880 for the complex values, but at least it makes the file loadable.
2881
2882 FIXME, we may be able to distinguish these by their names. FIXME. */
2883
2884 if (n3 == 0 && n2 > 0)
2885 {
2886 if (n2 == sizeof (float))
2887 return (lookup_fundamental_type (objfile, FT_FLOAT));
2888 return (lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT));
2889 }
2890
2891 /* If the upper bound is -1, it must really be an unsigned int. */
2892
2893 else if (n2 == 0 && n3 == -1)
2894 {
2895 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2896 long' is to look at its name! */
2897 if (
2898 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2899 long_kludge_name[9] == 'l' /* long */)
2900 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2901 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
2902 else
2903 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
2904 }
2905
2906 /* Special case: char is defined (Who knows why) as a subrange of
2907 itself with range 0-127. */
2908 else if (self_subrange && n2 == 0 && n3 == 127)
2909 return (lookup_fundamental_type (objfile, FT_CHAR));
2910
2911 /* Assumptions made here: Subrange of self is equivalent to subrange
2912 of int. FIXME: Host and target type-sizes assumed the same. */
2913 /* FIXME: This is the *only* place in GDB that depends on comparing
2914 some type to a builtin type with ==. Fix it! */
2915 else if (n2 == 0
2916 && (self_subrange ||
2917 *dbx_lookup_type (rangenums) == lookup_fundamental_type (objfile, FT_INTEGER)))
2918 {
2919 /* an unsigned type */
2920 #ifdef LONG_LONG
2921 if (n3 == - sizeof (long long))
2922 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
2923 #endif
2924 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2925 long' is to look at its name! */
2926 if (n3 == (unsigned long)~0L &&
2927 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2928 long_kludge_name[9] == 'l' /* long */)
2929 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2930 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
2931 if (n3 == (unsigned int)~0L)
2932 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
2933 if (n3 == (unsigned short)~0L)
2934 return (lookup_fundamental_type (objfile, FT_UNSIGNED_SHORT));
2935 if (n3 == (unsigned char)~0L)
2936 return (lookup_fundamental_type (objfile, FT_UNSIGNED_CHAR));
2937 }
2938 #ifdef LONG_LONG
2939 else if (n3 == 0 && n2 == -sizeof (long long))
2940 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
2941 #endif
2942 else if (n2 == -n3 -1)
2943 {
2944 /* a signed type */
2945 /* FIXME -- the only way to distinguish `int' from `long' is to look
2946 at its name! */
2947 if ((n3 ==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2948 long_kludge_name && long_kludge_name[0] == 'l' /* long */)
2949 return (lookup_fundamental_type (objfile, FT_LONG));
2950 if (n3 == (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2951 return (lookup_fundamental_type (objfile, FT_INTEGER));
2952 if (n3 == ( 1 << (8 * sizeof (short) - 1)) - 1)
2953 return (lookup_fundamental_type (objfile, FT_SHORT));
2954 if (n3 == ( 1 << (8 * sizeof (char) - 1)) - 1)
2955 return (lookup_fundamental_type (objfile, FT_SIGNED_CHAR));
2956 }
2957
2958 /* We have a real range type on our hands. Allocate space and
2959 return a real pointer. */
2960
2961 /* At this point I don't have the faintest idea how to deal with
2962 a self_subrange type; I'm going to assume that this is used
2963 as an idiom, and that all of them are special cases. So . . . */
2964 if (self_subrange)
2965 return error_type (pp);
2966
2967 index_type = *dbx_lookup_type (rangenums);
2968 if (index_type == NULL)
2969 {
2970 complain (&range_type_base_complaint, rangenums[1]);
2971 index_type = lookup_fundamental_type (objfile, FT_INTEGER);
2972 }
2973
2974 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
2975 return (result_type);
2976 }
2977
2978 /* Read a number from the string pointed to by *PP.
2979 The value of *PP is advanced over the number.
2980 If END is nonzero, the character that ends the
2981 number must match END, or an error happens;
2982 and that character is skipped if it does match.
2983 If END is zero, *PP is left pointing to that character. */
2984
2985 long
2986 read_number (pp, end)
2987 char **pp;
2988 int end;
2989 {
2990 register char *p = *pp;
2991 register long n = 0;
2992 register int c;
2993 int sign = 1;
2994
2995 /* Handle an optional leading minus sign. */
2996
2997 if (*p == '-')
2998 {
2999 sign = -1;
3000 p++;
3001 }
3002
3003 /* Read the digits, as far as they go. */
3004
3005 while ((c = *p++) >= '0' && c <= '9')
3006 {
3007 n *= 10;
3008 n += c - '0';
3009 }
3010 if (end)
3011 {
3012 if (c && c != end)
3013 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
3014 }
3015 else
3016 --p;
3017
3018 *pp = p;
3019 return n * sign;
3020 }
3021
3022 /* Read in an argument list. This is a list of types, separated by commas
3023 and terminated with END. Return the list of types read in, or (struct type
3024 **)-1 if there is an error. */
3025
3026 static struct type **
3027 read_args (pp, end, objfile)
3028 char **pp;
3029 int end;
3030 struct objfile *objfile;
3031 {
3032 /* FIXME! Remove this arbitrary limit! */
3033 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
3034 int n = 0;
3035
3036 while (**pp != end)
3037 {
3038 if (**pp != ',')
3039 /* Invalid argument list: no ','. */
3040 return (struct type **)-1;
3041 (*pp)++;
3042 STABS_CONTINUE (pp);
3043 types[n++] = read_type (pp, objfile);
3044 }
3045 (*pp)++; /* get past `end' (the ':' character) */
3046
3047 if (n == 1)
3048 {
3049 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3050 }
3051 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3052 {
3053 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3054 memset (rval + n, 0, sizeof (struct type *));
3055 }
3056 else
3057 {
3058 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3059 }
3060 memcpy (rval, types, n * sizeof (struct type *));
3061 return rval;
3062 }
3063
3064 /* Add a common block's start address to the offset of each symbol
3065 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3066 the common block name). */
3067
3068 static void
3069 fix_common_block (sym, valu)
3070 struct symbol *sym;
3071 int valu;
3072 {
3073 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
3074 for ( ; next; next = next->next)
3075 {
3076 register int j;
3077 for (j = next->nsyms - 1; j >= 0; j--)
3078 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3079 }
3080 }
3081
3082
3083 \f
3084 /* What about types defined as forward references inside of a small lexical
3085 scope? */
3086 /* Add a type to the list of undefined types to be checked through
3087 once this file has been read in. */
3088
3089 void
3090 add_undefined_type (type)
3091 struct type *type;
3092 {
3093 if (undef_types_length == undef_types_allocated)
3094 {
3095 undef_types_allocated *= 2;
3096 undef_types = (struct type **)
3097 xrealloc ((char *) undef_types,
3098 undef_types_allocated * sizeof (struct type *));
3099 }
3100 undef_types[undef_types_length++] = type;
3101 }
3102
3103 /* Go through each undefined type, see if it's still undefined, and fix it
3104 up if possible. We have two kinds of undefined types:
3105
3106 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3107 Fix: update array length using the element bounds
3108 and the target type's length.
3109 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3110 yet defined at the time a pointer to it was made.
3111 Fix: Do a full lookup on the struct/union tag. */
3112 void
3113 cleanup_undefined_types ()
3114 {
3115 struct type **type;
3116
3117 for (type = undef_types; type < undef_types + undef_types_length; type++)
3118 {
3119 switch (TYPE_CODE (*type))
3120 {
3121
3122 case TYPE_CODE_STRUCT:
3123 case TYPE_CODE_UNION:
3124 case TYPE_CODE_ENUM:
3125 {
3126 /* Check if it has been defined since. */
3127 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
3128 {
3129 struct pending *ppt;
3130 int i;
3131 /* Name of the type, without "struct" or "union" */
3132 char *typename = TYPE_NAME (*type);
3133
3134 if (!strncmp (typename, "struct ", 7))
3135 typename += 7;
3136 if (!strncmp (typename, "union ", 6))
3137 typename += 6;
3138 if (!strncmp (typename, "enum ", 5))
3139 typename += 5;
3140
3141 for (ppt = file_symbols; ppt; ppt = ppt->next)
3142 {
3143 for (i = 0; i < ppt->nsyms; i++)
3144 {
3145 struct symbol *sym = ppt->symbol[i];
3146
3147 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3148 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
3149 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
3150 TYPE_CODE (*type))
3151 && STREQ (SYMBOL_NAME (sym), typename))
3152 {
3153 memcpy (*type, SYMBOL_TYPE (sym),
3154 sizeof (struct type));
3155 }
3156 }
3157 }
3158 }
3159 }
3160 break;
3161
3162 case TYPE_CODE_ARRAY:
3163 {
3164 struct type *range_type;
3165 int lower, upper;
3166
3167 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
3168 goto badtype;
3169 if (TYPE_NFIELDS (*type) != 1)
3170 goto badtype;
3171 range_type = TYPE_FIELD_TYPE (*type, 0);
3172 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
3173 goto badtype;
3174
3175 /* Now recompute the length of the array type, based on its
3176 number of elements and the target type's length. */
3177 lower = TYPE_FIELD_BITPOS (range_type, 0);
3178 upper = TYPE_FIELD_BITPOS (range_type, 1);
3179 TYPE_LENGTH (*type) = (upper - lower + 1)
3180 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
3181 }
3182 break;
3183
3184 default:
3185 badtype:
3186 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type));
3187 break;
3188 }
3189 }
3190 undef_types_length = 0;
3191 }
3192
3193 /* Scan through all of the global symbols defined in the object file,
3194 assigning values to the debugging symbols that need to be assigned
3195 to. Get these symbols from the minimal symbol table. */
3196
3197 void
3198 scan_file_globals (objfile)
3199 struct objfile *objfile;
3200 {
3201 int hash;
3202 struct minimal_symbol *msymbol;
3203 struct symbol *sym, *prev;
3204
3205 if (objfile->msymbols == 0) /* Beware the null file. */
3206 return;
3207
3208 for (msymbol = objfile -> msymbols; SYMBOL_NAME (msymbol) != NULL; msymbol++)
3209 {
3210 QUIT;
3211
3212 prev = NULL;
3213
3214 /* Get the hash index and check all the symbols
3215 under that hash index. */
3216
3217 hash = hashname (SYMBOL_NAME (msymbol));
3218
3219 for (sym = global_sym_chain[hash]; sym;)
3220 {
3221 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
3222 STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
3223 {
3224 /* Splice this symbol out of the hash chain and
3225 assign the value we have to it. */
3226 if (prev)
3227 {
3228 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
3229 }
3230 else
3231 {
3232 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
3233 }
3234
3235 /* Check to see whether we need to fix up a common block. */
3236 /* Note: this code might be executed several times for
3237 the same symbol if there are multiple references. */
3238
3239 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3240 {
3241 fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol));
3242 }
3243 else
3244 {
3245 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol);
3246 }
3247
3248 if (prev)
3249 {
3250 sym = SYMBOL_VALUE_CHAIN (prev);
3251 }
3252 else
3253 {
3254 sym = global_sym_chain[hash];
3255 }
3256 }
3257 else
3258 {
3259 prev = sym;
3260 sym = SYMBOL_VALUE_CHAIN (sym);
3261 }
3262 }
3263 }
3264 }
3265
3266 /* Initialize anything that needs initializing when starting to read
3267 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3268 to a psymtab. */
3269
3270 void
3271 stabsread_init ()
3272 {
3273 }
3274
3275 /* Initialize anything that needs initializing when a completely new
3276 symbol file is specified (not just adding some symbols from another
3277 file, e.g. a shared library). */
3278
3279 void
3280 stabsread_new_init ()
3281 {
3282 /* Empty the hash table of global syms looking for values. */
3283 memset (global_sym_chain, 0, sizeof (global_sym_chain));
3284 }
3285
3286 /* Initialize anything that needs initializing at the same time as
3287 start_symtab() is called. */
3288
3289 void start_stabs ()
3290 {
3291 global_stabs = NULL; /* AIX COFF */
3292 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3293 n_this_object_header_files = 1;
3294 type_vector_length = 0;
3295 type_vector = (struct type **) 0;
3296 }
3297
3298 /* Call after end_symtab() */
3299
3300 void end_stabs ()
3301 {
3302 if (type_vector)
3303 {
3304 free ((char *) type_vector);
3305 }
3306 type_vector = 0;
3307 type_vector_length = 0;
3308 previous_stab_code = 0;
3309 }
3310
3311 void
3312 finish_global_stabs (objfile)
3313 struct objfile *objfile;
3314 {
3315 if (global_stabs)
3316 {
3317 patch_block_stabs (global_symbols, global_stabs, objfile);
3318 free ((PTR) global_stabs);
3319 global_stabs = NULL;
3320 }
3321 }
3322
3323 /* Initializer for this module */
3324
3325 void
3326 _initialize_stabsread ()
3327 {
3328 undef_types_allocated = 20;
3329 undef_types_length = 0;
3330 undef_types = (struct type **)
3331 xmalloc (undef_types_allocated * sizeof (struct type *));
3332 }
This page took 0.107158 seconds and 5 git commands to generate.