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