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