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