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