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