Modified Files:
[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 return error_type (pp);
1325 }
1326
1327 p = strchr(*pp, ':');
1328 while (p[1] == ':')
1329 {
1330 p += 2;
1331 p = strchr(p, ':');
1332 }
1333 to = type_name =
1334 (char *)obstack_alloc (&objfile->type_obstack, p - *pp + 1);
1335
1336 /* Copy the name. */
1337 from = *pp + 1;
1338 while (from < p)
1339 *to++ = *from++;
1340 *to = '\0';
1341
1342 /* Set the pointer ahead of the name which we just read. */
1343 *pp = from;
1344 }
1345
1346 /* Now check to see whether the type has already been declared. */
1347 /* This is necessary at least in the case where the
1348 program says something like
1349 struct foo bar[5];
1350 The compiler puts out a cross-reference; we better find
1351 set the length of the structure correctly so we can
1352 set the length of the array. */
1353 for (ppt = file_symbols; ppt; ppt = ppt->next)
1354 for (i = 0; i < ppt->nsyms; i++)
1355 {
1356 struct symbol *sym = ppt->symbol[i];
1357
1358 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1359 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1360 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1361 && STREQ (SYMBOL_NAME (sym), type_name))
1362 {
1363 obstack_free (&objfile -> type_obstack, type_name);
1364 type = SYMBOL_TYPE (sym);
1365 return type;
1366 }
1367 }
1368
1369 /* Didn't find the type to which this refers, so we must
1370 be dealing with a forward reference. Allocate a type
1371 structure for it, and keep track of it so we can
1372 fill in the rest of the fields when we get the full
1373 type. */
1374 type = dbx_alloc_type (typenums, objfile);
1375 TYPE_CODE (type) = code;
1376 TYPE_TAG_NAME (type) = type_name;
1377 INIT_CPLUS_SPECIFIC(type);
1378 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1379
1380 add_undefined_type (type);
1381 return type;
1382 }
1383
1384 case '-': /* RS/6000 built-in type */
1385 case '0':
1386 case '1':
1387 case '2':
1388 case '3':
1389 case '4':
1390 case '5':
1391 case '6':
1392 case '7':
1393 case '8':
1394 case '9':
1395 case '(':
1396
1397 (*pp)--;
1398 if (read_type_number (pp, xtypenums) != 0)
1399 return error_type (pp);
1400
1401 if (typenums[0] == xtypenums[0] && typenums[1] == xtypenums[1])
1402 /* It's being defined as itself. That means it is "void". */
1403 type = init_type (TYPE_CODE_VOID, 0, 0, NULL, objfile);
1404 else
1405 {
1406 struct type *xtype = *dbx_lookup_type (xtypenums);
1407
1408 /* This can happen if we had '-' followed by a garbage character,
1409 for example. */
1410 if (xtype == NULL)
1411 return error_type (pp);
1412
1413 /* The type is being defined to another type. So we copy the type.
1414 This loses if we copy a C++ class and so we lose track of how
1415 the names are mangled (but g++ doesn't output stabs like this
1416 now anyway). */
1417
1418 type = alloc_type (objfile);
1419 memcpy (type, xtype, sizeof (struct type));
1420
1421 /* The idea behind clearing the names is that the only purpose
1422 for defining a type to another type is so that the name of
1423 one can be different. So we probably don't need to worry much
1424 about the case where the compiler doesn't give a name to the
1425 new type. */
1426 TYPE_NAME (type) = NULL;
1427 TYPE_TAG_NAME (type) = NULL;
1428 }
1429 if (typenums[0] != -1)
1430 *dbx_lookup_type (typenums) = type;
1431 break;
1432
1433 /* In the following types, we must be sure to overwrite any existing
1434 type that the typenums refer to, rather than allocating a new one
1435 and making the typenums point to the new one. This is because there
1436 may already be pointers to the existing type (if it had been
1437 forward-referenced), and we must change it to a pointer, function,
1438 reference, or whatever, *in-place*. */
1439
1440 case '*':
1441 type1 = read_type (pp, objfile);
1442 type = make_pointer_type (type1, dbx_lookup_type (typenums));
1443 break;
1444
1445 case '&': /* Reference to another type */
1446 type1 = read_type (pp, objfile);
1447 type = make_reference_type (type1, dbx_lookup_type (typenums));
1448 break;
1449
1450 case 'f': /* Function returning another type */
1451 type1 = read_type (pp, objfile);
1452 type = make_function_type (type1, dbx_lookup_type (typenums));
1453 break;
1454
1455 case 'k': /* Const qualifier on some type (Sun) */
1456 type = read_type (pp, objfile);
1457 /* FIXME! For now, we ignore const and volatile qualifiers. */
1458 break;
1459
1460 case 'B': /* Volatile qual on some type (Sun) */
1461 type = read_type (pp, objfile);
1462 /* FIXME! For now, we ignore const and volatile qualifiers. */
1463 break;
1464
1465 /* FIXME -- we should be doing smash_to_XXX types here. */
1466 case '@': /* Member (class & variable) type */
1467 {
1468 struct type *domain = read_type (pp, objfile);
1469 struct type *memtype;
1470
1471 if (**pp != ',')
1472 /* Invalid member type data format. */
1473 return error_type (pp);
1474 ++*pp;
1475
1476 memtype = read_type (pp, objfile);
1477 type = dbx_alloc_type (typenums, objfile);
1478 smash_to_member_type (type, domain, memtype);
1479 }
1480 break;
1481
1482 case '#': /* Method (class & fn) type */
1483 if ((*pp)[0] == '#')
1484 {
1485 /* We'll get the parameter types from the name. */
1486 struct type *return_type;
1487
1488 (*pp)++;
1489 return_type = read_type (pp, objfile);
1490 if (*(*pp)++ != ';')
1491 complain (&invalid_member_complaint, symnum);
1492 type = allocate_stub_method (return_type);
1493 if (typenums[0] != -1)
1494 *dbx_lookup_type (typenums) = type;
1495 }
1496 else
1497 {
1498 struct type *domain = read_type (pp, objfile);
1499 struct type *return_type;
1500 struct type **args;
1501
1502 if (**pp != ',')
1503 /* Invalid member type data format. */
1504 return error_type (pp);
1505 else
1506 ++(*pp);
1507
1508 return_type = read_type (pp, objfile);
1509 args = read_args (pp, ';', objfile);
1510 type = dbx_alloc_type (typenums, objfile);
1511 smash_to_method_type (type, domain, return_type, args);
1512 }
1513 break;
1514
1515 case 'r': /* Range type */
1516 type = read_range_type (pp, typenums, objfile);
1517 if (typenums[0] != -1)
1518 *dbx_lookup_type (typenums) = type;
1519 break;
1520
1521 case 'b': /* Sun ACC builtin int type */
1522 type = read_sun_builtin_type (pp, typenums, objfile);
1523 if (typenums[0] != -1)
1524 *dbx_lookup_type (typenums) = type;
1525 break;
1526
1527 case 'R': /* Sun ACC builtin float type */
1528 type = read_sun_floating_type (pp, typenums, objfile);
1529 if (typenums[0] != -1)
1530 *dbx_lookup_type (typenums) = type;
1531 break;
1532
1533 case 'e': /* Enumeration type */
1534 type = dbx_alloc_type (typenums, objfile);
1535 type = read_enum_type (pp, type, objfile);
1536 if (typenums[0] != -1)
1537 *dbx_lookup_type (typenums) = type;
1538 break;
1539
1540 case 's': /* Struct type */
1541 case 'u': /* Union type */
1542 type = dbx_alloc_type (typenums, objfile);
1543 if (!TYPE_NAME (type))
1544 {
1545 TYPE_NAME (type) = type_synonym_name;
1546 }
1547 type_synonym_name = NULL;
1548 switch (type_descriptor)
1549 {
1550 case 's':
1551 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1552 break;
1553 case 'u':
1554 TYPE_CODE (type) = TYPE_CODE_UNION;
1555 break;
1556 }
1557 type = read_struct_type (pp, type, objfile);
1558 break;
1559
1560 case 'a': /* Array type */
1561 if (**pp != 'r')
1562 return error_type (pp);
1563 ++*pp;
1564
1565 type = dbx_alloc_type (typenums, objfile);
1566 type = read_array_type (pp, type, objfile);
1567 break;
1568
1569 default:
1570 --*pp; /* Go back to the symbol in error */
1571 /* Particularly important if it was \0! */
1572 return error_type (pp);
1573 }
1574
1575 if (type == 0)
1576 {
1577 warning ("GDB internal error, type is NULL in stabsread.c\n");
1578 return error_type (pp);
1579 }
1580
1581 /* Size specified in a type attribute overrides any other size. */
1582 if (type_size != -1)
1583 TYPE_LENGTH (type) = type_size / TARGET_CHAR_BIT;
1584
1585 return type;
1586 }
1587 \f
1588 /* RS/6000 xlc/dbx combination uses a set of builtin types, starting from -1.
1589 Return the proper type node for a given builtin type number. */
1590
1591 static struct type *
1592 rs6000_builtin_type (typenum)
1593 int typenum;
1594 {
1595 /* We recognize types numbered from -NUMBER_RECOGNIZED to -1. */
1596 #define NUMBER_RECOGNIZED 30
1597 /* This includes an empty slot for type number -0. */
1598 static struct type *negative_types[NUMBER_RECOGNIZED + 1];
1599 struct type *rettype = NULL;
1600
1601 if (typenum >= 0 || typenum < -NUMBER_RECOGNIZED)
1602 {
1603 complain (&rs6000_builtin_complaint, typenum);
1604 return builtin_type_error;
1605 }
1606 if (negative_types[-typenum] != NULL)
1607 return negative_types[-typenum];
1608
1609 #if TARGET_CHAR_BIT != 8
1610 #error This code wrong for TARGET_CHAR_BIT not 8
1611 /* These definitions all assume that TARGET_CHAR_BIT is 8. I think
1612 that if that ever becomes not true, the correct fix will be to
1613 make the size in the struct type to be in bits, not in units of
1614 TARGET_CHAR_BIT. */
1615 #endif
1616
1617 switch (-typenum)
1618 {
1619 case 1:
1620 /* The size of this and all the other types are fixed, defined
1621 by the debugging format. If there is a type called "int" which
1622 is other than 32 bits, then it should use a new negative type
1623 number (or avoid negative type numbers for that case).
1624 See stabs.texinfo. */
1625 rettype = init_type (TYPE_CODE_INT, 4, 0, "int", NULL);
1626 break;
1627 case 2:
1628 rettype = init_type (TYPE_CODE_INT, 1, 0, "char", NULL);
1629 break;
1630 case 3:
1631 rettype = init_type (TYPE_CODE_INT, 2, 0, "short", NULL);
1632 break;
1633 case 4:
1634 rettype = init_type (TYPE_CODE_INT, 4, 0, "long", NULL);
1635 break;
1636 case 5:
1637 rettype = init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED,
1638 "unsigned char", NULL);
1639 break;
1640 case 6:
1641 rettype = init_type (TYPE_CODE_INT, 1, 0, "signed char", NULL);
1642 break;
1643 case 7:
1644 rettype = init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED,
1645 "unsigned short", NULL);
1646 break;
1647 case 8:
1648 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1649 "unsigned int", NULL);
1650 break;
1651 case 9:
1652 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1653 "unsigned", NULL);
1654 case 10:
1655 rettype = init_type (TYPE_CODE_INT, 4, TYPE_FLAG_UNSIGNED,
1656 "unsigned long", NULL);
1657 break;
1658 case 11:
1659 rettype = init_type (TYPE_CODE_VOID, 0, 0, "void", NULL);
1660 break;
1661 case 12:
1662 /* IEEE single precision (32 bit). */
1663 rettype = init_type (TYPE_CODE_FLT, 4, 0, "float", NULL);
1664 break;
1665 case 13:
1666 /* IEEE double precision (64 bit). */
1667 rettype = init_type (TYPE_CODE_FLT, 8, 0, "double", NULL);
1668 break;
1669 case 14:
1670 /* This is an IEEE double on the RS/6000, and different machines with
1671 different sizes for "long double" should use different negative
1672 type numbers. See stabs.texinfo. */
1673 rettype = init_type (TYPE_CODE_FLT, 8, 0, "long double", NULL);
1674 break;
1675 case 15:
1676 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer", NULL);
1677 break;
1678 case 16:
1679 rettype = init_type (TYPE_CODE_BOOL, 4, 0, "boolean", NULL);
1680 break;
1681 case 17:
1682 rettype = init_type (TYPE_CODE_FLT, 4, 0, "short real", NULL);
1683 break;
1684 case 18:
1685 rettype = init_type (TYPE_CODE_FLT, 8, 0, "real", NULL);
1686 break;
1687 case 19:
1688 rettype = init_type (TYPE_CODE_ERROR, 0, 0, "stringptr", NULL);
1689 break;
1690 case 20:
1691 rettype = init_type (TYPE_CODE_CHAR, 1, TYPE_FLAG_UNSIGNED,
1692 "character", NULL);
1693 break;
1694 case 21:
1695 rettype = init_type (TYPE_CODE_BOOL, 1, TYPE_FLAG_UNSIGNED,
1696 "logical*1", NULL);
1697 break;
1698 case 22:
1699 rettype = init_type (TYPE_CODE_BOOL, 2, TYPE_FLAG_UNSIGNED,
1700 "logical*2", NULL);
1701 break;
1702 case 23:
1703 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1704 "logical*4", NULL);
1705 break;
1706 case 24:
1707 rettype = init_type (TYPE_CODE_BOOL, 4, TYPE_FLAG_UNSIGNED,
1708 "logical", NULL);
1709 break;
1710 case 25:
1711 /* Complex type consisting of two IEEE single precision values. */
1712 rettype = init_type (TYPE_CODE_ERROR, 8, 0, "complex", NULL);
1713 break;
1714 case 26:
1715 /* Complex type consisting of two IEEE double precision values. */
1716 rettype = init_type (TYPE_CODE_ERROR, 16, 0, "double complex", NULL);
1717 break;
1718 case 27:
1719 rettype = init_type (TYPE_CODE_INT, 1, 0, "integer*1", NULL);
1720 break;
1721 case 28:
1722 rettype = init_type (TYPE_CODE_INT, 2, 0, "integer*2", NULL);
1723 break;
1724 case 29:
1725 rettype = init_type (TYPE_CODE_INT, 4, 0, "integer*4", NULL);
1726 break;
1727 case 30:
1728 rettype = init_type (TYPE_CODE_CHAR, 2, 0, "wchar", NULL);
1729 break;
1730 }
1731 negative_types[-typenum] = rettype;
1732 return rettype;
1733 }
1734 \f
1735 /* This page contains subroutines of read_type. */
1736
1737 #define VISIBILITY_PRIVATE '0' /* Stabs character for private field */
1738 #define VISIBILITY_PROTECTED '1' /* Stabs character for protected fld */
1739 #define VISIBILITY_PUBLIC '2' /* Stabs character for public field */
1740 #define VISIBILITY_IGNORE '9' /* Optimized out or zero length */
1741
1742 /* Read member function stabs info for C++ classes. The form of each member
1743 function data is:
1744
1745 NAME :: TYPENUM[=type definition] ARGS : PHYSNAME ;
1746
1747 An example with two member functions is:
1748
1749 afunc1::20=##15;:i;2A.;afunc2::20:i;2A.;
1750
1751 For the case of overloaded operators, the format is op$::*.funcs, where
1752 $ is the CPLUS_MARKER (usually '$'), `*' holds the place for an operator
1753 name (such as `+=') and `.' marks the end of the operator name.
1754
1755 Returns 1 for success, 0 for failure. */
1756
1757 static int
1758 read_member_functions (fip, pp, type, objfile)
1759 struct field_info *fip;
1760 char **pp;
1761 struct type *type;
1762 struct objfile *objfile;
1763 {
1764 int nfn_fields = 0;
1765 int length = 0;
1766 /* Total number of member functions defined in this class. If the class
1767 defines two `f' functions, and one `g' function, then this will have
1768 the value 3. */
1769 int total_length = 0;
1770 int i;
1771 struct next_fnfield
1772 {
1773 struct next_fnfield *next;
1774 struct fn_field fn_field;
1775 } *sublist;
1776 struct type *look_ahead_type;
1777 struct next_fnfieldlist *new_fnlist;
1778 struct next_fnfield *new_sublist;
1779 char *main_fn_name;
1780 register char *p;
1781
1782 /* Process each list until we find something that is not a member function
1783 or find the end of the functions. */
1784
1785 while (**pp != ';')
1786 {
1787 /* We should be positioned at the start of the function name.
1788 Scan forward to find the first ':' and if it is not the
1789 first of a "::" delimiter, then this is not a member function. */
1790 p = *pp;
1791 while (*p != ':')
1792 {
1793 p++;
1794 }
1795 if (p[1] != ':')
1796 {
1797 break;
1798 }
1799
1800 sublist = NULL;
1801 look_ahead_type = NULL;
1802 length = 0;
1803
1804 new_fnlist = (struct next_fnfieldlist *)
1805 xmalloc (sizeof (struct next_fnfieldlist));
1806 make_cleanup (free, new_fnlist);
1807 memset (new_fnlist, 0, sizeof (struct next_fnfieldlist));
1808
1809 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
1810 {
1811 /* This is a completely wierd case. In order to stuff in the
1812 names that might contain colons (the usual name delimiter),
1813 Mike Tiemann defined a different name format which is
1814 signalled if the identifier is "op$". In that case, the
1815 format is "op$::XXXX." where XXXX is the name. This is
1816 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1817 /* This lets the user type "break operator+".
1818 We could just put in "+" as the name, but that wouldn't
1819 work for "*". */
1820 static char opname[32] = {'o', 'p', CPLUS_MARKER};
1821 char *o = opname + 3;
1822
1823 /* Skip past '::'. */
1824 *pp = p + 2;
1825
1826 STABS_CONTINUE (pp);
1827 p = *pp;
1828 while (*p != '.')
1829 {
1830 *o++ = *p++;
1831 }
1832 main_fn_name = savestring (opname, o - opname);
1833 /* Skip past '.' */
1834 *pp = p + 1;
1835 }
1836 else
1837 {
1838 main_fn_name = savestring (*pp, p - *pp);
1839 /* Skip past '::'. */
1840 *pp = p + 2;
1841 }
1842 new_fnlist -> fn_fieldlist.name = main_fn_name;
1843
1844 do
1845 {
1846 new_sublist =
1847 (struct next_fnfield *) xmalloc (sizeof (struct next_fnfield));
1848 make_cleanup (free, new_sublist);
1849 memset (new_sublist, 0, sizeof (struct next_fnfield));
1850
1851 /* Check for and handle cretinous dbx symbol name continuation! */
1852 if (look_ahead_type == NULL)
1853 {
1854 /* Normal case. */
1855 STABS_CONTINUE (pp);
1856
1857 new_sublist -> fn_field.type = read_type (pp, objfile);
1858 if (**pp != ':')
1859 {
1860 /* Invalid symtab info for member function. */
1861 return 0;
1862 }
1863 }
1864 else
1865 {
1866 /* g++ version 1 kludge */
1867 new_sublist -> fn_field.type = look_ahead_type;
1868 look_ahead_type = NULL;
1869 }
1870
1871 (*pp)++;
1872 p = *pp;
1873 while (*p != ';')
1874 {
1875 p++;
1876 }
1877
1878 /* If this is just a stub, then we don't have the real name here. */
1879
1880 if (TYPE_FLAGS (new_sublist -> fn_field.type) & TYPE_FLAG_STUB)
1881 {
1882 if (!TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type))
1883 TYPE_DOMAIN_TYPE (new_sublist -> fn_field.type) = type;
1884 new_sublist -> fn_field.is_stub = 1;
1885 }
1886 new_sublist -> fn_field.physname = savestring (*pp, p - *pp);
1887 *pp = p + 1;
1888
1889 /* Set this member function's visibility fields. */
1890 switch (*(*pp)++)
1891 {
1892 case VISIBILITY_PRIVATE:
1893 new_sublist -> fn_field.is_private = 1;
1894 break;
1895 case VISIBILITY_PROTECTED:
1896 new_sublist -> fn_field.is_protected = 1;
1897 break;
1898 }
1899
1900 STABS_CONTINUE (pp);
1901 switch (**pp)
1902 {
1903 case 'A': /* Normal functions. */
1904 new_sublist -> fn_field.is_const = 0;
1905 new_sublist -> fn_field.is_volatile = 0;
1906 (*pp)++;
1907 break;
1908 case 'B': /* `const' member functions. */
1909 new_sublist -> fn_field.is_const = 1;
1910 new_sublist -> fn_field.is_volatile = 0;
1911 (*pp)++;
1912 break;
1913 case 'C': /* `volatile' member function. */
1914 new_sublist -> fn_field.is_const = 0;
1915 new_sublist -> fn_field.is_volatile = 1;
1916 (*pp)++;
1917 break;
1918 case 'D': /* `const volatile' member function. */
1919 new_sublist -> fn_field.is_const = 1;
1920 new_sublist -> fn_field.is_volatile = 1;
1921 (*pp)++;
1922 break;
1923 case '*': /* File compiled with g++ version 1 -- no info */
1924 case '?':
1925 case '.':
1926 break;
1927 default:
1928 complain (&const_vol_complaint, **pp);
1929 break;
1930 }
1931
1932 switch (*(*pp)++)
1933 {
1934 case '*':
1935 {
1936 int nbits;
1937 /* virtual member function, followed by index.
1938 The sign bit is set to distinguish pointers-to-methods
1939 from virtual function indicies. Since the array is
1940 in words, the quantity must be shifted left by 1
1941 on 16 bit machine, and by 2 on 32 bit machine, forcing
1942 the sign bit out, and usable as a valid index into
1943 the array. Remove the sign bit here. */
1944 new_sublist -> fn_field.voffset =
1945 (0x7fffffff & read_huge_number (pp, ';', &nbits)) + 2;
1946 if (nbits != 0)
1947 return 0;
1948
1949 STABS_CONTINUE (pp);
1950 if (**pp == ';' || **pp == '\0')
1951 {
1952 /* Must be g++ version 1. */
1953 new_sublist -> fn_field.fcontext = 0;
1954 }
1955 else
1956 {
1957 /* Figure out from whence this virtual function came.
1958 It may belong to virtual function table of
1959 one of its baseclasses. */
1960 look_ahead_type = read_type (pp, objfile);
1961 if (**pp == ':')
1962 {
1963 /* g++ version 1 overloaded methods. */
1964 }
1965 else
1966 {
1967 new_sublist -> fn_field.fcontext = look_ahead_type;
1968 if (**pp != ';')
1969 {
1970 return 0;
1971 }
1972 else
1973 {
1974 ++*pp;
1975 }
1976 look_ahead_type = NULL;
1977 }
1978 }
1979 break;
1980 }
1981 case '?':
1982 /* static member function. */
1983 new_sublist -> fn_field.voffset = VOFFSET_STATIC;
1984 if (strncmp (new_sublist -> fn_field.physname,
1985 main_fn_name, strlen (main_fn_name)))
1986 {
1987 new_sublist -> fn_field.is_stub = 1;
1988 }
1989 break;
1990
1991 default:
1992 /* error */
1993 complain (&member_fn_complaint, (*pp)[-1]);
1994 /* Fall through into normal member function. */
1995
1996 case '.':
1997 /* normal member function. */
1998 new_sublist -> fn_field.voffset = 0;
1999 new_sublist -> fn_field.fcontext = 0;
2000 break;
2001 }
2002
2003 new_sublist -> next = sublist;
2004 sublist = new_sublist;
2005 length++;
2006 STABS_CONTINUE (pp);
2007 }
2008 while (**pp != ';' && **pp != '\0');
2009
2010 (*pp)++;
2011
2012 new_fnlist -> fn_fieldlist.fn_fields = (struct fn_field *)
2013 obstack_alloc (&objfile -> type_obstack,
2014 sizeof (struct fn_field) * length);
2015 memset (new_fnlist -> fn_fieldlist.fn_fields, 0,
2016 sizeof (struct fn_field) * length);
2017 for (i = length; (i--, sublist); sublist = sublist -> next)
2018 {
2019 new_fnlist -> fn_fieldlist.fn_fields[i] = sublist -> fn_field;
2020 }
2021
2022 new_fnlist -> fn_fieldlist.length = length;
2023 new_fnlist -> next = fip -> fnlist;
2024 fip -> fnlist = new_fnlist;
2025 nfn_fields++;
2026 total_length += length;
2027 STABS_CONTINUE (pp);
2028 }
2029
2030 if (nfn_fields)
2031 {
2032 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2033 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2034 TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * nfn_fields);
2035 memset (TYPE_FN_FIELDLISTS (type), 0,
2036 sizeof (struct fn_fieldlist) * nfn_fields);
2037 TYPE_NFN_FIELDS (type) = nfn_fields;
2038 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2039 }
2040
2041 return 1;
2042 }
2043
2044 /* Special GNU C++ name.
2045
2046 Returns 1 for success, 0 for failure. "failure" means that we can't
2047 keep parsing and it's time for error_type(). */
2048
2049 static int
2050 read_cpp_abbrev (fip, pp, type, objfile)
2051 struct field_info *fip;
2052 char **pp;
2053 struct type *type;
2054 struct objfile *objfile;
2055 {
2056 register char *p;
2057 char *name;
2058 char cpp_abbrev;
2059 struct type *context;
2060
2061 p = *pp;
2062 if (*++p == 'v')
2063 {
2064 name = NULL;
2065 cpp_abbrev = *++p;
2066
2067 *pp = p + 1;
2068
2069 /* At this point, *pp points to something like "22:23=*22...",
2070 where the type number before the ':' is the "context" and
2071 everything after is a regular type definition. Lookup the
2072 type, find it's name, and construct the field name. */
2073
2074 context = read_type (pp, objfile);
2075
2076 switch (cpp_abbrev)
2077 {
2078 case 'f': /* $vf -- a virtual function table pointer */
2079 fip->list->field.name =
2080 obconcat (&objfile->type_obstack, vptr_name, "", "");
2081 break;
2082
2083 case 'b': /* $vb -- a virtual bsomethingorother */
2084 name = type_name_no_tag (context);
2085 if (name == NULL)
2086 {
2087 complain (&invalid_cpp_type_complaint, symnum);
2088 name = "FOO";
2089 }
2090 fip->list->field.name =
2091 obconcat (&objfile->type_obstack, vb_name, name, "");
2092 break;
2093
2094 default:
2095 complain (&invalid_cpp_abbrev_complaint, *pp);
2096 fip->list->field.name =
2097 obconcat (&objfile->type_obstack,
2098 "INVALID_CPLUSPLUS_ABBREV", "", "");
2099 break;
2100 }
2101
2102 /* At this point, *pp points to the ':'. Skip it and read the
2103 field type. */
2104
2105 p = ++(*pp);
2106 if (p[-1] != ':')
2107 {
2108 complain (&invalid_cpp_abbrev_complaint, *pp);
2109 return 0;
2110 }
2111 fip->list->field.type = read_type (pp, objfile);
2112 if (**pp == ',')
2113 (*pp)++; /* Skip the comma. */
2114 else
2115 return 0;
2116
2117 {
2118 int nbits;
2119 fip->list->field.bitpos = read_huge_number (pp, ';', &nbits);
2120 if (nbits != 0)
2121 return 0;
2122 }
2123 /* This field is unpacked. */
2124 fip->list->field.bitsize = 0;
2125 fip->list->visibility = VISIBILITY_PRIVATE;
2126 }
2127 else
2128 {
2129 complain (&invalid_cpp_abbrev_complaint, *pp);
2130 /* We have no idea what syntax an unrecognized abbrev would have, so
2131 better return 0. If we returned 1, we would need to at least advance
2132 *pp to avoid an infinite loop. */
2133 return 0;
2134 }
2135 return 1;
2136 }
2137
2138 static void
2139 read_one_struct_field (fip, pp, p, type, objfile)
2140 struct field_info *fip;
2141 char **pp;
2142 char *p;
2143 struct type *type;
2144 struct objfile *objfile;
2145 {
2146 fip -> list -> field.name =
2147 obsavestring (*pp, p - *pp, &objfile -> type_obstack);
2148 *pp = p + 1;
2149
2150 /* This means we have a visibility for a field coming. */
2151 if (**pp == '/')
2152 {
2153 (*pp)++;
2154 fip -> list -> visibility = *(*pp)++;
2155 }
2156 else
2157 {
2158 /* normal dbx-style format, no explicit visibility */
2159 fip -> list -> visibility = VISIBILITY_PUBLIC;
2160 }
2161
2162 fip -> list -> field.type = read_type (pp, objfile);
2163 if (**pp == ':')
2164 {
2165 p = ++(*pp);
2166 #if 0
2167 /* Possible future hook for nested types. */
2168 if (**pp == '!')
2169 {
2170 fip -> list -> field.bitpos = (long)-2; /* nested type */
2171 p = ++(*pp);
2172 }
2173 else
2174 #endif
2175 {
2176 /* Static class member. */
2177 fip -> list -> field.bitpos = (long) -1;
2178 }
2179 while (*p != ';')
2180 {
2181 p++;
2182 }
2183 fip -> list -> field.bitsize = (long) savestring (*pp, p - *pp);
2184 *pp = p + 1;
2185 return;
2186 }
2187 else if (**pp != ',')
2188 {
2189 /* Bad structure-type format. */
2190 complain (&stabs_general_complaint, "bad structure-type format");
2191 return;
2192 }
2193
2194 (*pp)++; /* Skip the comma. */
2195
2196 {
2197 int nbits;
2198 fip -> list -> field.bitpos = read_huge_number (pp, ',', &nbits);
2199 if (nbits != 0)
2200 {
2201 complain (&stabs_general_complaint, "bad structure-type format");
2202 return;
2203 }
2204 fip -> list -> field.bitsize = read_huge_number (pp, ';', &nbits);
2205 if (nbits != 0)
2206 {
2207 complain (&stabs_general_complaint, "bad structure-type format");
2208 return;
2209 }
2210 }
2211
2212 if (fip -> list -> field.bitpos == 0 && fip -> list -> field.bitsize == 0)
2213 {
2214 /* This can happen in two cases: (1) at least for gcc 2.4.5 or so,
2215 it is a field which has been optimized out. The correct stab for
2216 this case is to use VISIBILITY_IGNORE, but that is a recent
2217 invention. (2) It is a 0-size array. For example
2218 union { int num; char str[0]; } foo. Printing "<no value>" for
2219 str in "p foo" is OK, since foo.str (and thus foo.str[3])
2220 will continue to work, and a 0-size array as a whole doesn't
2221 have any contents to print.
2222
2223 I suspect this probably could also happen with gcc -gstabs (not
2224 -gstabs+) for static fields, and perhaps other C++ extensions.
2225 Hopefully few people use -gstabs with gdb, since it is intended
2226 for dbx compatibility. */
2227
2228 /* Ignore this field. */
2229 fip -> list-> visibility = VISIBILITY_IGNORE;
2230 }
2231 else
2232 {
2233 /* Detect an unpacked field and mark it as such.
2234 dbx gives a bit size for all fields.
2235 Note that forward refs cannot be packed,
2236 and treat enums as if they had the width of ints. */
2237
2238 if (TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_INT
2239 && TYPE_CODE (fip -> list -> field.type) != TYPE_CODE_ENUM)
2240 {
2241 fip -> list -> field.bitsize = 0;
2242 }
2243 if ((fip -> list -> field.bitsize
2244 == TARGET_CHAR_BIT * TYPE_LENGTH (fip -> list -> field.type)
2245 || (TYPE_CODE (fip -> list -> field.type) == TYPE_CODE_ENUM
2246 && (fip -> list -> field.bitsize
2247 == TARGET_INT_BIT)
2248 )
2249 )
2250 &&
2251 fip -> list -> field.bitpos % 8 == 0)
2252 {
2253 fip -> list -> field.bitsize = 0;
2254 }
2255 }
2256 }
2257
2258
2259 /* Read struct or class data fields. They have the form:
2260
2261 NAME : [VISIBILITY] TYPENUM , BITPOS , BITSIZE ;
2262
2263 At the end, we see a semicolon instead of a field.
2264
2265 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2266 a static field.
2267
2268 The optional VISIBILITY is one of:
2269
2270 '/0' (VISIBILITY_PRIVATE)
2271 '/1' (VISIBILITY_PROTECTED)
2272 '/2' (VISIBILITY_PUBLIC)
2273 '/9' (VISIBILITY_IGNORE)
2274
2275 or nothing, for C style fields with public visibility.
2276
2277 Returns 1 for success, 0 for failure. */
2278
2279 static int
2280 read_struct_fields (fip, pp, type, objfile)
2281 struct field_info *fip;
2282 char **pp;
2283 struct type *type;
2284 struct objfile *objfile;
2285 {
2286 register char *p;
2287 struct nextfield *new;
2288
2289 /* We better set p right now, in case there are no fields at all... */
2290
2291 p = *pp;
2292
2293 /* Read each data member type until we find the terminating ';' at the end of
2294 the data member list, or break for some other reason such as finding the
2295 start of the member function list. */
2296
2297 while (**pp != ';')
2298 {
2299 STABS_CONTINUE (pp);
2300 /* Get space to record the next field's data. */
2301 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2302 make_cleanup (free, new);
2303 memset (new, 0, sizeof (struct nextfield));
2304 new -> next = fip -> list;
2305 fip -> list = new;
2306
2307 /* Get the field name. */
2308 p = *pp;
2309
2310 /* If is starts with CPLUS_MARKER it is a special abbreviation,
2311 unless the CPLUS_MARKER is followed by an underscore, in
2312 which case it is just the name of an anonymous type, which we
2313 should handle like any other type name. We accept either '$'
2314 or '.', because a field name can never contain one of these
2315 characters except as a CPLUS_MARKER (we probably should be
2316 doing that in most parts of GDB). */
2317
2318 if ((*p == '$' || *p == '.') && p[1] != '_')
2319 {
2320 if (!read_cpp_abbrev (fip, pp, type, objfile))
2321 return 0;
2322 continue;
2323 }
2324
2325 /* Look for the ':' that separates the field name from the field
2326 values. Data members are delimited by a single ':', while member
2327 functions are delimited by a pair of ':'s. When we hit the member
2328 functions (if any), terminate scan loop and return. */
2329
2330 while (*p != ':' && *p != '\0')
2331 {
2332 p++;
2333 }
2334 if (*p == '\0')
2335 return 0;
2336
2337 /* Check to see if we have hit the member functions yet. */
2338 if (p[1] == ':')
2339 {
2340 break;
2341 }
2342 read_one_struct_field (fip, pp, p, type, objfile);
2343 }
2344 if (p[1] == ':')
2345 {
2346 /* chill the list of fields: the last entry (at the head) is a
2347 partially constructed entry which we now scrub. */
2348 fip -> list = fip -> list -> next;
2349 }
2350 return 1;
2351 }
2352
2353 /* The stabs for C++ derived classes contain baseclass information which
2354 is marked by a '!' character after the total size. This function is
2355 called when we encounter the baseclass marker, and slurps up all the
2356 baseclass information.
2357
2358 Immediately following the '!' marker is the number of base classes that
2359 the class is derived from, followed by information for each base class.
2360 For each base class, there are two visibility specifiers, a bit offset
2361 to the base class information within the derived class, a reference to
2362 the type for the base class, and a terminating semicolon.
2363
2364 A typical example, with two base classes, would be "!2,020,19;0264,21;".
2365 ^^ ^ ^ ^ ^ ^ ^
2366 Baseclass information marker __________________|| | | | | | |
2367 Number of baseclasses __________________________| | | | | | |
2368 Visibility specifiers (2) ________________________| | | | | |
2369 Offset in bits from start of class _________________| | | | |
2370 Type number for base class ___________________________| | | |
2371 Visibility specifiers (2) _______________________________| | |
2372 Offset in bits from start of class ________________________| |
2373 Type number of base class ____________________________________|
2374
2375 Return 1 for success, 0 for (error-type-inducing) failure. */
2376
2377 static int
2378 read_baseclasses (fip, pp, type, objfile)
2379 struct field_info *fip;
2380 char **pp;
2381 struct type *type;
2382 struct objfile *objfile;
2383 {
2384 int i;
2385 struct nextfield *new;
2386
2387 if (**pp != '!')
2388 {
2389 return 1;
2390 }
2391 else
2392 {
2393 /* Skip the '!' baseclass information marker. */
2394 (*pp)++;
2395 }
2396
2397 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2398 {
2399 int nbits;
2400 TYPE_N_BASECLASSES (type) = read_huge_number (pp, ',', &nbits);
2401 if (nbits != 0)
2402 return 0;
2403 }
2404
2405 #if 0
2406 /* Some stupid compilers have trouble with the following, so break
2407 it up into simpler expressions. */
2408 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
2409 TYPE_ALLOC (type, B_BYTES (TYPE_N_BASECLASSES (type)));
2410 #else
2411 {
2412 int num_bytes = B_BYTES (TYPE_N_BASECLASSES (type));
2413 char *pointer;
2414
2415 pointer = (char *) TYPE_ALLOC (type, num_bytes);
2416 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer;
2417 }
2418 #endif /* 0 */
2419
2420 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), TYPE_N_BASECLASSES (type));
2421
2422 for (i = 0; i < TYPE_N_BASECLASSES (type); i++)
2423 {
2424 new = (struct nextfield *) xmalloc (sizeof (struct nextfield));
2425 make_cleanup (free, new);
2426 memset (new, 0, sizeof (struct nextfield));
2427 new -> next = fip -> list;
2428 fip -> list = new;
2429 new -> field.bitsize = 0; /* this should be an unpacked field! */
2430
2431 STABS_CONTINUE (pp);
2432 switch (**pp)
2433 {
2434 case '0':
2435 /* Nothing to do. */
2436 break;
2437 case '1':
2438 SET_TYPE_FIELD_VIRTUAL (type, i);
2439 break;
2440 default:
2441 /* Unknown character. Complain and treat it as non-virtual. */
2442 {
2443 static struct complaint msg = {
2444 "Unknown virtual character `%c' for baseclass", 0, 0};
2445 complain (&msg, **pp);
2446 }
2447 }
2448 ++(*pp);
2449
2450 new -> visibility = *(*pp)++;
2451 switch (new -> visibility)
2452 {
2453 case VISIBILITY_PRIVATE:
2454 case VISIBILITY_PROTECTED:
2455 case VISIBILITY_PUBLIC:
2456 break;
2457 default:
2458 /* Bad visibility format. Complain and treat it as
2459 public. */
2460 {
2461 static struct complaint msg = {
2462 "Unknown visibility `%c' for baseclass", 0, 0};
2463 complain (&msg, new -> visibility);
2464 new -> visibility = VISIBILITY_PUBLIC;
2465 }
2466 }
2467
2468 {
2469 int nbits;
2470
2471 /* The remaining value is the bit offset of the portion of the object
2472 corresponding to this baseclass. Always zero in the absence of
2473 multiple inheritance. */
2474
2475 new -> field.bitpos = read_huge_number (pp, ',', &nbits);
2476 if (nbits != 0)
2477 return 0;
2478 }
2479
2480 /* The last piece of baseclass information is the type of the
2481 base class. Read it, and remember it's type name as this
2482 field's name. */
2483
2484 new -> field.type = read_type (pp, objfile);
2485 new -> field.name = type_name_no_tag (new -> field.type);
2486
2487 /* skip trailing ';' and bump count of number of fields seen */
2488 if (**pp == ';')
2489 (*pp)++;
2490 else
2491 return 0;
2492 }
2493 return 1;
2494 }
2495
2496 /* The tail end of stabs for C++ classes that contain a virtual function
2497 pointer contains a tilde, a %, and a type number.
2498 The type number refers to the base class (possibly this class itself) which
2499 contains the vtable pointer for the current class.
2500
2501 This function is called when we have parsed all the method declarations,
2502 so we can look for the vptr base class info. */
2503
2504 static int
2505 read_tilde_fields (fip, pp, type, objfile)
2506 struct field_info *fip;
2507 char **pp;
2508 struct type *type;
2509 struct objfile *objfile;
2510 {
2511 register char *p;
2512
2513 STABS_CONTINUE (pp);
2514
2515 /* If we are positioned at a ';', then skip it. */
2516 if (**pp == ';')
2517 {
2518 (*pp)++;
2519 }
2520
2521 if (**pp == '~')
2522 {
2523 (*pp)++;
2524
2525 if (**pp == '=' || **pp == '+' || **pp == '-')
2526 {
2527 /* Obsolete flags that used to indicate the presence
2528 of constructors and/or destructors. */
2529 (*pp)++;
2530 }
2531
2532 /* Read either a '%' or the final ';'. */
2533 if (*(*pp)++ == '%')
2534 {
2535 /* The next number is the type number of the base class
2536 (possibly our own class) which supplies the vtable for
2537 this class. Parse it out, and search that class to find
2538 its vtable pointer, and install those into TYPE_VPTR_BASETYPE
2539 and TYPE_VPTR_FIELDNO. */
2540
2541 struct type *t;
2542 int i;
2543
2544 t = read_type (pp, objfile);
2545 p = (*pp)++;
2546 while (*p != '\0' && *p != ';')
2547 {
2548 p++;
2549 }
2550 if (*p == '\0')
2551 {
2552 /* Premature end of symbol. */
2553 return 0;
2554 }
2555
2556 TYPE_VPTR_BASETYPE (type) = t;
2557 if (type == t) /* Our own class provides vtbl ptr */
2558 {
2559 for (i = TYPE_NFIELDS (t) - 1;
2560 i >= TYPE_N_BASECLASSES (t);
2561 --i)
2562 {
2563 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2564 sizeof (vptr_name) - 1))
2565 {
2566 TYPE_VPTR_FIELDNO (type) = i;
2567 goto gotit;
2568 }
2569 }
2570 /* Virtual function table field not found. */
2571 complain (&vtbl_notfound_complaint, TYPE_NAME (type));
2572 return 0;
2573 }
2574 else
2575 {
2576 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2577 }
2578
2579 gotit:
2580 *pp = p + 1;
2581 }
2582 }
2583 return 1;
2584 }
2585
2586 static int
2587 attach_fn_fields_to_type (fip, type)
2588 struct field_info *fip;
2589 register struct type *type;
2590 {
2591 register int n;
2592
2593 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2594 {
2595 if (TYPE_CODE (TYPE_BASECLASS (type, n)) == TYPE_CODE_UNDEF)
2596 {
2597 /* @@ Memory leak on objfile -> type_obstack? */
2598 return 0;
2599 }
2600 TYPE_NFN_FIELDS_TOTAL (type) +=
2601 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, n));
2602 }
2603
2604 for (n = TYPE_NFN_FIELDS (type);
2605 fip -> fnlist != NULL;
2606 fip -> fnlist = fip -> fnlist -> next)
2607 {
2608 --n; /* Circumvent Sun3 compiler bug */
2609 TYPE_FN_FIELDLISTS (type)[n] = fip -> fnlist -> fn_fieldlist;
2610 }
2611 return 1;
2612 }
2613
2614 /* Create the vector of fields, and record how big it is.
2615 We need this info to record proper virtual function table information
2616 for this class's virtual functions. */
2617
2618 static int
2619 attach_fields_to_type (fip, type, objfile)
2620 struct field_info *fip;
2621 register struct type *type;
2622 struct objfile *objfile;
2623 {
2624 register int nfields = 0;
2625 register int non_public_fields = 0;
2626 register struct nextfield *scan;
2627
2628 /* Count up the number of fields that we have, as well as taking note of
2629 whether or not there are any non-public fields, which requires us to
2630 allocate and build the private_field_bits and protected_field_bits
2631 bitfields. */
2632
2633 for (scan = fip -> list; scan != NULL; scan = scan -> next)
2634 {
2635 nfields++;
2636 if (scan -> visibility != VISIBILITY_PUBLIC)
2637 {
2638 non_public_fields++;
2639 }
2640 }
2641
2642 /* Now we know how many fields there are, and whether or not there are any
2643 non-public fields. Record the field count, allocate space for the
2644 array of fields, and create blank visibility bitfields if necessary. */
2645
2646 TYPE_NFIELDS (type) = nfields;
2647 TYPE_FIELDS (type) = (struct field *)
2648 TYPE_ALLOC (type, sizeof (struct field) * nfields);
2649 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
2650
2651 if (non_public_fields)
2652 {
2653 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2654
2655 TYPE_FIELD_PRIVATE_BITS (type) =
2656 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2657 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2658
2659 TYPE_FIELD_PROTECTED_BITS (type) =
2660 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2661 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2662
2663 TYPE_FIELD_IGNORE_BITS (type) =
2664 (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields));
2665 B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields);
2666 }
2667
2668 /* Copy the saved-up fields into the field vector. Start from the head
2669 of the list, adding to the tail of the field array, so that they end
2670 up in the same order in the array in which they were added to the list. */
2671
2672 while (nfields-- > 0)
2673 {
2674 TYPE_FIELD (type, nfields) = fip -> list -> field;
2675 switch (fip -> list -> visibility)
2676 {
2677 case VISIBILITY_PRIVATE:
2678 SET_TYPE_FIELD_PRIVATE (type, nfields);
2679 break;
2680
2681 case VISIBILITY_PROTECTED:
2682 SET_TYPE_FIELD_PROTECTED (type, nfields);
2683 break;
2684
2685 case VISIBILITY_IGNORE:
2686 SET_TYPE_FIELD_IGNORE (type, nfields);
2687 break;
2688
2689 case VISIBILITY_PUBLIC:
2690 break;
2691
2692 default:
2693 /* Unknown visibility. Complain and treat it as public. */
2694 {
2695 static struct complaint msg = {
2696 "Unknown visibility `%c' for field", 0, 0};
2697 complain (&msg, fip -> list -> visibility);
2698 }
2699 break;
2700 }
2701 fip -> list = fip -> list -> next;
2702 }
2703 return 1;
2704 }
2705
2706 /* Read the description of a structure (or union type) and return an object
2707 describing the type.
2708
2709 PP points to a character pointer that points to the next unconsumed token
2710 in the the stabs string. For example, given stabs "A:T4=s4a:1,0,32;;",
2711 *PP will point to "4a:1,0,32;;".
2712
2713 TYPE points to an incomplete type that needs to be filled in.
2714
2715 OBJFILE points to the current objfile from which the stabs information is
2716 being read. (Note that it is redundant in that TYPE also contains a pointer
2717 to this same objfile, so it might be a good idea to eliminate it. FIXME).
2718 */
2719
2720 static struct type *
2721 read_struct_type (pp, type, objfile)
2722 char **pp;
2723 struct type *type;
2724 struct objfile *objfile;
2725 {
2726 struct cleanup *back_to;
2727 struct field_info fi;
2728
2729 fi.list = NULL;
2730 fi.fnlist = NULL;
2731
2732 back_to = make_cleanup (null_cleanup, 0);
2733
2734 INIT_CPLUS_SPECIFIC (type);
2735 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2736
2737 /* First comes the total size in bytes. */
2738
2739 {
2740 int nbits;
2741 TYPE_LENGTH (type) = read_huge_number (pp, 0, &nbits);
2742 if (nbits != 0)
2743 return error_type (pp);
2744 }
2745
2746 /* Now read the baseclasses, if any, read the regular C struct or C++
2747 class member fields, attach the fields to the type, read the C++
2748 member functions, attach them to the type, and then read any tilde
2749 field (baseclass specifier for the class holding the main vtable). */
2750
2751 if (!read_baseclasses (&fi, pp, type, objfile)
2752 || !read_struct_fields (&fi, pp, type, objfile)
2753 || !attach_fields_to_type (&fi, type, objfile)
2754 || !read_member_functions (&fi, pp, type, objfile)
2755 || !attach_fn_fields_to_type (&fi, type)
2756 || !read_tilde_fields (&fi, pp, type, objfile))
2757 {
2758 do_cleanups (back_to);
2759 return (error_type (pp));
2760 }
2761
2762 do_cleanups (back_to);
2763 return (type);
2764 }
2765
2766 /* Read a definition of an array type,
2767 and create and return a suitable type object.
2768 Also creates a range type which represents the bounds of that
2769 array. */
2770
2771 static struct type *
2772 read_array_type (pp, type, objfile)
2773 register char **pp;
2774 register struct type *type;
2775 struct objfile *objfile;
2776 {
2777 struct type *index_type, *element_type, *range_type;
2778 int lower, upper;
2779 int adjustable = 0;
2780 int nbits;
2781
2782 /* Format of an array type:
2783 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2784 to handle this.
2785
2786 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2787 for these, produce a type like float[][]. */
2788
2789 index_type = read_type (pp, objfile);
2790 if (**pp != ';')
2791 /* Improper format of array type decl. */
2792 return error_type (pp);
2793 ++*pp;
2794
2795 if (!(**pp >= '0' && **pp <= '9'))
2796 {
2797 (*pp)++;
2798 adjustable = 1;
2799 }
2800 lower = read_huge_number (pp, ';', &nbits);
2801 if (nbits != 0)
2802 return error_type (pp);
2803
2804 if (!(**pp >= '0' && **pp <= '9'))
2805 {
2806 (*pp)++;
2807 adjustable = 1;
2808 }
2809 upper = read_huge_number (pp, ';', &nbits);
2810 if (nbits != 0)
2811 return error_type (pp);
2812
2813 element_type = read_type (pp, objfile);
2814
2815 if (adjustable)
2816 {
2817 lower = 0;
2818 upper = -1;
2819 }
2820
2821 range_type =
2822 create_range_type ((struct type *) NULL, index_type, lower, upper);
2823 type = create_array_type (type, element_type, range_type);
2824
2825 /* If we have an array whose element type is not yet known, but whose
2826 bounds *are* known, record it to be adjusted at the end of the file. */
2827
2828 if (TYPE_LENGTH (element_type) == 0 && !adjustable)
2829 {
2830 add_undefined_type (type);
2831 }
2832
2833 return type;
2834 }
2835
2836
2837 /* Read a definition of an enumeration type,
2838 and create and return a suitable type object.
2839 Also defines the symbols that represent the values of the type. */
2840
2841 static struct type *
2842 read_enum_type (pp, type, objfile)
2843 register char **pp;
2844 register struct type *type;
2845 struct objfile *objfile;
2846 {
2847 register char *p;
2848 char *name;
2849 register long n;
2850 register struct symbol *sym;
2851 int nsyms = 0;
2852 struct pending **symlist;
2853 struct pending *osyms, *syms;
2854 int o_nsyms;
2855
2856 #if 0
2857 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2858 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2859 to do? For now, force all enum values to file scope. */
2860 if (within_function)
2861 symlist = &local_symbols;
2862 else
2863 #endif
2864 symlist = &file_symbols;
2865 osyms = *symlist;
2866 o_nsyms = osyms ? osyms->nsyms : 0;
2867
2868 /* Read the value-names and their values.
2869 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2870 A semicolon or comma instead of a NAME means the end. */
2871 while (**pp && **pp != ';' && **pp != ',')
2872 {
2873 int nbits;
2874 STABS_CONTINUE (pp);
2875 p = *pp;
2876 while (*p != ':') p++;
2877 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
2878 *pp = p + 1;
2879 n = read_huge_number (pp, ',', &nbits);
2880 if (nbits != 0)
2881 return error_type (pp);
2882
2883 sym = (struct symbol *)
2884 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
2885 memset (sym, 0, sizeof (struct symbol));
2886 SYMBOL_NAME (sym) = name;
2887 SYMBOL_LANGUAGE (sym) = current_subfile -> language;
2888 SYMBOL_CLASS (sym) = LOC_CONST;
2889 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2890 SYMBOL_VALUE (sym) = n;
2891 add_symbol_to_list (sym, symlist);
2892 nsyms++;
2893 }
2894
2895 if (**pp == ';')
2896 (*pp)++; /* Skip the semicolon. */
2897
2898 /* Now fill in the fields of the type-structure. */
2899
2900 TYPE_LENGTH (type) = sizeof (int);
2901 TYPE_CODE (type) = TYPE_CODE_ENUM;
2902 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2903 TYPE_NFIELDS (type) = nsyms;
2904 TYPE_FIELDS (type) = (struct field *)
2905 TYPE_ALLOC (type, sizeof (struct field) * nsyms);
2906 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
2907
2908 /* Find the symbols for the values and put them into the type.
2909 The symbols can be found in the symlist that we put them on
2910 to cause them to be defined. osyms contains the old value
2911 of that symlist; everything up to there was defined by us. */
2912 /* Note that we preserve the order of the enum constants, so
2913 that in something like "enum {FOO, LAST_THING=FOO}" we print
2914 FOO, not LAST_THING. */
2915
2916 for (syms = *symlist, n = 0; syms; syms = syms->next)
2917 {
2918 int j = 0;
2919 if (syms == osyms)
2920 j = o_nsyms;
2921 for (; j < syms->nsyms; j++,n++)
2922 {
2923 struct symbol *xsym = syms->symbol[j];
2924 SYMBOL_TYPE (xsym) = type;
2925 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2926 TYPE_FIELD_VALUE (type, n) = 0;
2927 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2928 TYPE_FIELD_BITSIZE (type, n) = 0;
2929 }
2930 if (syms == osyms)
2931 break;
2932 }
2933
2934 #if 0
2935 /* This screws up perfectly good C programs with enums. FIXME. */
2936 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2937 if(TYPE_NFIELDS(type) == 2 &&
2938 ((STREQ(TYPE_FIELD_NAME(type,0),"TRUE") &&
2939 STREQ(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2940 (STREQ(TYPE_FIELD_NAME(type,1),"TRUE") &&
2941 STREQ(TYPE_FIELD_NAME(type,0),"FALSE"))))
2942 TYPE_CODE(type) = TYPE_CODE_BOOL;
2943 #endif
2944
2945 return type;
2946 }
2947
2948 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2949 typedefs in every file (for int, long, etc):
2950
2951 type = b <signed> <width>; <offset>; <nbits>
2952 signed = u or s. Possible c in addition to u or s (for char?).
2953 offset = offset from high order bit to start bit of type.
2954 width is # bytes in object of this type, nbits is # bits in type.
2955
2956 The width/offset stuff appears to be for small objects stored in
2957 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2958 FIXME. */
2959
2960 static struct type *
2961 read_sun_builtin_type (pp, typenums, objfile)
2962 char **pp;
2963 int typenums[2];
2964 struct objfile *objfile;
2965 {
2966 int type_bits;
2967 int nbits;
2968 int signed_type;
2969
2970 switch (**pp)
2971 {
2972 case 's':
2973 signed_type = 1;
2974 break;
2975 case 'u':
2976 signed_type = 0;
2977 break;
2978 default:
2979 return error_type (pp);
2980 }
2981 (*pp)++;
2982
2983 /* For some odd reason, all forms of char put a c here. This is strange
2984 because no other type has this honor. We can safely ignore this because
2985 we actually determine 'char'acterness by the number of bits specified in
2986 the descriptor. */
2987
2988 if (**pp == 'c')
2989 (*pp)++;
2990
2991 /* The first number appears to be the number of bytes occupied
2992 by this type, except that unsigned short is 4 instead of 2.
2993 Since this information is redundant with the third number,
2994 we will ignore it. */
2995 read_huge_number (pp, ';', &nbits);
2996 if (nbits != 0)
2997 return error_type (pp);
2998
2999 /* The second number is always 0, so ignore it too. */
3000 read_huge_number (pp, ';', &nbits);
3001 if (nbits != 0)
3002 return error_type (pp);
3003
3004 /* The third number is the number of bits for this type. */
3005 type_bits = read_huge_number (pp, 0, &nbits);
3006 if (nbits != 0)
3007 return error_type (pp);
3008
3009 return init_type (type_bits == 0 ? TYPE_CODE_VOID : TYPE_CODE_INT,
3010 type_bits / TARGET_CHAR_BIT,
3011 signed_type ? 0 : TYPE_FLAG_UNSIGNED, (char *)NULL,
3012 objfile);
3013 }
3014
3015 static struct type *
3016 read_sun_floating_type (pp, typenums, objfile)
3017 char **pp;
3018 int typenums[2];
3019 struct objfile *objfile;
3020 {
3021 int nbits;
3022 int details;
3023 int nbytes;
3024
3025 /* The first number has more details about the type, for example
3026 FN_COMPLEX. */
3027 details = read_huge_number (pp, ';', &nbits);
3028 if (nbits != 0)
3029 return error_type (pp);
3030
3031 /* The second number is the number of bytes occupied by this type */
3032 nbytes = read_huge_number (pp, ';', &nbits);
3033 if (nbits != 0)
3034 return error_type (pp);
3035
3036 if (details == NF_COMPLEX || details == NF_COMPLEX16
3037 || details == NF_COMPLEX32)
3038 /* This is a type we can't handle, but we do know the size.
3039 We also will be able to give it a name. */
3040 return init_type (TYPE_CODE_ERROR, nbytes, 0, NULL, objfile);
3041
3042 return init_type (TYPE_CODE_FLT, nbytes, 0, NULL, objfile);
3043 }
3044
3045 /* Read a number from the string pointed to by *PP.
3046 The value of *PP is advanced over the number.
3047 If END is nonzero, the character that ends the
3048 number must match END, or an error happens;
3049 and that character is skipped if it does match.
3050 If END is zero, *PP is left pointing to that character.
3051
3052 If the number fits in a long, set *BITS to 0 and return the value.
3053 If not, set *BITS to be the number of bits in the number and return 0.
3054
3055 If encounter garbage, set *BITS to -1 and return 0. */
3056
3057 static long
3058 read_huge_number (pp, end, bits)
3059 char **pp;
3060 int end;
3061 int *bits;
3062 {
3063 char *p = *pp;
3064 int sign = 1;
3065 long n = 0;
3066 int radix = 10;
3067 char overflow = 0;
3068 int nbits = 0;
3069 int c;
3070 long upper_limit;
3071
3072 if (*p == '-')
3073 {
3074 sign = -1;
3075 p++;
3076 }
3077
3078 /* Leading zero means octal. GCC uses this to output values larger
3079 than an int (because that would be hard in decimal). */
3080 if (*p == '0')
3081 {
3082 radix = 8;
3083 p++;
3084 }
3085
3086 upper_limit = LONG_MAX / radix;
3087 while ((c = *p++) >= '0' && c < ('0' + radix))
3088 {
3089 if (n <= upper_limit)
3090 {
3091 n *= radix;
3092 n += c - '0'; /* FIXME this overflows anyway */
3093 }
3094 else
3095 overflow = 1;
3096
3097 /* This depends on large values being output in octal, which is
3098 what GCC does. */
3099 if (radix == 8)
3100 {
3101 if (nbits == 0)
3102 {
3103 if (c == '0')
3104 /* Ignore leading zeroes. */
3105 ;
3106 else if (c == '1')
3107 nbits = 1;
3108 else if (c == '2' || c == '3')
3109 nbits = 2;
3110 else
3111 nbits = 3;
3112 }
3113 else
3114 nbits += 3;
3115 }
3116 }
3117 if (end)
3118 {
3119 if (c && c != end)
3120 {
3121 if (bits != NULL)
3122 *bits = -1;
3123 return 0;
3124 }
3125 }
3126 else
3127 --p;
3128
3129 *pp = p;
3130 if (overflow)
3131 {
3132 if (nbits == 0)
3133 {
3134 /* Large decimal constants are an error (because it is hard to
3135 count how many bits are in them). */
3136 if (bits != NULL)
3137 *bits = -1;
3138 return 0;
3139 }
3140
3141 /* -0x7f is the same as 0x80. So deal with it by adding one to
3142 the number of bits. */
3143 if (sign == -1)
3144 ++nbits;
3145 if (bits)
3146 *bits = nbits;
3147 }
3148 else
3149 {
3150 if (bits)
3151 *bits = 0;
3152 return n * sign;
3153 }
3154 /* It's *BITS which has the interesting information. */
3155 return 0;
3156 }
3157
3158 static struct type *
3159 read_range_type (pp, typenums, objfile)
3160 char **pp;
3161 int typenums[2];
3162 struct objfile *objfile;
3163 {
3164 int rangenums[2];
3165 long n2, n3;
3166 int n2bits, n3bits;
3167 int self_subrange;
3168 struct type *result_type;
3169 struct type *index_type;
3170
3171 /* First comes a type we are a subrange of.
3172 In C it is usually 0, 1 or the type being defined. */
3173 /* FIXME: according to stabs.texinfo and AIX doc, this can be a type-id
3174 not just a type number. */
3175 if (read_type_number (pp, rangenums) != 0)
3176 return error_type (pp);
3177 self_subrange = (rangenums[0] == typenums[0] &&
3178 rangenums[1] == typenums[1]);
3179
3180 /* A semicolon should now follow; skip it. */
3181 if (**pp == ';')
3182 (*pp)++;
3183
3184 /* The remaining two operands are usually lower and upper bounds
3185 of the range. But in some special cases they mean something else. */
3186 n2 = read_huge_number (pp, ';', &n2bits);
3187 n3 = read_huge_number (pp, ';', &n3bits);
3188
3189 if (n2bits == -1 || n3bits == -1)
3190 return error_type (pp);
3191
3192 /* If limits are huge, must be large integral type. */
3193 if (n2bits != 0 || n3bits != 0)
3194 {
3195 char got_signed = 0;
3196 char got_unsigned = 0;
3197 /* Number of bits in the type. */
3198 int nbits = 0;
3199
3200 /* Range from 0 to <large number> is an unsigned large integral type. */
3201 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
3202 {
3203 got_unsigned = 1;
3204 nbits = n3bits;
3205 }
3206 /* Range from <large number> to <large number>-1 is a large signed
3207 integral type. Take care of the case where <large number> doesn't
3208 fit in a long but <large number>-1 does. */
3209 else if ((n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
3210 || (n2bits != 0 && n3bits == 0
3211 && (n2bits == sizeof (long) * HOST_CHAR_BIT)
3212 && n3 == LONG_MAX))
3213 {
3214 got_signed = 1;
3215 nbits = n2bits;
3216 }
3217
3218 if (got_signed || got_unsigned)
3219 {
3220 return init_type (TYPE_CODE_INT, nbits / TARGET_CHAR_BIT,
3221 got_unsigned ? TYPE_FLAG_UNSIGNED : 0, NULL,
3222 objfile);
3223 }
3224 else
3225 return error_type (pp);
3226 }
3227
3228 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3229 if (self_subrange && n2 == 0 && n3 == 0)
3230 return init_type (TYPE_CODE_VOID, 0, 0, NULL, objfile);
3231
3232 /* If n3 is zero and n2 is not, we want a floating type,
3233 and n2 is the width in bytes.
3234
3235 Fortran programs appear to use this for complex types also,
3236 and they give no way to distinguish between double and single-complex!
3237
3238 GDB does not have complex types.
3239
3240 Just return the complex as a float of that size. It won't work right
3241 for the complex values, but at least it makes the file loadable. */
3242
3243 if (n3 == 0 && n2 > 0)
3244 {
3245 return init_type (TYPE_CODE_FLT, n2, 0, NULL, objfile);
3246 }
3247
3248 /* If the upper bound is -1, it must really be an unsigned int. */
3249
3250 else if (n2 == 0 && n3 == -1)
3251 {
3252 /* It is unsigned int or unsigned long. */
3253 /* GCC 2.3.3 uses this for long long too, but that is just a GDB 3.5
3254 compatibility hack. */
3255 return init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3256 TYPE_FLAG_UNSIGNED, NULL, objfile);
3257 }
3258
3259 /* Special case: char is defined (Who knows why) as a subrange of
3260 itself with range 0-127. */
3261 else if (self_subrange && n2 == 0 && n3 == 127)
3262 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
3263
3264 /* We used to do this only for subrange of self or subrange of int. */
3265 else if (n2 == 0)
3266 {
3267 if (n3 < 0)
3268 /* n3 actually gives the size. */
3269 return init_type (TYPE_CODE_INT, - n3, TYPE_FLAG_UNSIGNED,
3270 NULL, objfile);
3271 if (n3 == 0xff)
3272 return init_type (TYPE_CODE_INT, 1, TYPE_FLAG_UNSIGNED, NULL, objfile);
3273 if (n3 == 0xffff)
3274 return init_type (TYPE_CODE_INT, 2, TYPE_FLAG_UNSIGNED, NULL, objfile);
3275
3276 /* -1 is used for the upper bound of (4 byte) "unsigned int" and
3277 "unsigned long", and we already checked for that,
3278 so don't need to test for it here. */
3279 }
3280 /* I think this is for Convex "long long". Since I don't know whether
3281 Convex sets self_subrange, I also accept that particular size regardless
3282 of self_subrange. */
3283 else if (n3 == 0 && n2 < 0
3284 && (self_subrange
3285 || n2 == - TARGET_LONG_LONG_BIT / TARGET_CHAR_BIT))
3286 return init_type (TYPE_CODE_INT, - n2, 0, NULL, objfile);
3287 else if (n2 == -n3 -1)
3288 {
3289 if (n3 == 0x7f)
3290 return init_type (TYPE_CODE_INT, 1, 0, NULL, objfile);
3291 if (n3 == 0x7fff)
3292 return init_type (TYPE_CODE_INT, 2, 0, NULL, objfile);
3293 if (n3 == 0x7fffffff)
3294 return init_type (TYPE_CODE_INT, 4, 0, NULL, objfile);
3295 }
3296
3297 /* We have a real range type on our hands. Allocate space and
3298 return a real pointer. */
3299
3300 /* At this point I don't have the faintest idea how to deal with
3301 a self_subrange type; I'm going to assume that this is used
3302 as an idiom, and that all of them are special cases. So . . . */
3303 if (self_subrange)
3304 return error_type (pp);
3305
3306 index_type = *dbx_lookup_type (rangenums);
3307 if (index_type == NULL)
3308 {
3309 /* Does this actually ever happen? Is that why we are worrying
3310 about dealing with it rather than just calling error_type? */
3311
3312 static struct type *range_type_index;
3313
3314 complain (&range_type_base_complaint, rangenums[1]);
3315 if (range_type_index == NULL)
3316 range_type_index =
3317 init_type (TYPE_CODE_INT, TARGET_INT_BIT / TARGET_CHAR_BIT,
3318 0, "range type index type", NULL);
3319 index_type = range_type_index;
3320 }
3321
3322 result_type = create_range_type ((struct type *) NULL, index_type, n2, n3);
3323 return (result_type);
3324 }
3325
3326 /* Read in an argument list. This is a list of types, separated by commas
3327 and terminated with END. Return the list of types read in, or (struct type
3328 **)-1 if there is an error. */
3329
3330 static struct type **
3331 read_args (pp, end, objfile)
3332 char **pp;
3333 int end;
3334 struct objfile *objfile;
3335 {
3336 /* FIXME! Remove this arbitrary limit! */
3337 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
3338 int n = 0;
3339
3340 while (**pp != end)
3341 {
3342 if (**pp != ',')
3343 /* Invalid argument list: no ','. */
3344 return (struct type **)-1;
3345 (*pp)++;
3346 STABS_CONTINUE (pp);
3347 types[n++] = read_type (pp, objfile);
3348 }
3349 (*pp)++; /* get past `end' (the ':' character) */
3350
3351 if (n == 1)
3352 {
3353 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3354 }
3355 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3356 {
3357 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3358 memset (rval + n, 0, sizeof (struct type *));
3359 }
3360 else
3361 {
3362 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3363 }
3364 memcpy (rval, types, n * sizeof (struct type *));
3365 return rval;
3366 }
3367 \f
3368 /* Common block handling. */
3369
3370 /* List of symbols declared since the last BCOMM. This list is a tail
3371 of local_symbols. When ECOMM is seen, the symbols on the list
3372 are noted so their proper addresses can be filled in later,
3373 using the common block base address gotten from the assembler
3374 stabs. */
3375
3376 static struct pending *common_block;
3377 static int common_block_i;
3378
3379 /* Name of the current common block. We get it from the BCOMM instead of the
3380 ECOMM to match IBM documentation (even though IBM puts the name both places
3381 like everyone else). */
3382 static char *common_block_name;
3383
3384 /* Process a N_BCOMM symbol. The storage for NAME is not guaranteed
3385 to remain after this function returns. */
3386
3387 void
3388 common_block_start (name, objfile)
3389 char *name;
3390 struct objfile *objfile;
3391 {
3392 if (common_block_name != NULL)
3393 {
3394 static struct complaint msg = {
3395 "Invalid symbol data: common block within common block",
3396 0, 0};
3397 complain (&msg);
3398 }
3399 common_block = local_symbols;
3400 common_block_i = local_symbols ? local_symbols->nsyms : 0;
3401 common_block_name = obsavestring (name, strlen (name),
3402 &objfile -> symbol_obstack);
3403 }
3404
3405 /* Process a N_ECOMM symbol. */
3406
3407 void
3408 common_block_end (objfile)
3409 struct objfile *objfile;
3410 {
3411 /* Symbols declared since the BCOMM are to have the common block
3412 start address added in when we know it. common_block and
3413 common_block_i point to the first symbol after the BCOMM in
3414 the local_symbols list; copy the list and hang it off the
3415 symbol for the common block name for later fixup. */
3416 int i;
3417 struct symbol *sym;
3418 struct pending *new = 0;
3419 struct pending *next;
3420 int j;
3421
3422 if (common_block_name == NULL)
3423 {
3424 static struct complaint msg = {"ECOMM symbol unmatched by BCOMM", 0, 0};
3425 complain (&msg);
3426 return;
3427 }
3428
3429 sym = (struct symbol *)
3430 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
3431 memset (sym, 0, sizeof (struct symbol));
3432 SYMBOL_NAME (sym) = common_block_name;
3433 SYMBOL_CLASS (sym) = LOC_BLOCK;
3434
3435 /* Now we copy all the symbols which have been defined since the BCOMM. */
3436
3437 /* Copy all the struct pendings before common_block. */
3438 for (next = local_symbols;
3439 next != NULL && next != common_block;
3440 next = next->next)
3441 {
3442 for (j = 0; j < next->nsyms; j++)
3443 add_symbol_to_list (next->symbol[j], &new);
3444 }
3445
3446 /* Copy however much of COMMON_BLOCK we need. If COMMON_BLOCK is
3447 NULL, it means copy all the local symbols (which we already did
3448 above). */
3449
3450 if (common_block != NULL)
3451 for (j = common_block_i; j < common_block->nsyms; j++)
3452 add_symbol_to_list (common_block->symbol[j], &new);
3453
3454 SYMBOL_NAMESPACE (sym) = (enum namespace)((long) new);
3455
3456 /* Should we be putting local_symbols back to what it was?
3457 Does it matter? */
3458
3459 i = hashname (SYMBOL_NAME (sym));
3460 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
3461 global_sym_chain[i] = sym;
3462 common_block_name = NULL;
3463 }
3464
3465 /* Add a common block's start address to the offset of each symbol
3466 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3467 the common block name). */
3468
3469 static void
3470 fix_common_block (sym, valu)
3471 struct symbol *sym;
3472 int valu;
3473 {
3474 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
3475 for ( ; next; next = next->next)
3476 {
3477 register int j;
3478 for (j = next->nsyms - 1; j >= 0; j--)
3479 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3480 }
3481 }
3482
3483
3484 \f
3485 /* What about types defined as forward references inside of a small lexical
3486 scope? */
3487 /* Add a type to the list of undefined types to be checked through
3488 once this file has been read in. */
3489
3490 void
3491 add_undefined_type (type)
3492 struct type *type;
3493 {
3494 if (undef_types_length == undef_types_allocated)
3495 {
3496 undef_types_allocated *= 2;
3497 undef_types = (struct type **)
3498 xrealloc ((char *) undef_types,
3499 undef_types_allocated * sizeof (struct type *));
3500 }
3501 undef_types[undef_types_length++] = type;
3502 }
3503
3504 /* Go through each undefined type, see if it's still undefined, and fix it
3505 up if possible. We have two kinds of undefined types:
3506
3507 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
3508 Fix: update array length using the element bounds
3509 and the target type's length.
3510 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
3511 yet defined at the time a pointer to it was made.
3512 Fix: Do a full lookup on the struct/union tag. */
3513 void
3514 cleanup_undefined_types ()
3515 {
3516 struct type **type;
3517
3518 for (type = undef_types; type < undef_types + undef_types_length; type++)
3519 {
3520 switch (TYPE_CODE (*type))
3521 {
3522
3523 case TYPE_CODE_STRUCT:
3524 case TYPE_CODE_UNION:
3525 case TYPE_CODE_ENUM:
3526 {
3527 /* Check if it has been defined since. */
3528 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
3529 {
3530 struct pending *ppt;
3531 int i;
3532 /* Name of the type, without "struct" or "union" */
3533 char *typename = TYPE_TAG_NAME (*type);
3534
3535 if (typename == NULL)
3536 {
3537 static struct complaint msg = {"need a type name", 0, 0};
3538 complain (&msg);
3539 break;
3540 }
3541 for (ppt = file_symbols; ppt; ppt = ppt->next)
3542 {
3543 for (i = 0; i < ppt->nsyms; i++)
3544 {
3545 struct symbol *sym = ppt->symbol[i];
3546
3547 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
3548 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
3549 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
3550 TYPE_CODE (*type))
3551 && STREQ (SYMBOL_NAME (sym), typename))
3552 {
3553 memcpy (*type, SYMBOL_TYPE (sym),
3554 sizeof (struct type));
3555 }
3556 }
3557 }
3558 }
3559 }
3560 break;
3561
3562 case TYPE_CODE_ARRAY:
3563 {
3564 struct type *range_type;
3565 int lower, upper;
3566
3567 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
3568 goto badtype;
3569 if (TYPE_NFIELDS (*type) != 1)
3570 goto badtype;
3571 range_type = TYPE_FIELD_TYPE (*type, 0);
3572 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
3573 goto badtype;
3574
3575 /* Now recompute the length of the array type, based on its
3576 number of elements and the target type's length. */
3577 lower = TYPE_FIELD_BITPOS (range_type, 0);
3578 upper = TYPE_FIELD_BITPOS (range_type, 1);
3579 TYPE_LENGTH (*type) = (upper - lower + 1)
3580 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
3581 }
3582 break;
3583
3584 default:
3585 badtype:
3586 {
3587 static struct complaint msg = {"\
3588 GDB internal error. cleanup_undefined_types with bad type %d.", 0, 0};
3589 complain (&msg, TYPE_CODE (*type));
3590 }
3591 break;
3592 }
3593 }
3594 undef_types_length = 0;
3595 }
3596
3597 /* Scan through all of the global symbols defined in the object file,
3598 assigning values to the debugging symbols that need to be assigned
3599 to. Get these symbols from the minimal symbol table. */
3600
3601 void
3602 scan_file_globals (objfile)
3603 struct objfile *objfile;
3604 {
3605 int hash;
3606 struct minimal_symbol *msymbol;
3607 struct symbol *sym, *prev;
3608
3609 if (objfile->msymbols == 0) /* Beware the null file. */
3610 return;
3611
3612 for (msymbol = objfile -> msymbols; SYMBOL_NAME (msymbol) != NULL; msymbol++)
3613 {
3614 QUIT;
3615
3616 prev = NULL;
3617
3618 /* Get the hash index and check all the symbols
3619 under that hash index. */
3620
3621 hash = hashname (SYMBOL_NAME (msymbol));
3622
3623 for (sym = global_sym_chain[hash]; sym;)
3624 {
3625 if (SYMBOL_NAME (msymbol)[0] == SYMBOL_NAME (sym)[0] &&
3626 STREQ(SYMBOL_NAME (msymbol) + 1, SYMBOL_NAME (sym) + 1))
3627 {
3628 /* Splice this symbol out of the hash chain and
3629 assign the value we have to it. */
3630 if (prev)
3631 {
3632 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
3633 }
3634 else
3635 {
3636 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
3637 }
3638
3639 /* Check to see whether we need to fix up a common block. */
3640 /* Note: this code might be executed several times for
3641 the same symbol if there are multiple references. */
3642
3643 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
3644 {
3645 fix_common_block (sym, SYMBOL_VALUE_ADDRESS (msymbol));
3646 }
3647 else
3648 {
3649 SYMBOL_VALUE_ADDRESS (sym) = SYMBOL_VALUE_ADDRESS (msymbol);
3650 }
3651
3652 if (prev)
3653 {
3654 sym = SYMBOL_VALUE_CHAIN (prev);
3655 }
3656 else
3657 {
3658 sym = global_sym_chain[hash];
3659 }
3660 }
3661 else
3662 {
3663 prev = sym;
3664 sym = SYMBOL_VALUE_CHAIN (sym);
3665 }
3666 }
3667 }
3668 }
3669
3670 /* Initialize anything that needs initializing when starting to read
3671 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
3672 to a psymtab. */
3673
3674 void
3675 stabsread_init ()
3676 {
3677 }
3678
3679 /* Initialize anything that needs initializing when a completely new
3680 symbol file is specified (not just adding some symbols from another
3681 file, e.g. a shared library). */
3682
3683 void
3684 stabsread_new_init ()
3685 {
3686 /* Empty the hash table of global syms looking for values. */
3687 memset (global_sym_chain, 0, sizeof (global_sym_chain));
3688 }
3689
3690 /* Initialize anything that needs initializing at the same time as
3691 start_symtab() is called. */
3692
3693 void start_stabs ()
3694 {
3695 global_stabs = NULL; /* AIX COFF */
3696 /* Leave FILENUM of 0 free for builtin types and this file's types. */
3697 n_this_object_header_files = 1;
3698 type_vector_length = 0;
3699 type_vector = (struct type **) 0;
3700
3701 /* FIXME: If common_block_name is not already NULL, we should complain(). */
3702 common_block_name = NULL;
3703 }
3704
3705 /* Call after end_symtab() */
3706
3707 void end_stabs ()
3708 {
3709 if (type_vector)
3710 {
3711 free ((char *) type_vector);
3712 }
3713 type_vector = 0;
3714 type_vector_length = 0;
3715 previous_stab_code = 0;
3716 }
3717
3718 void
3719 finish_global_stabs (objfile)
3720 struct objfile *objfile;
3721 {
3722 if (global_stabs)
3723 {
3724 patch_block_stabs (global_symbols, global_stabs, objfile);
3725 free ((PTR) global_stabs);
3726 global_stabs = NULL;
3727 }
3728 }
3729
3730 /* Initializer for this module */
3731
3732 void
3733 _initialize_stabsread ()
3734 {
3735 undef_types_allocated = 20;
3736 undef_types_length = 0;
3737 undef_types = (struct type **)
3738 xmalloc (undef_types_allocated * sizeof (struct type *));
3739 }
This page took 0.143978 seconds and 4 git commands to generate.