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