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