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