* breakpoint.c (enable_longjmp_breakpoint,
[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
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" /* Needed for "struct complaint" */
33 #include "objfiles.h"
34 #include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
35 #include "buildsym.h"
36
37 /* Ask stabsread.h to define the vars it normally declares `extern'. */
38 #define EXTERN /**/
39 #include "stabsread.h" /* Our own declarations */
40 #undef EXTERN
41
42 static struct type *
43 dbx_alloc_type PARAMS ((int [2], struct objfile *));
44
45 static void
46 read_huge_number PARAMS ((char **, int, long *, int *));
47
48 static void
49 patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
50 struct objfile *));
51
52 static void
53 fix_common_block PARAMS ((struct symbol *, int));
54
55 static struct type *
56 read_range_type PARAMS ((char **, int [2], struct objfile *));
57
58 static struct type *
59 read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *));
60
61 static struct type *
62 read_sun_floating_type PARAMS ((char **, int [2], struct objfile *));
63
64 static struct type *
65 read_enum_type PARAMS ((char **, struct type *, struct objfile *));
66
67 static struct type *
68 read_struct_type PARAMS ((char **, struct type *, struct objfile *));
69
70 static struct type *
71 read_array_type PARAMS ((char **, struct type *, struct objfile *));
72
73 static struct type **
74 read_args PARAMS ((char **, int, struct objfile *));
75
76 static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
77 static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
78
79 /* Define this as 1 if a pcc declaration of a char or short argument
80 gives the correct address. Otherwise assume pcc gives the
81 address of the corresponding int, which is not the same on a
82 big-endian machine. */
83
84 #ifndef BELIEVE_PCC_PROMOTION
85 #define BELIEVE_PCC_PROMOTION 0
86 #endif
87
88 /* During some calls to read_type (and thus to read_range_type), this
89 contains the name of the type being defined. Range types are only
90 used in C as basic types. We use the name to distinguish the otherwise
91 identical basic types "int" and "long" and their unsigned versions.
92 FIXME, this should disappear with better type management. */
93
94 static char *long_kludge_name;
95
96 #if 0
97 struct complaint dbx_class_complaint =
98 {
99 "encountered DBX-style class variable debugging information.\n\
100 You seem to have compiled your program with \
101 \"g++ -g0\" instead of \"g++ -g\".\n\
102 Therefore GDB will not know about your class variables", 0, 0
103 };
104 #endif
105
106 struct complaint invalid_cpp_abbrev_complaint =
107 {"invalid C++ abbreviation `%s'", 0, 0};
108
109 struct complaint invalid_cpp_type_complaint =
110 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
111
112 struct complaint member_fn_complaint =
113 {"member function type missing, got '%c'", 0, 0};
114
115 struct complaint const_vol_complaint =
116 {"const/volatile indicator missing, got '%c'", 0, 0};
117
118 struct complaint error_type_complaint =
119 {"debug info mismatch between compiler and debugger", 0, 0};
120
121 struct complaint invalid_member_complaint =
122 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
123
124 struct complaint range_type_base_complaint =
125 {"base type %d of range type is not defined", 0, 0};
126
127 struct complaint reg_value_complaint =
128 {"register number too large in symbol %s", 0, 0};
129
130 /* Make a list of forward references which haven't been defined. */
131
132 static struct type **undef_types;
133 static int undef_types_allocated;
134 static int undef_types_length;
135
136 \f
137 int
138 hashname (name)
139 char *name;
140 {
141 register char *p = name;
142 register int total = p[0];
143 register int c;
144
145 c = p[1];
146 total += c << 2;
147 if (c)
148 {
149 c = p[2];
150 total += c << 4;
151 if (c)
152 {
153 total += p[3] << 6;
154 }
155 }
156
157 /* Ensure result is positive. */
158 if (total < 0)
159 {
160 total += (1000 << 6);
161 }
162 return (total % HASHSIZE);
163 }
164
165 \f
166 /* Look up a dbx type-number pair. Return the address of the slot
167 where the type for that number-pair is stored.
168 The number-pair is in TYPENUMS.
169
170 This can be used for finding the type associated with that pair
171 or for associating a new type with the pair. */
172
173 struct type **
174 dbx_lookup_type (typenums)
175 int typenums[2];
176 {
177 register int filenum = typenums[0];
178 register int index = typenums[1];
179 unsigned old_len;
180 register int real_filenum;
181 register struct header_file *f;
182 int f_orig_length;
183
184 if (filenum == -1) /* -1,-1 is for temporary types. */
185 return 0;
186
187 if (filenum < 0 || filenum >= n_this_object_header_files)
188 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
189 filenum, index, symnum);
190
191 if (filenum == 0)
192 {
193 /* Type is defined outside of header files.
194 Find it in this object file's type vector. */
195 if (index >= type_vector_length)
196 {
197 old_len = type_vector_length;
198 if (old_len == 0)
199 {
200 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
201 type_vector = (struct type **)
202 malloc (type_vector_length * sizeof (struct type *));
203 }
204 while (index >= type_vector_length)
205 {
206 type_vector_length *= 2;
207 }
208 type_vector = (struct type **)
209 xrealloc ((char *) type_vector,
210 (type_vector_length * sizeof (struct type *)));
211 memset (&type_vector[old_len], 0,
212 (type_vector_length - old_len) * sizeof (struct type *));
213 }
214 return (&type_vector[index]);
215 }
216 else
217 {
218 real_filenum = this_object_header_files[filenum];
219
220 if (real_filenum >= n_header_files)
221 {
222 abort ();
223 }
224
225 f = &header_files[real_filenum];
226
227 f_orig_length = f->length;
228 if (index >= f_orig_length)
229 {
230 while (index >= f->length)
231 {
232 f->length *= 2;
233 }
234 f->vector = (struct type **)
235 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
236 memset (&f->vector[f_orig_length], 0,
237 (f->length - f_orig_length) * sizeof (struct type *));
238 }
239 return (&f->vector[index]);
240 }
241 }
242
243 /* Make sure there is a type allocated for type numbers TYPENUMS
244 and return the type object.
245 This can create an empty (zeroed) type object.
246 TYPENUMS may be (-1, -1) to return a new type object that is not
247 put into the type vector, and so may not be referred to by number. */
248
249 static struct type *
250 dbx_alloc_type (typenums, objfile)
251 int typenums[2];
252 struct objfile *objfile;
253 {
254 register struct type **type_addr;
255
256 if (typenums[0] == -1)
257 {
258 return (alloc_type (objfile));
259 }
260
261 type_addr = dbx_lookup_type (typenums);
262
263 /* If we are referring to a type not known at all yet,
264 allocate an empty type for it.
265 We will fill it in later if we find out how. */
266 if (*type_addr == 0)
267 {
268 *type_addr = alloc_type (objfile);
269 }
270
271 return (*type_addr);
272 }
273
274 /* for all the stabs in a given stab vector, build appropriate types
275 and fix their symbols in given symbol vector. */
276
277 static void
278 patch_block_stabs (symbols, stabs, objfile)
279 struct pending *symbols;
280 struct pending_stabs *stabs;
281 struct objfile *objfile;
282 {
283 int ii;
284 char *name;
285 char *pp;
286 struct symbol *sym;
287
288 if (stabs)
289 {
290
291 /* for all the stab entries, find their corresponding symbols and
292 patch their types! */
293
294 for (ii = 0; ii < stabs->count; ++ii)
295 {
296 name = stabs->stab[ii];
297 pp = (char*) strchr (name, ':');
298 sym = find_symbol_in_list (symbols, name, pp-name);
299 if (!sym)
300 {
301 #ifndef IBM6000_TARGET
302 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
303 #endif
304 }
305 else
306 {
307 pp += 2;
308 if (*(pp-1) == 'F' || *(pp-1) == 'f')
309 {
310 SYMBOL_TYPE (sym) =
311 lookup_function_type (read_type (&pp, objfile));
312 }
313 else
314 {
315 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
316 }
317 }
318 }
319 }
320 }
321
322 \f
323 /* Read a number by which a type is referred to in dbx data,
324 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
325 Just a single number N is equivalent to (0,N).
326 Return the two numbers by storing them in the vector TYPENUMS.
327 TYPENUMS will then be used as an argument to dbx_lookup_type. */
328
329 void
330 read_type_number (pp, typenums)
331 register char **pp;
332 register int *typenums;
333 {
334 if (**pp == '(')
335 {
336 (*pp)++;
337 typenums[0] = read_number (pp, ',');
338 typenums[1] = read_number (pp, ')');
339 }
340 else
341 {
342 typenums[0] = 0;
343 typenums[1] = read_number (pp, 0);
344 }
345 }
346
347 \f
348 /* To handle GNU C++ typename abbreviation, we need to be able to
349 fill in a type's name as soon as space for that type is allocated.
350 `type_synonym_name' is the name of the type being allocated.
351 It is cleared as soon as it is used (lest all allocated types
352 get this name). */
353
354 static char *type_synonym_name;
355
356 /* ARGSUSED */
357 struct symbol *
358 define_symbol (valu, string, desc, type, objfile)
359 unsigned int valu;
360 char *string;
361 int desc;
362 int type;
363 struct objfile *objfile;
364 {
365 register struct symbol *sym;
366 char *p = (char *) strchr (string, ':');
367 int deftype;
368 int synonym = 0;
369 register int i;
370 struct type *temptype;
371
372 /* We would like to eliminate nameless symbols, but keep their types.
373 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
374 to type 2, but, should not creat a symbol to address that type. Since
375 the symbol will be nameless, there is no way any user can refer to it. */
376
377 int nameless;
378
379 /* Ignore syms with empty names. */
380 if (string[0] == 0)
381 return 0;
382
383 /* Ignore old-style symbols from cc -go */
384 if (p == 0)
385 return 0;
386
387 /* If a nameless stab entry, all we need is the type, not the symbol.
388 e.g. ":t10=*2" */
389 nameless = (p == string);
390
391 sym = (struct symbol *)
392 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
393 memset (sym, 0, sizeof (struct symbol));
394
395 if (processing_gcc_compilation)
396 {
397 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
398 number of bytes occupied by a type or object, which we ignore. */
399 SYMBOL_LINE(sym) = desc;
400 }
401 else
402 {
403 SYMBOL_LINE(sym) = 0; /* unknown */
404 }
405
406 if (string[0] == CPLUS_MARKER)
407 {
408 /* Special GNU C++ names. */
409 switch (string[1])
410 {
411 case 't':
412 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
413 &objfile -> symbol_obstack);
414 break;
415
416 case 'v': /* $vtbl_ptr_type */
417 /* Was: SYMBOL_NAME (sym) = "vptr"; */
418 goto normal;
419
420 case 'e':
421 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
422 &objfile -> symbol_obstack);
423 break;
424
425 case '_':
426 /* This was an anonymous type that was never fixed up. */
427 goto normal;
428
429 default:
430 abort ();
431 }
432 }
433 else
434 {
435 normal:
436 SYMBOL_NAME (sym) = (char *)
437 obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
438 /* Open-coded bcopy--saves function call time. */
439 {
440 register char *p1 = string;
441 register char *p2 = SYMBOL_NAME (sym);
442 while (p1 != p)
443 {
444 *p2++ = *p1++;
445 }
446 *p2++ = '\0';
447 }
448 }
449 p++;
450 /* Determine the type of name being defined. */
451 /* The Acorn RISC machine's compiler can put out locals that don't
452 start with "234=" or "(3,4)=", so assume anything other than the
453 deftypes we know how to handle is a local. */
454 /* (Peter Watkins @ Computervision)
455 Handle Sun-style local fortran array types 'ar...' .
456 (gnu@cygnus.com) -- this strchr() handles them properly?
457 (tiemann@cygnus.com) -- 'C' is for catch. */
458
459 #ifdef IBM6000_TARGET
460
461 /* 'R' is for register parameters. */
462
463 if (!strchr ("cfFGpPrStTvVXCR", *p))
464
465 #else
466
467 if (!strchr ("cfFGpPrStTvVXC", *p))
468
469 #endif
470 deftype = 'l';
471 else
472 deftype = *p++;
473
474 /* c is a special case, not followed by a type-number.
475 SYMBOL:c=iVALUE for an integer constant symbol.
476 SYMBOL:c=rVALUE for a floating constant symbol.
477 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
478 e.g. "b:c=e6,0" for "const b = blob1"
479 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
480 if (deftype == 'c')
481 {
482 if (*p++ != '=')
483 error ("Invalid symbol data at symtab pos %d.", symnum);
484 switch (*p++)
485 {
486 case 'r':
487 {
488 double d = atof (p);
489 char *dbl_valu;
490
491 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
492 FT_DBL_PREC_FLOAT);
493 dbl_valu = (char *)
494 obstack_alloc (&objfile -> type_obstack, sizeof (double));
495 memcpy (dbl_valu, &d, sizeof (double));
496 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
497 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
498 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
499 }
500 break;
501 case 'i':
502 {
503 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
504 FT_INTEGER);
505 SYMBOL_VALUE (sym) = atoi (p);
506 SYMBOL_CLASS (sym) = LOC_CONST;
507 }
508 break;
509 case 'e':
510 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
511 e.g. "b:c=e6,0" for "const b = blob1"
512 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
513 {
514 int typenums[2];
515
516 read_type_number (&p, typenums);
517 if (*p++ != ',')
518 error ("Invalid symbol data: no comma in enum const symbol");
519
520 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
521 SYMBOL_VALUE (sym) = atoi (p);
522 SYMBOL_CLASS (sym) = LOC_CONST;
523 }
524 break;
525 default:
526 error ("Invalid symbol data at symtab pos %d.", symnum);
527 }
528 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
529 add_symbol_to_list (sym, &file_symbols);
530 return sym;
531 }
532
533 /* Now usually comes a number that says which data type,
534 and possibly more stuff to define the type
535 (all of which is handled by read_type) */
536
537 if (deftype == 'p' && *p == 'F')
538 /* pF is a two-letter code that means a function parameter in Fortran.
539 The type-number specifies the type of the return value.
540 Translate it into a pointer-to-function type. */
541 {
542 p++;
543 SYMBOL_TYPE (sym)
544 = lookup_pointer_type (lookup_function_type (read_type (&p, objfile)));
545 }
546
547 #ifdef IBM6000_TARGET
548 else if (deftype == 'R')
549 SYMBOL_TYPE (sym) = read_type (&p, objfile);
550 #endif
551
552 else
553 {
554 /* The symbol class letter is followed by a type (typically the
555 type of the symbol, or its return-type, or etc). Read it. */
556
557 synonym = *p == 't';
558
559 if (synonym)
560 {
561 p += 1;
562 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
563 strlen (SYMBOL_NAME (sym)),
564 &objfile -> symbol_obstack);
565 }
566
567 /* Here we save the name of the symbol for read_range_type, which
568 ends up reading in the basic types. In stabs, unfortunately there
569 is no distinction between "int" and "long" types except their
570 names. Until we work out a saner type policy (eliminating most
571 builtin types and using the names specified in the files), we
572 save away the name so that far away from here in read_range_type,
573 we can examine it to decide between "int" and "long". FIXME. */
574 long_kludge_name = SYMBOL_NAME (sym);
575
576 SYMBOL_TYPE (sym) = read_type (&p, objfile);
577 }
578
579 switch (deftype)
580 {
581 case 'C':
582 /* The name of a caught exception. */
583 SYMBOL_CLASS (sym) = LOC_LABEL;
584 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
585 SYMBOL_VALUE_ADDRESS (sym) = valu;
586 add_symbol_to_list (sym, &local_symbols);
587 break;
588
589 case 'f':
590 /* A static function definition. */
591 SYMBOL_CLASS (sym) = LOC_BLOCK;
592 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
593 add_symbol_to_list (sym, &file_symbols);
594 /* fall into process_function_types. */
595
596 process_function_types:
597 /* Function result types are described as the result type in stabs.
598 We need to convert this to the function-returning-type-X type
599 in GDB. E.g. "int" is converted to "function returning int". */
600 if (TYPE_CODE (SYMBOL_TYPE (sym)) != TYPE_CODE_FUNC)
601 {
602 #if 0
603 /* This code doesn't work -- it needs to realloc and can't. */
604 /* Attempt to set up to record a function prototype... */
605 struct type *new = (struct type *)
606 obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
607
608 /* Generate a template for the type of this function. The
609 types of the arguments will be added as we read the symbol
610 table. */
611 *new = *lookup_function_type (SYMBOL_TYPE(sym));
612 SYMBOL_TYPE(sym) = new;
613 TYPE_OBJFILE (new) = objfile;
614 in_function_type = new;
615 #else
616 SYMBOL_TYPE (sym) = lookup_function_type (SYMBOL_TYPE (sym));
617 #endif
618 }
619 /* fall into process_prototype_types */
620
621 process_prototype_types:
622 /* Sun acc puts declared types of arguments here. We don't care
623 about their actual types (FIXME -- we should remember the whole
624 function prototype), but the list may define some new types
625 that we have to remember, so we must scan it now. */
626 while (*p == ';') {
627 p++;
628 read_type (&p, objfile);
629 }
630 break;
631
632 case 'F':
633 /* A global function definition. */
634 SYMBOL_CLASS (sym) = LOC_BLOCK;
635 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
636 add_symbol_to_list (sym, &global_symbols);
637 goto process_function_types;
638
639 case 'G':
640 /* For a class G (global) symbol, it appears that the
641 value is not correct. It is necessary to search for the
642 corresponding linker definition to find the value.
643 These definitions appear at the end of the namelist. */
644 i = hashname (SYMBOL_NAME (sym));
645 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
646 global_sym_chain[i] = sym;
647 SYMBOL_CLASS (sym) = LOC_STATIC;
648 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
649 add_symbol_to_list (sym, &global_symbols);
650 break;
651
652 /* This case is faked by a conditional above,
653 when there is no code letter in the dbx data.
654 Dbx data never actually contains 'l'. */
655 case 'l':
656 SYMBOL_CLASS (sym) = LOC_LOCAL;
657 SYMBOL_VALUE (sym) = valu;
658 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
659 add_symbol_to_list (sym, &local_symbols);
660 break;
661
662 case 'p':
663 /* Normally this is a parameter, a LOC_ARG. On the i960, it
664 can also be a LOC_LOCAL_ARG depending on symbol type. */
665 #ifndef DBX_PARM_SYMBOL_CLASS
666 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
667 #endif
668 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
669 SYMBOL_VALUE (sym) = valu;
670 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
671 #if 0
672 /* This doesn't work yet. */
673 add_param_to_type (&in_function_type, sym);
674 #endif
675 add_symbol_to_list (sym, &local_symbols);
676
677 /* If it's gcc-compiled, if it says `short', believe it. */
678 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
679 break;
680
681 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
682 /* This macro is defined on machines (e.g. sparc) where
683 we should believe the type of a PCC 'short' argument,
684 but shouldn't believe the address (the address is
685 the address of the corresponding int). Note that
686 this is only different from the BELIEVE_PCC_PROMOTION
687 case on big-endian machines.
688
689 My guess is that this correction, as opposed to changing
690 the parameter to an 'int' (as done below, for PCC
691 on most machines), is the right thing to do
692 on all machines, but I don't want to risk breaking
693 something that already works. On most PCC machines,
694 the sparc problem doesn't come up because the calling
695 function has to zero the top bytes (not knowing whether
696 the called function wants an int or a short), so there
697 is no practical difference between an int and a short
698 (except perhaps what happens when the GDB user types
699 "print short_arg = 0x10000;").
700
701 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
702 actually produces the correct address (we don't need to fix it
703 up). I made this code adapt so that it will offset the symbol
704 if it was pointing at an int-aligned location and not
705 otherwise. This way you can use the same gdb for 4.0.x and
706 4.1 systems.
707
708 If the parameter is shorter than an int, and is integral
709 (e.g. char, short, or unsigned equivalent), and is claimed to
710 be passed on an integer boundary, don't believe it! Offset the
711 parameter's address to the tail-end of that integer. */
712
713 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
714 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
715 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
716 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
717 {
718 SYMBOL_VALUE (sym) += TYPE_LENGTH (temptype)
719 - TYPE_LENGTH (SYMBOL_TYPE (sym));
720 }
721 break;
722
723 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
724
725 /* If PCC says a parameter is a short or a char,
726 it is really an int. */
727 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
728 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
729 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
730 {
731 SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym))
732 ? lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER)
733 : temptype;
734 }
735 break;
736
737 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
738
739 case 'P':
740 /* acc seems to use P to delare the prototypes of functions that
741 are referenced by this file. gdb is not prepared to deal
742 with this extra information. FIXME, it ought to. */
743 if (type == N_FUN)
744 goto process_prototype_types;
745
746 /* Parameter which is in a register. */
747 SYMBOL_CLASS (sym) = LOC_REGPARM;
748 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
749 if (SYMBOL_VALUE (sym) >= NUM_REGS)
750 {
751 complain (&reg_value_complaint, SYMBOL_NAME (sym));
752 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
753 }
754 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
755 add_symbol_to_list (sym, &local_symbols);
756 break;
757
758 #ifdef IBM6000_TARGET
759 case 'R':
760 #endif
761 case 'r':
762 /* Register variable (either global or local). */
763 SYMBOL_CLASS (sym) = LOC_REGISTER;
764 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
765 if (SYMBOL_VALUE (sym) >= NUM_REGS)
766 {
767 complain (&reg_value_complaint, SYMBOL_NAME (sym));
768 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
769 }
770 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
771 if (within_function)
772 add_symbol_to_list (sym, &local_symbols);
773 else
774 add_symbol_to_list (sym, &file_symbols);
775 break;
776
777 case 'S':
778 /* Static symbol at top level of file */
779 SYMBOL_CLASS (sym) = LOC_STATIC;
780 SYMBOL_VALUE_ADDRESS (sym) = valu;
781 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
782 add_symbol_to_list (sym, &file_symbols);
783 break;
784
785 case 't':
786 /* For a nameless type, we don't want a create a symbol, thus we
787 did not use `sym'. Return without further processing. */
788 if (nameless) return NULL;
789
790 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
791 SYMBOL_VALUE (sym) = valu;
792 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
793 /* C++ vagaries: we may have a type which is derived from
794 a base type which did not have its name defined when the
795 derived class was output. We fill in the derived class's
796 base part member's name here in that case. */
797 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
798 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
799 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
800 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
801 {
802 int j;
803 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
804 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
805 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
806 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
807 }
808
809 add_symbol_to_list (sym, &file_symbols);
810 break;
811
812 case 'T':
813 /* For a nameless type, we don't want a create a symbol, thus we
814 did not use `sym'. Return without further processing. */
815 if (nameless) return NULL;
816
817 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
818 SYMBOL_VALUE (sym) = valu;
819 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
820 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
821 TYPE_NAME (SYMBOL_TYPE (sym))
822 = obconcat (&objfile -> type_obstack, "",
823 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
824 ? "enum "
825 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
826 ? "struct " : "union ")),
827 SYMBOL_NAME (sym));
828 add_symbol_to_list (sym, &file_symbols);
829
830 if (synonym)
831 {
832 register struct symbol *typedef_sym = (struct symbol *)
833 obstack_alloc (&objfile -> type_obstack, sizeof (struct symbol));
834 memset (typedef_sym, 0, sizeof (struct symbol));
835 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
836 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
837
838 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
839 SYMBOL_VALUE (typedef_sym) = valu;
840 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
841 add_symbol_to_list (typedef_sym, &file_symbols);
842 }
843 break;
844
845 case 'V':
846 /* Static symbol of local scope */
847 SYMBOL_CLASS (sym) = LOC_STATIC;
848 SYMBOL_VALUE_ADDRESS (sym) = valu;
849 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
850 add_symbol_to_list (sym, &local_symbols);
851 break;
852
853 case 'v':
854 /* Reference parameter */
855 SYMBOL_CLASS (sym) = LOC_REF_ARG;
856 SYMBOL_VALUE (sym) = valu;
857 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
858 add_symbol_to_list (sym, &local_symbols);
859 break;
860
861 case 'X':
862 /* This is used by Sun FORTRAN for "function result value".
863 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
864 that Pascal uses it too, but when I tried it Pascal used
865 "x:3" (local symbol) instead. */
866 SYMBOL_CLASS (sym) = LOC_LOCAL;
867 SYMBOL_VALUE (sym) = valu;
868 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
869 add_symbol_to_list (sym, &local_symbols);
870 break;
871
872 default:
873 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
874 }
875 return sym;
876 }
877
878 \f
879 /* Skip rest of this symbol and return an error type.
880
881 General notes on error recovery: error_type always skips to the
882 end of the symbol (modulo cretinous dbx symbol name continuation).
883 Thus code like this:
884
885 if (*(*pp)++ != ';')
886 return error_type (pp);
887
888 is wrong because if *pp starts out pointing at '\0' (typically as the
889 result of an earlier error), it will be incremented to point to the
890 start of the next symbol, which might produce strange results, at least
891 if you run off the end of the string table. Instead use
892
893 if (**pp != ';')
894 return error_type (pp);
895 ++*pp;
896
897 or
898
899 if (**pp != ';')
900 foo = error_type (pp);
901 else
902 ++*pp;
903
904 And in case it isn't obvious, the point of all this hair is so the compiler
905 can define new types and new syntaxes, and old versions of the
906 debugger will be able to read the new symbol tables. */
907
908 struct type *
909 error_type (pp)
910 char **pp;
911 {
912 complain (&error_type_complaint, 0);
913 while (1)
914 {
915 /* Skip to end of symbol. */
916 while (**pp != '\0')
917 (*pp)++;
918
919 /* Check for and handle cretinous dbx symbol name continuation! */
920 if ((*pp)[-1] == '\\')
921 *pp = next_symbol_text ();
922 else
923 break;
924 }
925 return builtin_type_error;
926 }
927
928 \f
929 /* Read a dbx type reference or definition;
930 return the type that is meant.
931 This can be just a number, in which case it references
932 a type already defined and placed in type_vector.
933 Or the number can be followed by an =, in which case
934 it means to define a new type according to the text that
935 follows the =. */
936
937 struct type *
938 read_type (pp, objfile)
939 register char **pp;
940 struct objfile *objfile;
941 {
942 register struct type *type = 0;
943 struct type *type1;
944 int typenums[2];
945 int xtypenums[2];
946
947 /* Read type number if present. The type number may be omitted.
948 for instance in a two-dimensional array declared with type
949 "ar1;1;10;ar1;1;10;4". */
950 if ((**pp >= '0' && **pp <= '9')
951 || **pp == '(')
952 {
953 read_type_number (pp, typenums);
954
955 /* Type is not being defined here. Either it already exists,
956 or this is a forward reference to it. dbx_alloc_type handles
957 both cases. */
958 if (**pp != '=')
959 return dbx_alloc_type (typenums, objfile);
960
961 /* Type is being defined here. */
962 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
963 {
964 struct type *tt;
965
966 /* if such a type already exists, this is an unnecessary duplication
967 of the stab string, which is common in (RS/6000) xlc generated
968 objects. In that case, simply return NULL and let the caller take
969 care of it. */
970
971 tt = *dbx_lookup_type (typenums);
972 if (tt && tt->length && tt->code)
973 return NULL;
974 }
975 #endif
976
977 *pp += 2;
978 }
979 else
980 {
981 /* 'typenums=' not present, type is anonymous. Read and return
982 the definition, but don't put it in the type vector. */
983 typenums[0] = typenums[1] = -1;
984 *pp += 1;
985 }
986
987 switch ((*pp)[-1])
988 {
989 case 'x':
990 {
991 enum type_code code;
992
993 /* Used to index through file_symbols. */
994 struct pending *ppt;
995 int i;
996
997 /* Name including "struct", etc. */
998 char *type_name;
999
1000 /* Name without "struct", etc. */
1001 char *type_name_only;
1002
1003 {
1004 char *prefix;
1005 char *from, *to;
1006
1007 /* Set the type code according to the following letter. */
1008 switch ((*pp)[0])
1009 {
1010 case 's':
1011 code = TYPE_CODE_STRUCT;
1012 prefix = "struct ";
1013 break;
1014 case 'u':
1015 code = TYPE_CODE_UNION;
1016 prefix = "union ";
1017 break;
1018 case 'e':
1019 code = TYPE_CODE_ENUM;
1020 prefix = "enum ";
1021 break;
1022 default:
1023 return error_type (pp);
1024 }
1025
1026 to = type_name = (char *)
1027 obstack_alloc (&objfile -> type_obstack,
1028 (strlen (prefix) +
1029 ((char *) strchr (*pp, ':') - (*pp)) + 1));
1030
1031 /* Copy the prefix. */
1032 from = prefix;
1033 while (*to++ = *from++)
1034 ;
1035 to--;
1036
1037 type_name_only = to;
1038
1039 /* Copy the name. */
1040 from = *pp + 1;
1041 while ((*to++ = *from++) != ':')
1042 ;
1043 *--to = '\0';
1044
1045 /* Set the pointer ahead of the name which we just read. */
1046 *pp = from;
1047
1048 #if 0
1049 /* The following hack is clearly wrong, because it doesn't
1050 check whether we are in a baseclass. I tried to reproduce
1051 the case that it is trying to fix, but I couldn't get
1052 g++ to put out a cross reference to a basetype. Perhaps
1053 it doesn't do it anymore. */
1054 /* Note: for C++, the cross reference may be to a base type which
1055 has not yet been seen. In this case, we skip to the comma,
1056 which will mark the end of the base class name. (The ':'
1057 at the end of the base class name will be skipped as well.)
1058 But sometimes (ie. when the cross ref is the last thing on
1059 the line) there will be no ','. */
1060 from = (char *) strchr (*pp, ',');
1061 if (from)
1062 *pp = from;
1063 #endif /* 0 */
1064 }
1065
1066 /* Now check to see whether the type has already been declared. */
1067 /* This is necessary at least in the case where the
1068 program says something like
1069 struct foo bar[5];
1070 The compiler puts out a cross-reference; we better find
1071 set the length of the structure correctly so we can
1072 set the length of the array. */
1073 for (ppt = file_symbols; ppt; ppt = ppt->next)
1074 for (i = 0; i < ppt->nsyms; i++)
1075 {
1076 struct symbol *sym = ppt->symbol[i];
1077
1078 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1079 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1080 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1081 && !strcmp (SYMBOL_NAME (sym), type_name_only))
1082 {
1083 obstack_free (&objfile -> type_obstack, type_name);
1084 type = SYMBOL_TYPE (sym);
1085 return type;
1086 }
1087 }
1088
1089 /* Didn't find the type to which this refers, so we must
1090 be dealing with a forward reference. Allocate a type
1091 structure for it, and keep track of it so we can
1092 fill in the rest of the fields when we get the full
1093 type. */
1094 type = dbx_alloc_type (typenums, objfile);
1095 TYPE_CODE (type) = code;
1096 TYPE_NAME (type) = type_name;
1097 INIT_CPLUS_SPECIFIC(type);
1098 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1099
1100 add_undefined_type (type);
1101 return type;
1102 }
1103
1104 case '-': /* RS/6000 built-in type */
1105 (*pp)--;
1106 type = builtin_type (pp); /* (in xcoffread.c) */
1107 goto after_digits;
1108
1109 case '0':
1110 case '1':
1111 case '2':
1112 case '3':
1113 case '4':
1114 case '5':
1115 case '6':
1116 case '7':
1117 case '8':
1118 case '9':
1119 case '(':
1120 (*pp)--;
1121 read_type_number (pp, xtypenums);
1122 type = *dbx_lookup_type (xtypenums);
1123 /* fall through */
1124
1125 after_digits:
1126 if (type == 0)
1127 type = lookup_fundamental_type (objfile, FT_VOID);
1128 if (typenums[0] != -1)
1129 *dbx_lookup_type (typenums) = type;
1130 break;
1131
1132 /* In the following types, we must be sure to overwrite any existing
1133 type that the typenums refer to, rather than allocating a new one
1134 and making the typenums point to the new one. This is because there
1135 may already be pointers to the existing type (if it had been
1136 forward-referenced), and we must change it to a pointer, function,
1137 reference, or whatever, *in-place*. */
1138
1139 case '*':
1140 type1 = read_type (pp, objfile);
1141 type = make_pointer_type (type1, dbx_lookup_type (typenums));
1142 break;
1143
1144 case '&': /* Reference to another type */
1145 type1 = read_type (pp, objfile);
1146 type = make_reference_type (type1, dbx_lookup_type (typenums));
1147 break;
1148
1149 case 'f': /* Function returning another type */
1150 type1 = read_type (pp, objfile);
1151 type = make_function_type (type1, dbx_lookup_type (typenums));
1152 break;
1153
1154 case 'k': /* Const qualifier on some type (Sun) */
1155 type = read_type (pp, objfile);
1156 /* FIXME! For now, we ignore const and volatile qualifiers. */
1157 break;
1158
1159 case 'B': /* Volatile qual on some type (Sun) */
1160 type = read_type (pp, objfile);
1161 /* FIXME! For now, we ignore const and volatile qualifiers. */
1162 break;
1163
1164 /* FIXME -- we should be doing smash_to_XXX types here. */
1165 case '@': /* Member (class & variable) type */
1166 {
1167 struct type *domain = read_type (pp, objfile);
1168 struct type *memtype;
1169
1170 if (**pp != ',')
1171 /* Invalid member type data format. */
1172 return error_type (pp);
1173 ++*pp;
1174
1175 memtype = read_type (pp, objfile);
1176 type = dbx_alloc_type (typenums, objfile);
1177 smash_to_member_type (type, domain, memtype);
1178 }
1179 break;
1180
1181 case '#': /* Method (class & fn) type */
1182 if ((*pp)[0] == '#')
1183 {
1184 /* We'll get the parameter types from the name. */
1185 struct type *return_type;
1186
1187 *pp += 1;
1188 return_type = read_type (pp, objfile);
1189 if (*(*pp)++ != ';')
1190 complain (&invalid_member_complaint, (char *) symnum);
1191 type = allocate_stub_method (return_type);
1192 if (typenums[0] != -1)
1193 *dbx_lookup_type (typenums) = type;
1194 }
1195 else
1196 {
1197 struct type *domain = read_type (pp, objfile);
1198 struct type *return_type;
1199 struct type **args;
1200
1201 if (*(*pp)++ != ',')
1202 error ("invalid member type data format, at symtab pos %d.",
1203 symnum);
1204
1205 return_type = read_type (pp, objfile);
1206 args = read_args (pp, ';', objfile);
1207 type = dbx_alloc_type (typenums, objfile);
1208 smash_to_method_type (type, domain, return_type, args);
1209 }
1210 break;
1211
1212 case 'r': /* Range type */
1213 type = read_range_type (pp, typenums, objfile);
1214 if (typenums[0] != -1)
1215 *dbx_lookup_type (typenums) = type;
1216 break;
1217
1218 case 'b': /* Sun ACC builtin int type */
1219 type = read_sun_builtin_type (pp, typenums, objfile);
1220 if (typenums[0] != -1)
1221 *dbx_lookup_type (typenums) = type;
1222 break;
1223
1224 case 'R': /* Sun ACC builtin float type */
1225 type = read_sun_floating_type (pp, typenums, objfile);
1226 if (typenums[0] != -1)
1227 *dbx_lookup_type (typenums) = type;
1228 break;
1229
1230 case 'e': /* Enumeration type */
1231 type = dbx_alloc_type (typenums, objfile);
1232 type = read_enum_type (pp, type, objfile);
1233 *dbx_lookup_type (typenums) = type;
1234 break;
1235
1236 case 's': /* Struct type */
1237 type = dbx_alloc_type (typenums, objfile);
1238 if (!TYPE_NAME (type))
1239 TYPE_NAME (type) = type_synonym_name;
1240 type_synonym_name = 0;
1241 type = read_struct_type (pp, type, objfile);
1242 break;
1243
1244 case 'u': /* Union type */
1245 type = dbx_alloc_type (typenums, objfile);
1246 if (!TYPE_NAME (type))
1247 TYPE_NAME (type) = type_synonym_name;
1248 type_synonym_name = 0;
1249 type = read_struct_type (pp, type, objfile);
1250 TYPE_CODE (type) = TYPE_CODE_UNION;
1251 break;
1252
1253 case 'a': /* Array type */
1254 if (**pp != 'r')
1255 return error_type (pp);
1256 ++*pp;
1257
1258 type = dbx_alloc_type (typenums, objfile);
1259 type = read_array_type (pp, type, objfile);
1260 break;
1261
1262 default:
1263 --*pp; /* Go back to the symbol in error */
1264 /* Particularly important if it was \0! */
1265 return error_type (pp);
1266 }
1267
1268 if (type == 0)
1269 abort ();
1270
1271 return type;
1272 }
1273 \f
1274 /* This page contains subroutines of read_type. */
1275
1276 /* Read the description of a structure (or union type)
1277 and return an object describing the type. */
1278
1279 static struct type *
1280 read_struct_type (pp, type, objfile)
1281 char **pp;
1282 register struct type *type;
1283 struct objfile *objfile;
1284 {
1285 /* Total number of methods defined in this class.
1286 If the class defines two `f' methods, and one `g' method,
1287 then this will have the value 3. */
1288 int total_length = 0;
1289
1290 struct nextfield
1291 {
1292 struct nextfield *next;
1293 int visibility; /* 0=public, 1=protected, 2=public */
1294 struct field field;
1295 };
1296
1297 struct next_fnfield
1298 {
1299 struct next_fnfield *next;
1300 struct fn_field fn_field;
1301 };
1302
1303 struct next_fnfieldlist
1304 {
1305 struct next_fnfieldlist *next;
1306 struct fn_fieldlist fn_fieldlist;
1307 };
1308
1309 register struct nextfield *list = 0;
1310 struct nextfield *new;
1311 register char *p;
1312 int nfields = 0;
1313 int non_public_fields = 0;
1314 register int n;
1315
1316 register struct next_fnfieldlist *mainlist = 0;
1317 int nfn_fields = 0;
1318
1319 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1320 INIT_CPLUS_SPECIFIC(type);
1321 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
1322
1323 /* First comes the total size in bytes. */
1324
1325 TYPE_LENGTH (type) = read_number (pp, 0);
1326
1327 /* C++: Now, if the class is a derived class, then the next character
1328 will be a '!', followed by the number of base classes derived from.
1329 Each element in the list contains visibility information,
1330 the offset of this base class in the derived structure,
1331 and then the base type. */
1332 if (**pp == '!')
1333 {
1334 int i, n_baseclasses, offset;
1335 struct type *baseclass;
1336 int via_public;
1337
1338 /* Nonzero if it is a virtual baseclass, i.e.,
1339
1340 struct A{};
1341 struct B{};
1342 struct C : public B, public virtual A {};
1343
1344 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1345 2.0 language feature. */
1346 int via_virtual;
1347
1348 *pp += 1;
1349
1350 ALLOCATE_CPLUS_STRUCT_TYPE(type);
1351
1352 n_baseclasses = read_number (pp, ',');
1353 TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *)
1354 obstack_alloc (&objfile -> type_obstack, B_BYTES (n_baseclasses));
1355 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
1356
1357 for (i = 0; i < n_baseclasses; i++)
1358 {
1359 if (**pp == '\\')
1360 *pp = next_symbol_text ();
1361
1362 switch (**pp)
1363 {
1364 case '0':
1365 via_virtual = 0;
1366 break;
1367 case '1':
1368 via_virtual = 1;
1369 break;
1370 default:
1371 /* Bad visibility format. */
1372 return error_type (pp);
1373 }
1374 ++*pp;
1375
1376 switch (**pp)
1377 {
1378 case '0':
1379 via_public = 0;
1380 non_public_fields++;
1381 break;
1382 case '2':
1383 via_public = 2;
1384 break;
1385 default:
1386 /* Bad visibility format. */
1387 return error_type (pp);
1388 }
1389 if (via_virtual)
1390 SET_TYPE_FIELD_VIRTUAL (type, i);
1391 ++*pp;
1392
1393 /* Offset of the portion of the object corresponding to
1394 this baseclass. Always zero in the absence of
1395 multiple inheritance. */
1396 offset = read_number (pp, ',');
1397 baseclass = read_type (pp, objfile);
1398 *pp += 1; /* skip trailing ';' */
1399
1400 /* Make this baseclass visible for structure-printing purposes. */
1401 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1402 memset (new, 0, sizeof (struct nextfield));
1403 new->next = list;
1404 list = new;
1405 list->visibility = via_public;
1406 list->field.type = baseclass;
1407 list->field.name = type_name_no_tag (baseclass);
1408 list->field.bitpos = offset;
1409 list->field.bitsize = 0; /* this should be an unpacked field! */
1410 nfields++;
1411 }
1412 TYPE_N_BASECLASSES (type) = n_baseclasses;
1413 }
1414
1415 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
1416 At the end, we see a semicolon instead of a field.
1417
1418 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1419 a static field.
1420
1421 The `?' is a placeholder for one of '/2' (public visibility),
1422 '/1' (protected visibility), '/0' (private visibility), or nothing
1423 (C style symbol table, public visibility). */
1424
1425 /* We better set p right now, in case there are no fields at all... */
1426 p = *pp;
1427
1428 while (**pp != ';')
1429 {
1430 /* Check for and handle cretinous dbx symbol name continuation! */
1431 if (**pp == '\\') *pp = next_symbol_text ();
1432
1433 /* Get space to record the next field's data. */
1434 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1435 memset (new, 0, sizeof (struct nextfield));
1436 new->next = list;
1437 list = new;
1438
1439 /* Get the field name. */
1440 p = *pp;
1441 if (*p == CPLUS_MARKER)
1442 {
1443 /* Special GNU C++ name. */
1444 if (*++p == 'v')
1445 {
1446 const char *prefix;
1447 char *name = 0;
1448 struct type *context;
1449
1450 switch (*++p)
1451 {
1452 case 'f':
1453 prefix = vptr_name;
1454 break;
1455 case 'b':
1456 prefix = vb_name;
1457 break;
1458 default:
1459 complain (&invalid_cpp_abbrev_complaint, *pp);
1460 prefix = "INVALID_C++_ABBREV";
1461 break;
1462 }
1463 *pp = p + 1;
1464 context = read_type (pp, objfile);
1465 name = type_name_no_tag (context);
1466 if (name == 0)
1467 {
1468 complain (&invalid_cpp_type_complaint, (char *) symnum);
1469 name = "FOO";
1470 }
1471 list->field.name = obconcat (&objfile -> type_obstack,
1472 prefix, name, "");
1473 p = ++(*pp);
1474 if (p[-1] != ':')
1475 complain (&invalid_cpp_abbrev_complaint, *pp);
1476 list->field.type = read_type (pp, objfile);
1477 (*pp)++; /* Skip the comma. */
1478 list->field.bitpos = read_number (pp, ';');
1479 /* This field is unpacked. */
1480 list->field.bitsize = 0;
1481 list->visibility = 0; /* private */
1482 non_public_fields++;
1483 }
1484 /* GNU C++ anonymous type. */
1485 else if (*p == '_')
1486 break;
1487 else
1488 complain (&invalid_cpp_abbrev_complaint, *pp);
1489
1490 nfields++;
1491 continue;
1492 }
1493
1494 while (*p != ':') p++;
1495 list->field.name = obsavestring (*pp, p - *pp,
1496 &objfile -> type_obstack);
1497
1498 /* C++: Check to see if we have hit the methods yet. */
1499 if (p[1] == ':')
1500 break;
1501
1502 *pp = p + 1;
1503
1504 /* This means we have a visibility for a field coming. */
1505 if (**pp == '/')
1506 {
1507 switch (*++*pp)
1508 {
1509 case '0':
1510 list->visibility = 0; /* private */
1511 non_public_fields++;
1512 *pp += 1;
1513 break;
1514
1515 case '1':
1516 list->visibility = 1; /* protected */
1517 non_public_fields++;
1518 *pp += 1;
1519 break;
1520
1521 case '2':
1522 list->visibility = 2; /* public */
1523 *pp += 1;
1524 break;
1525 }
1526 }
1527 else /* normal dbx-style format. */
1528 list->visibility = 2; /* public */
1529
1530 list->field.type = read_type (pp, objfile);
1531 if (**pp == ':')
1532 {
1533 p = ++(*pp);
1534 #if 0
1535 /* Possible future hook for nested types. */
1536 if (**pp == '!')
1537 {
1538 list->field.bitpos = (long)-2; /* nested type */
1539 p = ++(*pp);
1540 }
1541 else
1542 #endif
1543 { /* Static class member. */
1544 list->field.bitpos = (long)-1;
1545 }
1546 while (*p != ';') p++;
1547 list->field.bitsize = (long) savestring (*pp, p - *pp);
1548 *pp = p + 1;
1549 nfields++;
1550 continue;
1551 }
1552 else if (**pp != ',')
1553 /* Bad structure-type format. */
1554 return error_type (pp);
1555
1556 (*pp)++; /* Skip the comma. */
1557 list->field.bitpos = read_number (pp, ',');
1558 list->field.bitsize = read_number (pp, ';');
1559
1560 #if 0
1561 /* FIXME-tiemann: Can't the compiler put out something which
1562 lets us distinguish these? (or maybe just not put out anything
1563 for the field). What is the story here? What does the compiler
1564 really do? Also, patch gdb.texinfo for this case; I document
1565 it as a possible problem there. Search for "DBX-style". */
1566
1567 /* This is wrong because this is identical to the symbols
1568 produced for GCC 0-size arrays. For example:
1569 typedef union {
1570 int num;
1571 char str[0];
1572 } foo;
1573 The code which dumped core in such circumstances should be
1574 fixed not to dump core. */
1575
1576 /* g++ -g0 can put out bitpos & bitsize zero for a static
1577 field. This does not give us any way of getting its
1578 class, so we can't know its name. But we can just
1579 ignore the field so we don't dump core and other nasty
1580 stuff. */
1581 if (list->field.bitpos == 0
1582 && list->field.bitsize == 0)
1583 {
1584 complain (&dbx_class_complaint, 0);
1585 /* Ignore this field. */
1586 list = list->next;
1587 }
1588 else
1589 #endif /* 0 */
1590 {
1591 /* Detect an unpacked field and mark it as such.
1592 dbx gives a bit size for all fields.
1593 Note that forward refs cannot be packed,
1594 and treat enums as if they had the width of ints. */
1595 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
1596 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
1597 list->field.bitsize = 0;
1598 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
1599 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
1600 && (list->field.bitsize
1601 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile, FT_INTEGER)))
1602 )
1603 )
1604 &&
1605 list->field.bitpos % 8 == 0)
1606 list->field.bitsize = 0;
1607 nfields++;
1608 }
1609 }
1610
1611 if (p[1] == ':')
1612 /* chill the list of fields: the last entry (at the head)
1613 is a partially constructed entry which we now scrub. */
1614 list = list->next;
1615
1616 /* Now create the vector of fields, and record how big it is.
1617 We need this info to record proper virtual function table information
1618 for this class's virtual functions. */
1619
1620 TYPE_NFIELDS (type) = nfields;
1621 TYPE_FIELDS (type) = (struct field *)
1622 obstack_alloc (&objfile -> type_obstack, sizeof (struct field) * nfields);
1623 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields);
1624
1625 if (non_public_fields)
1626 {
1627 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1628
1629 TYPE_FIELD_PRIVATE_BITS (type) = (B_TYPE *)
1630 obstack_alloc (&objfile -> type_obstack, B_BYTES (nfields));
1631 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
1632
1633 TYPE_FIELD_PROTECTED_BITS (type) = (B_TYPE *)
1634 obstack_alloc (&objfile -> type_obstack, B_BYTES (nfields));
1635 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
1636 }
1637
1638 /* Copy the saved-up fields into the field vector. */
1639
1640 for (n = nfields; list; list = list->next)
1641 {
1642 n -= 1;
1643 TYPE_FIELD (type, n) = list->field;
1644 if (list->visibility == 0)
1645 SET_TYPE_FIELD_PRIVATE (type, n);
1646 else if (list->visibility == 1)
1647 SET_TYPE_FIELD_PROTECTED (type, n);
1648 }
1649
1650 /* Now come the method fields, as NAME::methods
1651 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
1652 At the end, we see a semicolon instead of a field.
1653
1654 For the case of overloaded operators, the format is
1655 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
1656 `*' holds the place for an operator name (such as `+=')
1657 and `.' marks the end of the operator name. */
1658 if (p[1] == ':')
1659 {
1660 /* Now, read in the methods. To simplify matters, we
1661 "unread" the name that has been read, so that we can
1662 start from the top. */
1663
1664 ALLOCATE_CPLUS_STRUCT_TYPE (type);
1665 /* For each list of method lists... */
1666 do
1667 {
1668 int i;
1669 struct next_fnfield *sublist = 0;
1670 struct type *look_ahead_type = NULL;
1671 int length = 0;
1672 struct next_fnfieldlist *new_mainlist;
1673 char *main_fn_name;
1674
1675 new_mainlist = (struct next_fnfieldlist *)
1676 alloca (sizeof (struct next_fnfieldlist));
1677 memset (new_mainlist, 0, sizeof (struct next_fnfieldlist));
1678
1679 p = *pp;
1680
1681 /* read in the name. */
1682 while (*p != ':') p++;
1683 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
1684 {
1685 /* This is a completely wierd case. In order to stuff in the
1686 names that might contain colons (the usual name delimiter),
1687 Mike Tiemann defined a different name format which is
1688 signalled if the identifier is "op$". In that case, the
1689 format is "op$::XXXX." where XXXX is the name. This is
1690 used for names like "+" or "=". YUUUUUUUK! FIXME! */
1691 /* This lets the user type "break operator+".
1692 We could just put in "+" as the name, but that wouldn't
1693 work for "*". */
1694 static char opname[32] = {'o', 'p', CPLUS_MARKER};
1695 char *o = opname + 3;
1696
1697 /* Skip past '::'. */
1698 *pp = p + 2;
1699 if (**pp == '\\') *pp = next_symbol_text ();
1700 p = *pp;
1701 while (*p != '.')
1702 *o++ = *p++;
1703 main_fn_name = savestring (opname, o - opname);
1704 /* Skip past '.' */
1705 *pp = p + 1;
1706 }
1707 else
1708 {
1709 main_fn_name = savestring (*pp, p - *pp);
1710 /* Skip past '::'. */
1711 *pp = p + 2;
1712 }
1713 new_mainlist->fn_fieldlist.name = main_fn_name;
1714
1715 do
1716 {
1717 struct next_fnfield *new_sublist =
1718 (struct next_fnfield *) alloca (sizeof (struct next_fnfield));
1719 memset (new_sublist, 0, sizeof (struct next_fnfield));
1720
1721 /* Check for and handle cretinous dbx symbol name continuation! */
1722 if (look_ahead_type == NULL) /* Normal case. */
1723 {
1724 if (**pp == '\\') *pp = next_symbol_text ();
1725
1726 new_sublist->fn_field.type = read_type (pp, objfile);
1727 if (**pp != ':')
1728 /* Invalid symtab info for method. */
1729 return error_type (pp);
1730 }
1731 else
1732 { /* g++ version 1 kludge */
1733 new_sublist->fn_field.type = look_ahead_type;
1734 look_ahead_type = NULL;
1735 }
1736
1737 *pp += 1;
1738 p = *pp;
1739 while (*p != ';') p++;
1740
1741 /* If this is just a stub, then we don't have the
1742 real name here. */
1743 if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
1744 new_sublist->fn_field.is_stub = 1;
1745 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
1746 *pp = p + 1;
1747
1748 /* Set this method's visibility fields. */
1749 switch (*(*pp)++ - '0')
1750 {
1751 case 0:
1752 new_sublist->fn_field.is_private = 1;
1753 break;
1754 case 1:
1755 new_sublist->fn_field.is_protected = 1;
1756 break;
1757 }
1758
1759 if (**pp == '\\') *pp = next_symbol_text ();
1760 switch (**pp)
1761 {
1762 case 'A': /* Normal functions. */
1763 new_sublist->fn_field.is_const = 0;
1764 new_sublist->fn_field.is_volatile = 0;
1765 (*pp)++;
1766 break;
1767 case 'B': /* `const' member functions. */
1768 new_sublist->fn_field.is_const = 1;
1769 new_sublist->fn_field.is_volatile = 0;
1770 (*pp)++;
1771 break;
1772 case 'C': /* `volatile' member function. */
1773 new_sublist->fn_field.is_const = 0;
1774 new_sublist->fn_field.is_volatile = 1;
1775 (*pp)++;
1776 break;
1777 case 'D': /* `const volatile' member function. */
1778 new_sublist->fn_field.is_const = 1;
1779 new_sublist->fn_field.is_volatile = 1;
1780 (*pp)++;
1781 break;
1782 case '*': /* File compiled with g++ version 1 -- no info */
1783 case '?':
1784 case '.':
1785 break;
1786 default:
1787 complain (&const_vol_complaint, (char *) (long) **pp);
1788 break;
1789 }
1790
1791 switch (*(*pp)++)
1792 {
1793 case '*':
1794 /* virtual member function, followed by index. */
1795 /* The sign bit is set to distinguish pointers-to-methods
1796 from virtual function indicies. Since the array is
1797 in words, the quantity must be shifted left by 1
1798 on 16 bit machine, and by 2 on 32 bit machine, forcing
1799 the sign bit out, and usable as a valid index into
1800 the array. Remove the sign bit here. */
1801 new_sublist->fn_field.voffset =
1802 (0x7fffffff & read_number (pp, ';')) + 2;
1803
1804 if (**pp == '\\') *pp = next_symbol_text ();
1805
1806 if (**pp == ';' || **pp == '\0')
1807 /* Must be g++ version 1. */
1808 new_sublist->fn_field.fcontext = 0;
1809 else
1810 {
1811 /* Figure out from whence this virtual function came.
1812 It may belong to virtual function table of
1813 one of its baseclasses. */
1814 look_ahead_type = read_type (pp, objfile);
1815 if (**pp == ':')
1816 { /* g++ version 1 overloaded methods. */ }
1817 else
1818 {
1819 new_sublist->fn_field.fcontext = look_ahead_type;
1820 if (**pp != ';')
1821 return error_type (pp);
1822 else
1823 ++*pp;
1824 look_ahead_type = NULL;
1825 }
1826 }
1827 break;
1828
1829 case '?':
1830 /* static member function. */
1831 new_sublist->fn_field.voffset = VOFFSET_STATIC;
1832 if (strncmp (new_sublist->fn_field.physname,
1833 main_fn_name, strlen (main_fn_name)))
1834 new_sublist->fn_field.is_stub = 1;
1835 break;
1836
1837 default:
1838 /* error */
1839 complain (&member_fn_complaint, (char *) (long) (*pp)[-1]);
1840 /* Fall through into normal member function. */
1841
1842 case '.':
1843 /* normal member function. */
1844 new_sublist->fn_field.voffset = 0;
1845 new_sublist->fn_field.fcontext = 0;
1846 break;
1847 }
1848
1849 new_sublist->next = sublist;
1850 sublist = new_sublist;
1851 length++;
1852 if (**pp == '\\') *pp = next_symbol_text ();
1853 }
1854 while (**pp != ';' && **pp != '\0');
1855
1856 *pp += 1;
1857
1858 new_mainlist->fn_fieldlist.fn_fields = (struct fn_field *)
1859 obstack_alloc (&objfile -> type_obstack,
1860 sizeof (struct fn_field) * length);
1861 memset (new_mainlist->fn_fieldlist.fn_fields, 0,
1862 sizeof (struct fn_field) * length);
1863 for (i = length; (i--, sublist); sublist = sublist->next)
1864 new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
1865
1866 new_mainlist->fn_fieldlist.length = length;
1867 new_mainlist->next = mainlist;
1868 mainlist = new_mainlist;
1869 nfn_fields++;
1870 total_length += length;
1871 if (**pp == '\\') *pp = next_symbol_text ();
1872 }
1873 while (**pp != ';');
1874 }
1875
1876 *pp += 1;
1877
1878
1879 if (nfn_fields)
1880 {
1881 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
1882 obstack_alloc (&objfile -> type_obstack,
1883 sizeof (struct fn_fieldlist) * nfn_fields);
1884 memset (TYPE_FN_FIELDLISTS (type), 0,
1885 sizeof (struct fn_fieldlist) * nfn_fields);
1886 TYPE_NFN_FIELDS (type) = nfn_fields;
1887 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
1888 }
1889
1890 {
1891 int i;
1892 for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
1893 {
1894 if (TYPE_CODE (TYPE_BASECLASS (type, i)) == TYPE_CODE_UNDEF)
1895 /* @@ Memory leak on objfile->type_obstack? */
1896 return error_type (pp);
1897 TYPE_NFN_FIELDS_TOTAL (type) +=
1898 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
1899 }
1900 }
1901
1902 for (n = nfn_fields; mainlist; mainlist = mainlist->next) {
1903 --n; /* Circumvent Sun3 compiler bug */
1904 TYPE_FN_FIELDLISTS (type)[n] = mainlist->fn_fieldlist;
1905 }
1906
1907 if (**pp == '~')
1908 {
1909 *pp += 1;
1910
1911 if (**pp == '=' || **pp == '+' || **pp == '-')
1912 {
1913 /* Obsolete flags that used to indicate the presence
1914 of constructors and/or destructors. */
1915 *pp += 1;
1916 }
1917
1918 /* Read either a '%' or the final ';'. */
1919 if (*(*pp)++ == '%')
1920 {
1921 /* We'd like to be able to derive the vtable pointer field
1922 from the type information, but when it's inherited, that's
1923 hard. A reason it's hard is because we may read in the
1924 info about a derived class before we read in info about
1925 the base class that provides the vtable pointer field.
1926 Once the base info has been read, we could fill in the info
1927 for the derived classes, but for the fact that by then,
1928 we don't remember who needs what. */
1929
1930 #if 0
1931 int predicted_fieldno = -1;
1932 #endif
1933
1934 /* Now we must record the virtual function table pointer's
1935 field information. */
1936
1937 struct type *t;
1938 int i;
1939
1940
1941 #if 0
1942 {
1943 /* In version 2, we derive the vfield ourselves. */
1944 for (n = 0; n < nfields; n++)
1945 {
1946 if (! strncmp (TYPE_FIELD_NAME (type, n), vptr_name,
1947 sizeof (vptr_name) -1))
1948 {
1949 predicted_fieldno = n;
1950 break;
1951 }
1952 }
1953 if (predicted_fieldno < 0)
1954 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
1955 if (! TYPE_FIELD_VIRTUAL (type, n)
1956 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n)) >= 0)
1957 {
1958 predicted_fieldno = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n));
1959 break;
1960 }
1961 }
1962 #endif
1963
1964 t = read_type (pp, objfile);
1965 p = (*pp)++;
1966 while (*p != '\0' && *p != ';')
1967 p++;
1968 if (*p == '\0')
1969 /* Premature end of symbol. */
1970 return error_type (pp);
1971
1972 TYPE_VPTR_BASETYPE (type) = t;
1973 if (type == t)
1974 {
1975 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
1976 {
1977 /* FIXME-tiemann: what's this? */
1978 #if 0
1979 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
1980 #else
1981 error_type (pp);
1982 #endif
1983 }
1984 else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
1985 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
1986 sizeof (vptr_name) - 1))
1987 {
1988 TYPE_VPTR_FIELDNO (type) = i;
1989 break;
1990 }
1991 if (i < 0)
1992 /* Virtual function table field not found. */
1993 return error_type (pp);
1994 }
1995 else
1996 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
1997
1998 #if 0
1999 if (TYPE_VPTR_FIELDNO (type) != predicted_fieldno)
2000 error ("TYPE_VPTR_FIELDNO miscalculated");
2001 #endif
2002
2003 *pp = p + 1;
2004 }
2005 }
2006
2007 return type;
2008 }
2009
2010 /* Read a definition of an array type,
2011 and create and return a suitable type object.
2012 Also creates a range type which represents the bounds of that
2013 array. */
2014
2015 static struct type *
2016 read_array_type (pp, type, objfile)
2017 register char **pp;
2018 register struct type *type;
2019 struct objfile *objfile;
2020 {
2021 struct type *index_type, *element_type, *range_type;
2022 int lower, upper;
2023 int adjustable = 0;
2024
2025 /* Format of an array type:
2026 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2027 to handle this.
2028
2029 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2030 for these, produce a type like float[][]. */
2031
2032 index_type = read_type (pp, objfile);
2033 if (**pp != ';')
2034 /* Improper format of array type decl. */
2035 return error_type (pp);
2036 ++*pp;
2037
2038 if (!(**pp >= '0' && **pp <= '9'))
2039 {
2040 *pp += 1;
2041 adjustable = 1;
2042 }
2043 lower = read_number (pp, ';');
2044
2045 if (!(**pp >= '0' && **pp <= '9'))
2046 {
2047 *pp += 1;
2048 adjustable = 1;
2049 }
2050 upper = read_number (pp, ';');
2051
2052 element_type = read_type (pp, objfile);
2053
2054 if (adjustable)
2055 {
2056 lower = 0;
2057 upper = -1;
2058 }
2059
2060 {
2061 /* Create range type. */
2062 range_type = (struct type *)
2063 obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
2064 memset (range_type, 0, sizeof (struct type));
2065 TYPE_OBJFILE (range_type) = objfile;
2066 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
2067 TYPE_TARGET_TYPE (range_type) = index_type;
2068
2069 /* This should never be needed. */
2070 TYPE_LENGTH (range_type) = sizeof (int);
2071
2072 TYPE_NFIELDS (range_type) = 2;
2073 TYPE_FIELDS (range_type) = (struct field *)
2074 obstack_alloc (&objfile -> type_obstack, 2 * sizeof (struct field));
2075 memset (TYPE_FIELDS (range_type), 0, 2 * sizeof (struct field));
2076 TYPE_FIELD_BITPOS (range_type, 0) = lower;
2077 TYPE_FIELD_BITPOS (range_type, 1) = upper;
2078 }
2079
2080 TYPE_CODE (type) = TYPE_CODE_ARRAY;
2081 TYPE_TARGET_TYPE (type) = element_type;
2082 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
2083 TYPE_NFIELDS (type) = 1;
2084 TYPE_FIELDS (type) = (struct field *)
2085 obstack_alloc (&objfile -> type_obstack, sizeof (struct field));
2086 memset (TYPE_FIELDS (type), 0, sizeof (struct field));
2087 TYPE_FIELD_TYPE (type, 0) = range_type;
2088
2089 /* If we have an array whose element type is not yet known, but whose
2090 bounds *are* known, record it to be adjusted at the end of the file. */
2091 if (TYPE_LENGTH (element_type) == 0 && !adjustable)
2092 add_undefined_type (type);
2093
2094 return type;
2095 }
2096
2097
2098 /* Read a definition of an enumeration type,
2099 and create and return a suitable type object.
2100 Also defines the symbols that represent the values of the type. */
2101
2102 static struct type *
2103 read_enum_type (pp, type, objfile)
2104 register char **pp;
2105 register struct type *type;
2106 struct objfile *objfile;
2107 {
2108 register char *p;
2109 char *name;
2110 register long n;
2111 register struct symbol *sym;
2112 int nsyms = 0;
2113 struct pending **symlist;
2114 struct pending *osyms, *syms;
2115 int o_nsyms;
2116
2117 #if 0
2118 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2119 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2120 to do? For now, force all enum values to file scope. */
2121 if (within_function)
2122 symlist = &local_symbols;
2123 else
2124 #endif
2125 symlist = &file_symbols;
2126 osyms = *symlist;
2127 o_nsyms = osyms ? osyms->nsyms : 0;
2128
2129 /* Read the value-names and their values.
2130 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2131 A semicolon or comma instead of a NAME means the end. */
2132 while (**pp && **pp != ';' && **pp != ',')
2133 {
2134 /* Check for and handle cretinous dbx symbol name continuation! */
2135 if (**pp == '\\') *pp = next_symbol_text ();
2136
2137 p = *pp;
2138 while (*p != ':') p++;
2139 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
2140 *pp = p + 1;
2141 n = read_number (pp, ',');
2142
2143 sym = (struct symbol *)
2144 obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
2145 memset (sym, 0, sizeof (struct symbol));
2146 SYMBOL_NAME (sym) = name;
2147 SYMBOL_CLASS (sym) = LOC_CONST;
2148 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2149 SYMBOL_VALUE (sym) = n;
2150 add_symbol_to_list (sym, symlist);
2151 nsyms++;
2152 }
2153
2154 if (**pp == ';')
2155 (*pp)++; /* Skip the semicolon. */
2156
2157 /* Now fill in the fields of the type-structure. */
2158
2159 TYPE_LENGTH (type) = sizeof (int);
2160 TYPE_CODE (type) = TYPE_CODE_ENUM;
2161 TYPE_FLAGS (type) &= ~TYPE_FLAG_STUB;
2162 TYPE_NFIELDS (type) = nsyms;
2163 TYPE_FIELDS (type) = (struct field *)
2164 obstack_alloc (&objfile -> type_obstack, sizeof (struct field) * nsyms);
2165 memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nsyms);
2166
2167 /* Find the symbols for the values and put them into the type.
2168 The symbols can be found in the symlist that we put them on
2169 to cause them to be defined. osyms contains the old value
2170 of that symlist; everything up to there was defined by us. */
2171 /* Note that we preserve the order of the enum constants, so
2172 that in something like "enum {FOO, LAST_THING=FOO}" we print
2173 FOO, not LAST_THING. */
2174
2175 for (syms = *symlist, n = 0; syms; syms = syms->next)
2176 {
2177 int j = 0;
2178 if (syms == osyms)
2179 j = o_nsyms;
2180 for (; j < syms->nsyms; j++,n++)
2181 {
2182 struct symbol *xsym = syms->symbol[j];
2183 SYMBOL_TYPE (xsym) = type;
2184 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2185 TYPE_FIELD_VALUE (type, n) = 0;
2186 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2187 TYPE_FIELD_BITSIZE (type, n) = 0;
2188 }
2189 if (syms == osyms)
2190 break;
2191 }
2192
2193 #if 0
2194 /* This screws up perfectly good C programs with enums. FIXME. */
2195 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2196 if(TYPE_NFIELDS(type) == 2 &&
2197 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2198 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2199 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2200 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2201 TYPE_CODE(type) = TYPE_CODE_BOOL;
2202 #endif
2203
2204 return type;
2205 }
2206
2207 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2208 typedefs in every file (for int, long, etc):
2209
2210 type = b <signed> <width>; <offset>; <nbits>
2211 signed = u or s. Possible c in addition to u or s (for char?).
2212 offset = offset from high order bit to start bit of type.
2213 width is # bytes in object of this type, nbits is # bits in type.
2214
2215 The width/offset stuff appears to be for small objects stored in
2216 larger ones (e.g. `shorts' in `int' registers). We ignore it for now,
2217 FIXME. */
2218
2219 static struct type *
2220 read_sun_builtin_type (pp, typenums, objfile)
2221 char **pp;
2222 int typenums[2];
2223 struct objfile *objfile;
2224 {
2225 int nbits;
2226 int signed_type;
2227
2228 switch (**pp)
2229 {
2230 case 's':
2231 signed_type = 1;
2232 break;
2233 case 'u':
2234 signed_type = 0;
2235 break;
2236 default:
2237 return error_type (pp);
2238 }
2239 (*pp)++;
2240
2241 /* For some odd reason, all forms of char put a c here. This is strange
2242 because no other type has this honor. We can safely ignore this because
2243 we actually determine 'char'acterness by the number of bits specified in
2244 the descriptor. */
2245
2246 if (**pp == 'c')
2247 (*pp)++;
2248
2249 /* The first number appears to be the number of bytes occupied
2250 by this type, except that unsigned short is 4 instead of 2.
2251 Since this information is redundant with the third number,
2252 we will ignore it. */
2253 read_number (pp, ';');
2254
2255 /* The second number is always 0, so ignore it too. */
2256 read_number (pp, ';');
2257
2258 /* The third number is the number of bits for this type. */
2259 nbits = read_number (pp, 0);
2260
2261 /* FIXME. Here we should just be able to make a type of the right
2262 number of bits and signedness. FIXME. */
2263
2264 if (nbits == TARGET_LONG_LONG_BIT)
2265 return (lookup_fundamental_type (objfile,
2266 signed_type? FT_LONG_LONG: FT_UNSIGNED_LONG_LONG));
2267
2268 if (nbits == TARGET_INT_BIT)
2269 {
2270 /* FIXME -- the only way to distinguish `int' from `long'
2271 is to look at its name! */
2272 if (signed_type)
2273 {
2274 if (long_kludge_name && long_kludge_name[0] == 'l' /* long */)
2275 return lookup_fundamental_type (objfile, FT_LONG);
2276 else
2277 return lookup_fundamental_type (objfile, FT_INTEGER);
2278 }
2279 else
2280 {
2281 if (long_kludge_name
2282 && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2283 long_kludge_name[9] == 'l' /* long */)
2284 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2285 return lookup_fundamental_type (objfile, FT_UNSIGNED_LONG);
2286 else
2287 return lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
2288 }
2289 }
2290
2291 if (nbits == TARGET_SHORT_BIT)
2292 return (lookup_fundamental_type (objfile,
2293 signed_type? FT_SHORT: FT_UNSIGNED_SHORT));
2294
2295 if (nbits == TARGET_CHAR_BIT)
2296 return (lookup_fundamental_type (objfile,
2297 signed_type? FT_CHAR: FT_UNSIGNED_CHAR));
2298
2299 if (nbits == 0)
2300 return lookup_fundamental_type (objfile, FT_VOID);
2301
2302 return error_type (pp);
2303 }
2304
2305 static struct type *
2306 read_sun_floating_type (pp, typenums, objfile)
2307 char **pp;
2308 int typenums[2];
2309 struct objfile *objfile;
2310 {
2311 int nbytes;
2312
2313 /* The first number has more details about the type, for example
2314 FN_COMPLEX. See the sun stab.h. */
2315 read_number (pp, ';');
2316
2317 /* The second number is the number of bytes occupied by this type */
2318 nbytes = read_number (pp, ';');
2319
2320 if (**pp != 0)
2321 return error_type (pp);
2322
2323 if (nbytes == TARGET_FLOAT_BIT / TARGET_CHAR_BIT)
2324 return lookup_fundamental_type (objfile, FT_FLOAT);
2325
2326 if (nbytes == TARGET_DOUBLE_BIT / TARGET_CHAR_BIT)
2327 return lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
2328
2329 if (nbytes == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT)
2330 return lookup_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
2331
2332 return error_type (pp);
2333 }
2334
2335 /* Read a number from the string pointed to by *PP.
2336 The value of *PP is advanced over the number.
2337 If END is nonzero, the character that ends the
2338 number must match END, or an error happens;
2339 and that character is skipped if it does match.
2340 If END is zero, *PP is left pointing to that character.
2341
2342 If the number fits in a long, set *VALUE and set *BITS to 0.
2343 If not, set *BITS to be the number of bits in the number.
2344
2345 If encounter garbage, set *BITS to -1. */
2346
2347 static void
2348 read_huge_number (pp, end, valu, bits)
2349 char **pp;
2350 int end;
2351 long *valu;
2352 int *bits;
2353 {
2354 char *p = *pp;
2355 int sign = 1;
2356 long n = 0;
2357 int radix = 10;
2358 char overflow = 0;
2359 int nbits = 0;
2360 int c;
2361 long upper_limit;
2362
2363 if (*p == '-')
2364 {
2365 sign = -1;
2366 p++;
2367 }
2368
2369 /* Leading zero means octal. GCC uses this to output values larger
2370 than an int (because that would be hard in decimal). */
2371 if (*p == '0')
2372 {
2373 radix = 8;
2374 p++;
2375 }
2376
2377 upper_limit = LONG_MAX / radix;
2378 while ((c = *p++) >= '0' && c <= ('0' + radix))
2379 {
2380 if (n <= upper_limit)
2381 {
2382 n *= radix;
2383 n += c - '0'; /* FIXME this overflows anyway */
2384 }
2385 else
2386 overflow = 1;
2387
2388 /* This depends on large values being output in octal, which is
2389 what GCC does. */
2390 if (radix == 8)
2391 {
2392 if (nbits == 0)
2393 {
2394 if (c == '0')
2395 /* Ignore leading zeroes. */
2396 ;
2397 else if (c == '1')
2398 nbits = 1;
2399 else if (c == '2' || c == '3')
2400 nbits = 2;
2401 else
2402 nbits = 3;
2403 }
2404 else
2405 nbits += 3;
2406 }
2407 }
2408 if (end)
2409 {
2410 if (c && c != end)
2411 {
2412 if (bits != NULL)
2413 *bits = -1;
2414 return;
2415 }
2416 }
2417 else
2418 --p;
2419
2420 *pp = p;
2421 if (overflow)
2422 {
2423 if (nbits == 0)
2424 {
2425 /* Large decimal constants are an error (because it is hard to
2426 count how many bits are in them). */
2427 if (bits != NULL)
2428 *bits = -1;
2429 return;
2430 }
2431
2432 /* -0x7f is the same as 0x80. So deal with it by adding one to
2433 the number of bits. */
2434 if (sign == -1)
2435 ++nbits;
2436 if (bits)
2437 *bits = nbits;
2438 }
2439 else
2440 {
2441 if (valu)
2442 *valu = n * sign;
2443 if (bits)
2444 *bits = 0;
2445 }
2446 }
2447
2448 static struct type *
2449 read_range_type (pp, typenums, objfile)
2450 char **pp;
2451 int typenums[2];
2452 struct objfile *objfile;
2453 {
2454 int rangenums[2];
2455 long n2, n3;
2456 int n2bits, n3bits;
2457 int self_subrange;
2458 struct type *result_type;
2459
2460 /* First comes a type we are a subrange of.
2461 In C it is usually 0, 1 or the type being defined. */
2462 read_type_number (pp, rangenums);
2463 self_subrange = (rangenums[0] == typenums[0] &&
2464 rangenums[1] == typenums[1]);
2465
2466 /* A semicolon should now follow; skip it. */
2467 if (**pp == ';')
2468 (*pp)++;
2469
2470 /* The remaining two operands are usually lower and upper bounds
2471 of the range. But in some special cases they mean something else. */
2472 read_huge_number (pp, ';', &n2, &n2bits);
2473 read_huge_number (pp, ';', &n3, &n3bits);
2474
2475 if (n2bits == -1 || n3bits == -1)
2476 return error_type (pp);
2477
2478 /* If limits are huge, must be large integral type. */
2479 if (n2bits != 0 || n3bits != 0)
2480 {
2481 char got_signed = 0;
2482 char got_unsigned = 0;
2483 /* Number of bits in the type. */
2484 int nbits;
2485
2486 /* Range from 0 to <large number> is an unsigned large integral type. */
2487 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
2488 {
2489 got_unsigned = 1;
2490 nbits = n3bits;
2491 }
2492 /* Range from <large number> to <large number>-1 is a large signed
2493 integral type. */
2494 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
2495 {
2496 got_signed = 1;
2497 nbits = n2bits;
2498 }
2499
2500 /* Check for "long long". */
2501 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
2502 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
2503 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
2504 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
2505
2506 if (got_signed || got_unsigned)
2507 {
2508 result_type = (struct type *)
2509 obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
2510 memset (result_type, 0, sizeof (struct type));
2511 TYPE_OBJFILE (result_type) = objfile;
2512 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
2513 TYPE_CODE (result_type) = TYPE_CODE_INT;
2514 if (got_unsigned)
2515 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
2516 return result_type;
2517 }
2518 else
2519 return error_type (pp);
2520 }
2521
2522 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2523 if (self_subrange && n2 == 0 && n3 == 0)
2524 return (lookup_fundamental_type (objfile, FT_VOID));
2525
2526 /* If n3 is zero and n2 is not, we want a floating type,
2527 and n2 is the width in bytes.
2528
2529 Fortran programs appear to use this for complex types also,
2530 and they give no way to distinguish between double and single-complex!
2531 We don't have complex types, so we would lose on all fortran files!
2532 So return type `double' for all of those. It won't work right
2533 for the complex values, but at least it makes the file loadable.
2534
2535 FIXME, we may be able to distinguish these by their names. FIXME. */
2536
2537 if (n3 == 0 && n2 > 0)
2538 {
2539 if (n2 == sizeof (float))
2540 return (lookup_fundamental_type (objfile, FT_FLOAT));
2541 return (lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT));
2542 }
2543
2544 /* If the upper bound is -1, it must really be an unsigned int. */
2545
2546 else if (n2 == 0 && n3 == -1)
2547 {
2548 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2549 long' is to look at its name! */
2550 if (
2551 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2552 long_kludge_name[9] == 'l' /* long */)
2553 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2554 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
2555 else
2556 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
2557 }
2558
2559 /* Special case: char is defined (Who knows why) as a subrange of
2560 itself with range 0-127. */
2561 else if (self_subrange && n2 == 0 && n3 == 127)
2562 return (lookup_fundamental_type (objfile, FT_CHAR));
2563
2564 /* Assumptions made here: Subrange of self is equivalent to subrange
2565 of int. FIXME: Host and target type-sizes assumed the same. */
2566 /* FIXME: This is the *only* place in GDB that depends on comparing
2567 some type to a builtin type with ==. Fix it! */
2568 else if (n2 == 0
2569 && (self_subrange ||
2570 *dbx_lookup_type (rangenums) == lookup_fundamental_type (objfile, FT_INTEGER)))
2571 {
2572 /* an unsigned type */
2573 #ifdef LONG_LONG
2574 if (n3 == - sizeof (long long))
2575 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
2576 #endif
2577 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
2578 long' is to look at its name! */
2579 if (n3 == (unsigned long)~0L &&
2580 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
2581 long_kludge_name[9] == 'l' /* long */)
2582 || (long_kludge_name[0] == 'l' /* long unsigned */)))
2583 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
2584 if (n3 == (unsigned int)~0L)
2585 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
2586 if (n3 == (unsigned short)~0L)
2587 return (lookup_fundamental_type (objfile, FT_UNSIGNED_SHORT));
2588 if (n3 == (unsigned char)~0L)
2589 return (lookup_fundamental_type (objfile, FT_UNSIGNED_CHAR));
2590 }
2591 #ifdef LONG_LONG
2592 else if (n3 == 0 && n2 == -sizeof (long long))
2593 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
2594 #endif
2595 else if (n2 == -n3 -1)
2596 {
2597 /* a signed type */
2598 /* FIXME -- the only way to distinguish `int' from `long' is to look
2599 at its name! */
2600 if ((n3 ==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2601 long_kludge_name && long_kludge_name[0] == 'l' /* long */)
2602 return (lookup_fundamental_type (objfile, FT_LONG));
2603 if (n3 == (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
2604 return (lookup_fundamental_type (objfile, FT_INTEGER));
2605 if (n3 == ( 1 << (8 * sizeof (short) - 1)) - 1)
2606 return (lookup_fundamental_type (objfile, FT_SHORT));
2607 if (n3 == ( 1 << (8 * sizeof (char) - 1)) - 1)
2608 return (lookup_fundamental_type (objfile, FT_SIGNED_CHAR));
2609 }
2610
2611 /* We have a real range type on our hands. Allocate space and
2612 return a real pointer. */
2613
2614 /* At this point I don't have the faintest idea how to deal with
2615 a self_subrange type; I'm going to assume that this is used
2616 as an idiom, and that all of them are special cases. So . . . */
2617 if (self_subrange)
2618 return error_type (pp);
2619
2620 result_type = (struct type *)
2621 obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
2622 memset (result_type, 0, sizeof (struct type));
2623 TYPE_OBJFILE (result_type) = objfile;
2624
2625 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
2626
2627 TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
2628 if (TYPE_TARGET_TYPE (result_type) == 0) {
2629 complain (&range_type_base_complaint, (char *) rangenums[1]);
2630 TYPE_TARGET_TYPE (result_type) = lookup_fundamental_type (objfile, FT_INTEGER);
2631 }
2632
2633 TYPE_NFIELDS (result_type) = 2;
2634 TYPE_FIELDS (result_type) = (struct field *)
2635 obstack_alloc (&objfile -> type_obstack, 2 * sizeof (struct field));
2636 memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
2637 TYPE_FIELD_BITPOS (result_type, 0) = n2;
2638 TYPE_FIELD_BITPOS (result_type, 1) = n3;
2639
2640 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
2641
2642 return result_type;
2643 }
2644
2645 /* Read a number from the string pointed to by *PP.
2646 The value of *PP is advanced over the number.
2647 If END is nonzero, the character that ends the
2648 number must match END, or an error happens;
2649 and that character is skipped if it does match.
2650 If END is zero, *PP is left pointing to that character. */
2651
2652 long
2653 read_number (pp, end)
2654 char **pp;
2655 int end;
2656 {
2657 register char *p = *pp;
2658 register long n = 0;
2659 register int c;
2660 int sign = 1;
2661
2662 /* Handle an optional leading minus sign. */
2663
2664 if (*p == '-')
2665 {
2666 sign = -1;
2667 p++;
2668 }
2669
2670 /* Read the digits, as far as they go. */
2671
2672 while ((c = *p++) >= '0' && c <= '9')
2673 {
2674 n *= 10;
2675 n += c - '0';
2676 }
2677 if (end)
2678 {
2679 if (c && c != end)
2680 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
2681 }
2682 else
2683 --p;
2684
2685 *pp = p;
2686 return n * sign;
2687 }
2688
2689 /* Read in an argument list. This is a list of types, separated by commas
2690 and terminated with END. Return the list of types read in, or (struct type
2691 **)-1 if there is an error. */
2692
2693 static struct type **
2694 read_args (pp, end, objfile)
2695 char **pp;
2696 int end;
2697 struct objfile *objfile;
2698 {
2699 /* FIXME! Remove this arbitrary limit! */
2700 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
2701 int n = 0;
2702
2703 while (**pp != end)
2704 {
2705 if (**pp != ',')
2706 /* Invalid argument list: no ','. */
2707 return (struct type **)-1;
2708 *pp += 1;
2709
2710 /* Check for and handle cretinous dbx symbol name continuation! */
2711 if (**pp == '\\')
2712 *pp = next_symbol_text ();
2713
2714 types[n++] = read_type (pp, objfile);
2715 }
2716 *pp += 1; /* get past `end' (the ':' character) */
2717
2718 if (n == 1)
2719 {
2720 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
2721 }
2722 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
2723 {
2724 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
2725 memset (rval + n, 0, sizeof (struct type *));
2726 }
2727 else
2728 {
2729 rval = (struct type **) xmalloc (n * sizeof (struct type *));
2730 }
2731 memcpy (rval, types, n * sizeof (struct type *));
2732 return rval;
2733 }
2734
2735 /* Add a common block's start address to the offset of each symbol
2736 declared to be in it (by being between a BCOMM/ECOMM pair that uses
2737 the common block name). */
2738
2739 static void
2740 fix_common_block (sym, valu)
2741 struct symbol *sym;
2742 int valu;
2743 {
2744 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
2745 for ( ; next; next = next->next)
2746 {
2747 register int j;
2748 for (j = next->nsyms - 1; j >= 0; j--)
2749 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
2750 }
2751 }
2752
2753
2754 \f
2755 /* What about types defined as forward references inside of a small lexical
2756 scope? */
2757 /* Add a type to the list of undefined types to be checked through
2758 once this file has been read in. */
2759
2760 void
2761 add_undefined_type (type)
2762 struct type *type;
2763 {
2764 if (undef_types_length == undef_types_allocated)
2765 {
2766 undef_types_allocated *= 2;
2767 undef_types = (struct type **)
2768 xrealloc ((char *) undef_types,
2769 undef_types_allocated * sizeof (struct type *));
2770 }
2771 undef_types[undef_types_length++] = type;
2772 }
2773
2774 /* Go through each undefined type, see if it's still undefined, and fix it
2775 up if possible. We have two kinds of undefined types:
2776
2777 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
2778 Fix: update array length using the element bounds
2779 and the target type's length.
2780 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
2781 yet defined at the time a pointer to it was made.
2782 Fix: Do a full lookup on the struct/union tag. */
2783 void
2784 cleanup_undefined_types ()
2785 {
2786 struct type **type;
2787
2788 for (type = undef_types; type < undef_types + undef_types_length; type++)
2789 {
2790 switch (TYPE_CODE (*type))
2791 {
2792
2793 case TYPE_CODE_STRUCT:
2794 case TYPE_CODE_UNION:
2795 case TYPE_CODE_ENUM:
2796 {
2797 /* Check if it has been defined since. */
2798 if (TYPE_FLAGS (*type) & TYPE_FLAG_STUB)
2799 {
2800 struct pending *ppt;
2801 int i;
2802 /* Name of the type, without "struct" or "union" */
2803 char *typename = TYPE_NAME (*type);
2804
2805 if (!strncmp (typename, "struct ", 7))
2806 typename += 7;
2807 if (!strncmp (typename, "union ", 6))
2808 typename += 6;
2809 if (!strncmp (typename, "enum ", 5))
2810 typename += 5;
2811
2812 for (ppt = file_symbols; ppt; ppt = ppt->next)
2813 {
2814 for (i = 0; i < ppt->nsyms; i++)
2815 {
2816 struct symbol *sym = ppt->symbol[i];
2817
2818 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
2819 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
2820 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
2821 TYPE_CODE (*type))
2822 && !strcmp (SYMBOL_NAME (sym), typename))
2823 {
2824 memcpy (*type, SYMBOL_TYPE (sym),
2825 sizeof (struct type));
2826 }
2827 }
2828 }
2829 }
2830 }
2831 break;
2832
2833 case TYPE_CODE_ARRAY:
2834 {
2835 struct type *range_type;
2836 int lower, upper;
2837
2838 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
2839 goto badtype;
2840 if (TYPE_NFIELDS (*type) != 1)
2841 goto badtype;
2842 range_type = TYPE_FIELD_TYPE (*type, 0);
2843 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
2844 goto badtype;
2845
2846 /* Now recompute the length of the array type, based on its
2847 number of elements and the target type's length. */
2848 lower = TYPE_FIELD_BITPOS (range_type, 0);
2849 upper = TYPE_FIELD_BITPOS (range_type, 1);
2850 TYPE_LENGTH (*type) = (upper - lower + 1)
2851 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
2852 }
2853 break;
2854
2855 default:
2856 badtype:
2857 error ("GDB internal error. cleanup_undefined_types with bad type %d.", TYPE_CODE (*type));
2858 break;
2859 }
2860 }
2861 undef_types_length = 0;
2862 }
2863
2864 /* Scan through all of the global symbols defined in the object file,
2865 assigning values to the debugging symbols that need to be assigned
2866 to. Get these symbols from the minimal symbol table. */
2867
2868 void
2869 scan_file_globals (objfile)
2870 struct objfile *objfile;
2871 {
2872 int hash;
2873 struct minimal_symbol *msymbol;
2874 struct symbol *sym, *prev;
2875
2876 if (objfile->msymbols == 0) /* Beware the null file. */
2877 return;
2878
2879 for (msymbol = objfile -> msymbols; msymbol -> name != NULL; msymbol++)
2880 {
2881 QUIT;
2882
2883 prev = NULL;
2884
2885 /* Get the hash index and check all the symbols
2886 under that hash index. */
2887
2888 hash = hashname (msymbol -> name);
2889
2890 for (sym = global_sym_chain[hash]; sym;)
2891 {
2892 if (*(msymbol -> name) == SYMBOL_NAME (sym)[0]
2893 && !strcmp(msymbol -> name + 1, SYMBOL_NAME (sym) + 1))
2894 {
2895 /* Splice this symbol out of the hash chain and
2896 assign the value we have to it. */
2897 if (prev)
2898 {
2899 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
2900 }
2901 else
2902 {
2903 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
2904 }
2905
2906 /* Check to see whether we need to fix up a common block. */
2907 /* Note: this code might be executed several times for
2908 the same symbol if there are multiple references. */
2909
2910 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
2911 {
2912 fix_common_block (sym, msymbol -> address);
2913 }
2914 else
2915 {
2916 SYMBOL_VALUE_ADDRESS (sym) = msymbol -> address;
2917 }
2918
2919 if (prev)
2920 {
2921 sym = SYMBOL_VALUE_CHAIN (prev);
2922 }
2923 else
2924 {
2925 sym = global_sym_chain[hash];
2926 }
2927 }
2928 else
2929 {
2930 prev = sym;
2931 sym = SYMBOL_VALUE_CHAIN (sym);
2932 }
2933 }
2934 }
2935 }
2936
2937 /* Initialize anything that needs initializing when starting to read
2938 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
2939 to a psymtab. */
2940
2941 void
2942 stabsread_init ()
2943 {
2944 }
2945
2946 /* Initialize anything that needs initializing when a completely new
2947 symbol file is specified (not just adding some symbols from another
2948 file, e.g. a shared library). */
2949
2950 void
2951 stabsread_new_init ()
2952 {
2953 /* Empty the hash table of global syms looking for values. */
2954 memset (global_sym_chain, 0, sizeof (global_sym_chain));
2955 }
2956
2957 /* Initialize anything that needs initializing at the same time as
2958 start_symtab() is called. */
2959
2960 void start_stabs ()
2961 {
2962 global_stabs = NULL; /* AIX COFF */
2963 /* Leave FILENUM of 0 free for builtin types and this file's types. */
2964 n_this_object_header_files = 1;
2965 type_vector_length = 0;
2966 type_vector = (struct type **) 0;
2967 }
2968
2969 /* Call after end_symtab() */
2970
2971 void end_stabs ()
2972 {
2973 if (type_vector)
2974 {
2975 free ((char *) type_vector);
2976 }
2977 type_vector = 0;
2978 type_vector_length = 0;
2979 previous_stab_code = 0;
2980 }
2981
2982 void
2983 finish_global_stabs (objfile)
2984
2985 struct objfile *objfile;
2986 {
2987 if (global_stabs)
2988 {
2989 patch_block_stabs (global_symbols, global_stabs, objfile);
2990 free ((PTR) global_stabs);
2991 global_stabs = NULL;
2992 }
2993 }
2994
2995 /* Initializer for this module */
2996
2997 void
2998 _initialize_stabsread ()
2999 {
3000 undef_types_allocated = 20;
3001 undef_types_length = 0;
3002 undef_types = (struct type **)
3003 xmalloc (undef_types_allocated * sizeof (struct type *));
3004 }
This page took 0.09148 seconds and 4 git commands to generate.