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