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