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