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