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