* buildsym.c (define_symbol): Nameless types are now on several
[deliverable/binutils-gdb.git] / gdb / buildsym.c
CommitLineData
c0302457 1/* Build symbol tables in GDB's internal format.
93297ea0
JG
2 Copyright 1986, 1987, 1988, 1989, 1990, 1991, 1992
3 Free Software Foundation, Inc.
c0302457
JG
4
5This file is part of GDB.
6
7This program is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2 of the License, or
10(at your option) any later version.
11
12This program is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with this program; if not, write to the Free Software
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20
21/* This module provides subroutines used for creating and adding to
22 the symbol table. These routines are called from various symbol-
23 file-reading routines.
24
25 They originated in dbxread.c of gdb-4.2, and were split out to
26 make xcoffread.c more maintainable by sharing code. */
27
28#include "defs.h"
c0302457
JG
29#include "obstack.h"
30#include "symtab.h"
1ab3bf1b 31#include "gdbtypes.h"
c0302457
JG
32#include "breakpoint.h"
33#include "gdbcore.h" /* for bfd stuff for symfile.h */
34#include "symfile.h" /* Needed for "struct complaint" */
5e2e79f8
FF
35#include "objfiles.h"
36#include "aout/stab_gnu.h" /* We always use GNU stabs, not native */
c0302457
JG
37#include <string.h>
38#include <ctype.h>
39
40/* Ask buildsym.h to define the vars it normally declares `extern'. */
41#define EXTERN /**/
42#include "buildsym.h" /* Our own declarations */
43#undef EXTERN
44
1ab3bf1b
JG
45static void
46patch_block_stabs PARAMS ((struct pending *, struct pending_stabs *,
47 struct objfile *));
c0302457 48
1ab3bf1b
JG
49static void
50read_huge_number PARAMS ((char **, int, long *, int *));
51
2b5a8d9c 52struct type *
1ab3bf1b
JG
53dbx_alloc_type PARAMS ((int [2], struct objfile *));
54
55static int
56compare_line_numbers PARAMS ((const void *, const void *));
57
58static struct blockvector *
59make_blockvector PARAMS ((struct objfile *));
60
61static void
62fix_common_block PARAMS ((struct symbol *, int));
63
64static void
65cleanup_undefined_types PARAMS ((void));
66
67static struct type *
68read_range_type PARAMS ((char **, int [2], struct objfile *));
abefb1f1 69
93297ea0
JG
70static struct type *
71read_sun_builtin_type PARAMS ((char **, int [2], struct objfile *));
72
73static struct type *
74read_sun_floating_type PARAMS ((char **, int [2], struct objfile *));
75
1ab3bf1b
JG
76static struct type *
77read_enum_type PARAMS ((char **, struct type *, struct objfile *));
78
79static struct type *
80read_struct_type PARAMS ((char **, struct type *, struct objfile *));
81
82static struct type *
83read_array_type PARAMS ((char **, struct type *, struct objfile *));
84
85static struct type **
86read_args PARAMS ((char **, int, struct objfile *));
87
88\f
c0302457
JG
89
90static const char vptr_name[] = { '_','v','p','t','r',CPLUS_MARKER,'\0' };
91static const char vb_name[] = { '_','v','b',CPLUS_MARKER,'\0' };
92
93/* Define this as 1 if a pcc declaration of a char or short argument
94 gives the correct address. Otherwise assume pcc gives the
95 address of the corresponding int, which is not the same on a
96 big-endian machine. */
97
98#ifndef BELIEVE_PCC_PROMOTION
99#define BELIEVE_PCC_PROMOTION 0
100#endif
101
2a5ec41d
JG
102/* During some calls to read_type (and thus to read_range_type), this
103 contains the name of the type being defined. Range types are only
104 used in C as basic types. We use the name to distinguish the otherwise
105 identical basic types "int" and "long" and their unsigned versions.
106 FIXME, this should disappear with better type management. */
107
108static char *long_kludge_name;
109
c0302457
JG
110/* Make a list of forward references which haven't been defined. */
111static struct type **undef_types;
112static int undef_types_allocated, undef_types_length;
113
4137c5fc
JG
114/* Initial sizes of data structures. These are realloc'd larger if needed,
115 and realloc'd down to the size actually used, when completed. */
116
117#define INITIAL_CONTEXT_STACK_SIZE 10
118#define INITIAL_TYPE_VECTOR_LENGTH 160
119#define INITIAL_LINE_VECTOR_LENGTH 1000
c0302457
JG
120\f
121/* Complaints about the symbols we have encountered. */
122
123struct complaint innerblock_complaint =
124 {"inner block not inside outer block in %s", 0, 0};
125
126struct complaint blockvector_complaint =
127 {"block at %x out of order", 0, 0};
128
129#if 0
130struct complaint dbx_class_complaint =
131 {"encountered DBX-style class variable debugging information.\n\
132You seem to have compiled your program with \
133\"g++ -g0\" instead of \"g++ -g\".\n\
134Therefore GDB will not know about your class variables", 0, 0};
135#endif
136
f1d77e90
JG
137struct complaint invalid_cpp_abbrev_complaint =
138 {"invalid C++ abbreviation `%s'", 0, 0};
139
140struct complaint invalid_cpp_type_complaint =
141 {"C++ abbreviated type name unknown at symtab pos %d", 0, 0};
142
143struct complaint member_fn_complaint =
144 {"member function type missing, got '%c'", 0, 0};
145
c0302457 146struct complaint const_vol_complaint =
f1d77e90 147 {"const/volatile indicator missing, got '%c'", 0, 0};
c0302457
JG
148
149struct complaint error_type_complaint =
150 {"debug info mismatch between compiler and debugger", 0, 0};
151
152struct complaint invalid_member_complaint =
153 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
154
155struct complaint range_type_base_complaint =
156 {"base type %d of range type is not defined", 0, 0};
84ffdec2
JG
157
158struct complaint reg_value_complaint =
159 {"register number too large in symbol %s", 0, 0};
1ab3bf1b
JG
160\f
161int
162hashname (name)
163 char *name;
164{
165 register char *p = name;
166 register int total = p[0];
167 register int c;
168
169 c = p[1];
170 total += c << 2;
171 if (c)
172 {
173 c = p[2];
174 total += c << 4;
175 if (c)
176 total += p[3] << 6;
177 }
178
179 /* Ensure result is positive. */
180 if (total < 0) total += (1000 << 6);
181 return total % HASHSIZE;
182}
183
c0302457
JG
184\f
185/* Look up a dbx type-number pair. Return the address of the slot
186 where the type for that number-pair is stored.
187 The number-pair is in TYPENUMS.
188
189 This can be used for finding the type associated with that pair
190 or for associating a new type with the pair. */
191
192struct type **
193dbx_lookup_type (typenums)
194 int typenums[2];
195{
196 register int filenum = typenums[0], index = typenums[1];
a048c8f5 197 unsigned old_len;
c0302457 198
ea1549b3
JG
199 if (filenum == -1) /* -1,-1 is for temporary types. */
200 return 0;
201
c0302457
JG
202 if (filenum < 0 || filenum >= n_this_object_header_files)
203 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
204 filenum, index, symnum);
205
206 if (filenum == 0)
207 {
208 /* Type is defined outside of header files.
209 Find it in this object file's type vector. */
a048c8f5 210 if (index >= type_vector_length)
c0302457 211 {
a048c8f5
JG
212 old_len = type_vector_length;
213 if (old_len == 0) {
214 type_vector_length = INITIAL_TYPE_VECTOR_LENGTH;
215 type_vector = (struct type **)
216 malloc (type_vector_length * sizeof (struct type *));
217 }
218 while (index >= type_vector_length)
219 type_vector_length *= 2;
c0302457 220 type_vector = (struct type **)
1ab3bf1b 221 xrealloc ((char *) type_vector,
c0302457 222 (type_vector_length * sizeof (struct type *)));
a048c8f5
JG
223 bzero (&type_vector[old_len],
224 (type_vector_length - old_len) * sizeof (struct type *));
c0302457
JG
225 }
226 return &type_vector[index];
227 }
228 else
229 {
230 register int real_filenum = this_object_header_files[filenum];
231 register struct header_file *f;
232 int f_orig_length;
233
234 if (real_filenum >= n_header_files)
235 abort ();
236
237 f = &header_files[real_filenum];
238
239 f_orig_length = f->length;
240 if (index >= f_orig_length)
241 {
242 while (index >= f->length)
243 f->length *= 2;
244 f->vector = (struct type **)
1ab3bf1b 245 xrealloc ((char *) f->vector, f->length * sizeof (struct type *));
c0302457
JG
246 bzero (&f->vector[f_orig_length],
247 (f->length - f_orig_length) * sizeof (struct type *));
248 }
249 return &f->vector[index];
250 }
251}
252
c0302457
JG
253/* Make sure there is a type allocated for type numbers TYPENUMS
254 and return the type object.
255 This can create an empty (zeroed) type object.
256 TYPENUMS may be (-1, -1) to return a new type object that is not
257 put into the type vector, and so may not be referred to by number. */
258
2b5a8d9c 259struct type *
1ab3bf1b 260dbx_alloc_type (typenums, objfile)
c0302457 261 int typenums[2];
1ab3bf1b 262 struct objfile *objfile;
c0302457
JG
263{
264 register struct type **type_addr;
c0302457 265
ea1549b3
JG
266 if (typenums[0] == -1)
267 return alloc_type (objfile);
268
269 type_addr = dbx_lookup_type (typenums);
c0302457
JG
270
271 /* If we are referring to a type not known at all yet,
272 allocate an empty type for it.
273 We will fill it in later if we find out how. */
ea1549b3
JG
274 if (*type_addr == 0)
275 *type_addr = alloc_type (objfile);
276
277 return *type_addr;
c0302457
JG
278}
279\f
280/* maintain the lists of symbols and blocks */
281
282/* Add a symbol to one of the lists of symbols. */
283void
284add_symbol_to_list (symbol, listhead)
285 struct symbol *symbol;
286 struct pending **listhead;
287{
288 /* We keep PENDINGSIZE symbols in each link of the list.
289 If we don't have a link with room in it, add a new link. */
290 if (*listhead == 0 || (*listhead)->nsyms == PENDINGSIZE)
291 {
292 register struct pending *link;
293 if (free_pendings)
294 {
295 link = free_pendings;
296 free_pendings = link->next;
297 }
298 else
299 link = (struct pending *) xmalloc (sizeof (struct pending));
300
301 link->next = *listhead;
302 *listhead = link;
303 link->nsyms = 0;
304 }
305
306 (*listhead)->symbol[(*listhead)->nsyms++] = symbol;
307}
308
a048c8f5
JG
309/* Find a symbol on a pending list. */
310struct symbol *
311find_symbol_in_list (list, name, length)
312 struct pending *list;
313 char *name;
314 int length;
315{
316 int j;
317
318 while (list) {
319 for (j = list->nsyms; --j >= 0; ) {
320 char *pp = SYMBOL_NAME (list->symbol[j]);
321 if (*pp == *name && strncmp (pp, name, length) == 0 && pp[length] == '\0')
322 return list->symbol[j];
323 }
324 list = list->next;
325 }
326 return NULL;
327}
328
c0302457
JG
329/* At end of reading syms, or in case of quit,
330 really free as many `struct pending's as we can easily find. */
331
332/* ARGSUSED */
333void
334really_free_pendings (foo)
335 int foo;
336{
337 struct pending *next, *next1;
338#if 0
339 struct pending_block *bnext, *bnext1;
340#endif
341
342 for (next = free_pendings; next; next = next1)
343 {
344 next1 = next->next;
84ffdec2 345 free ((PTR)next);
c0302457
JG
346 }
347 free_pendings = 0;
348
349#if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
350 for (bnext = pending_blocks; bnext; bnext = bnext1)
351 {
352 bnext1 = bnext->next;
84ffdec2 353 free ((PTR)bnext);
c0302457
JG
354 }
355#endif
356 pending_blocks = 0;
357
358 for (next = file_symbols; next; next = next1)
359 {
360 next1 = next->next;
84ffdec2 361 free ((PTR)next);
c0302457
JG
362 }
363 file_symbols = 0;
364
365 for (next = global_symbols; next; next = next1)
366 {
367 next1 = next->next;
84ffdec2 368 free ((PTR)next);
c0302457
JG
369 }
370 global_symbols = 0;
371}
372
373/* Take one of the lists of symbols and make a block from it.
374 Keep the order the symbols have in the list (reversed from the input file).
375 Put the block on the list of pending blocks. */
376
377void
1ab3bf1b 378finish_block (symbol, listhead, old_blocks, start, end, objfile)
c0302457
JG
379 struct symbol *symbol;
380 struct pending **listhead;
381 struct pending_block *old_blocks;
382 CORE_ADDR start, end;
1ab3bf1b 383 struct objfile *objfile;
c0302457
JG
384{
385 register struct pending *next, *next1;
386 register struct block *block;
387 register struct pending_block *pblock;
388 struct pending_block *opblock;
389 register int i;
390
391 /* Count the length of the list of symbols. */
392
a048c8f5
JG
393 for (next = *listhead, i = 0;
394 next;
395 i += next->nsyms, next = next->next)
c0302457
JG
396 /*EMPTY*/;
397
1ab3bf1b 398 block = (struct block *) obstack_alloc (&objfile -> symbol_obstack,
a048c8f5 399 (sizeof (struct block) + ((i - 1) * sizeof (struct symbol *))));
c0302457
JG
400
401 /* Copy the symbols into the block. */
402
403 BLOCK_NSYMS (block) = i;
404 for (next = *listhead; next; next = next->next)
405 {
406 register int j;
407 for (j = next->nsyms - 1; j >= 0; j--)
408 BLOCK_SYM (block, --i) = next->symbol[j];
409 }
410
411 BLOCK_START (block) = start;
412 BLOCK_END (block) = end;
413 BLOCK_SUPERBLOCK (block) = 0; /* Filled in when containing block is made */
414 BLOCK_GCC_COMPILED (block) = processing_gcc_compilation;
415
416 /* Put the block in as the value of the symbol that names it. */
417
418 if (symbol)
419 {
420 SYMBOL_BLOCK_VALUE (symbol) = block;
421 BLOCK_FUNCTION (block) = symbol;
422 }
423 else
424 BLOCK_FUNCTION (block) = 0;
425
426 /* Now "free" the links of the list, and empty the list. */
427
428 for (next = *listhead; next; next = next1)
429 {
430 next1 = next->next;
431 next->next = free_pendings;
432 free_pendings = next;
433 }
434 *listhead = 0;
435
436 /* Install this block as the superblock
437 of all blocks made since the start of this scope
438 that don't have superblocks yet. */
439
440 opblock = 0;
441 for (pblock = pending_blocks; pblock != old_blocks; pblock = pblock->next)
442 {
443 if (BLOCK_SUPERBLOCK (pblock->block) == 0) {
444#if 1
445 /* Check to be sure the blocks are nested as we receive them.
446 If the compiler/assembler/linker work, this just burns a small
447 amount of time. */
448 if (BLOCK_START (pblock->block) < BLOCK_START (block)
449 || BLOCK_END (pblock->block) > BLOCK_END (block)) {
450 complain(&innerblock_complaint, symbol? SYMBOL_NAME (symbol):
451 "(don't know)");
452 BLOCK_START (pblock->block) = BLOCK_START (block);
453 BLOCK_END (pblock->block) = BLOCK_END (block);
454 }
455#endif
456 BLOCK_SUPERBLOCK (pblock->block) = block;
457 }
458 opblock = pblock;
459 }
460
461 /* Record this block on the list of all blocks in the file.
462 Put it after opblock, or at the beginning if opblock is 0.
463 This puts the block in the list after all its subblocks. */
464
465 /* Allocate in the symbol_obstack to save time.
466 It wastes a little space. */
467 pblock = (struct pending_block *)
1ab3bf1b 468 obstack_alloc (&objfile -> symbol_obstack,
c0302457
JG
469 sizeof (struct pending_block));
470 pblock->block = block;
471 if (opblock)
472 {
473 pblock->next = opblock->next;
474 opblock->next = pblock;
475 }
476 else
477 {
478 pblock->next = pending_blocks;
479 pending_blocks = pblock;
480 }
481}
482
1ab3bf1b
JG
483static struct blockvector *
484make_blockvector (objfile)
485 struct objfile *objfile;
c0302457
JG
486{
487 register struct pending_block *next;
488 register struct blockvector *blockvector;
489 register int i;
490
491 /* Count the length of the list of blocks. */
492
493 for (next = pending_blocks, i = 0; next; next = next->next, i++);
494
495 blockvector = (struct blockvector *)
1ab3bf1b 496 obstack_alloc (&objfile -> symbol_obstack,
c0302457
JG
497 (sizeof (struct blockvector)
498 + (i - 1) * sizeof (struct block *)));
499
500 /* Copy the blocks into the blockvector.
501 This is done in reverse order, which happens to put
502 the blocks into the proper order (ascending starting address).
503 finish_block has hair to insert each block into the list
504 after its subblocks in order to make sure this is true. */
505
506 BLOCKVECTOR_NBLOCKS (blockvector) = i;
507 for (next = pending_blocks; next; next = next->next) {
508 BLOCKVECTOR_BLOCK (blockvector, --i) = next->block;
509 }
510
511#if 0 /* Now we make the links in the obstack, so don't free them. */
512 /* Now free the links of the list, and empty the list. */
513
514 for (next = pending_blocks; next; next = next1)
515 {
516 next1 = next->next;
517 free (next);
518 }
519#endif
520 pending_blocks = 0;
521
522#if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
523 /* Some compilers output blocks in the wrong order, but we depend
524 on their being in the right order so we can binary search.
525 Check the order and moan about it. FIXME. */
526 if (BLOCKVECTOR_NBLOCKS (blockvector) > 1)
527 for (i = 1; i < BLOCKVECTOR_NBLOCKS (blockvector); i++) {
528 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i-1))
529 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i))) {
530 complain (&blockvector_complaint,
1ab3bf1b 531 (char *) BLOCK_START(BLOCKVECTOR_BLOCK (blockvector, i)));
c0302457
JG
532 }
533 }
534#endif
535
536 return blockvector;
537}
538\f
4137c5fc
JG
539/* Start recording information about source code that came from an included
540 (or otherwise merged-in) source file with a different name. */
c0302457
JG
541
542void
4137c5fc
JG
543start_subfile (name, dirname)
544 char *name;
545 char *dirname;
546{
547 register struct subfile *subfile;
548
549 /* See if this subfile is already known as a subfile of the
550 current main source file. */
551
552 for (subfile = subfiles; subfile; subfile = subfile->next)
553 {
554 if (!strcmp (subfile->name, name))
555 {
556 current_subfile = subfile;
557 return;
558 }
559 }
560
561 /* This subfile is not known. Add an entry for it.
562 Make an entry for this subfile in the list of all subfiles
563 of the current main source file. */
564
565 subfile = (struct subfile *) xmalloc (sizeof (struct subfile));
566 subfile->next = subfiles;
567 subfiles = subfile;
568 current_subfile = subfile;
569
570 /* Save its name and compilation directory name */
1ab3bf1b 571 subfile->name = strdup (name);
4137c5fc
JG
572 if (dirname == NULL)
573 subfile->dirname = NULL;
574 else
1ab3bf1b 575 subfile->dirname = strdup (dirname);
4137c5fc
JG
576
577 /* Initialize line-number recording for this subfile. */
578 subfile->line_vector = 0;
579}
580\f
a048c8f5
JG
581/* Handle the N_BINCL and N_EINCL symbol types
582 that act like N_SOL for switching source files
583 (different subfiles, as we call them) within one object file,
584 but using a stack rather than in an arbitrary order. */
585
586void
587push_subfile ()
588{
589 register struct subfile_stack *tem
590 = (struct subfile_stack *) xmalloc (sizeof (struct subfile_stack));
591
592 tem->next = subfile_stack;
593 subfile_stack = tem;
594 if (current_subfile == 0 || current_subfile->name == 0)
595 abort ();
596 tem->name = current_subfile->name;
a048c8f5
JG
597}
598
599char *
600pop_subfile ()
601{
602 register char *name;
603 register struct subfile_stack *link = subfile_stack;
604
605 if (link == 0)
606 abort ();
607
608 name = link->name;
609 subfile_stack = link->next;
84ffdec2 610 free ((PTR)link);
a048c8f5
JG
611
612 return name;
613}
614\f
4137c5fc
JG
615/* Manage the vector of line numbers for each subfile. */
616
617void
618record_line (subfile, line, pc)
619 register struct subfile *subfile;
c0302457
JG
620 int line;
621 CORE_ADDR pc;
622{
623 struct linetable_entry *e;
624 /* Ignore the dummy line number in libg.o */
625
626 if (line == 0xffff)
627 return;
628
4137c5fc
JG
629 /* Make sure line vector exists and is big enough. */
630 if (!subfile->line_vector) {
631 subfile->line_vector_length = INITIAL_LINE_VECTOR_LENGTH;
632 subfile->line_vector = (struct linetable *)
633 xmalloc (sizeof (struct linetable)
634 + subfile->line_vector_length * sizeof (struct linetable_entry));
635 subfile->line_vector->nitems = 0;
636 }
c0302457 637
4137c5fc 638 if (subfile->line_vector->nitems + 1 >= subfile->line_vector_length)
c0302457 639 {
4137c5fc
JG
640 subfile->line_vector_length *= 2;
641 subfile->line_vector = (struct linetable *)
1ab3bf1b 642 xrealloc ((char *) subfile->line_vector, (sizeof (struct linetable)
4137c5fc 643 + subfile->line_vector_length * sizeof (struct linetable_entry)));
c0302457
JG
644 }
645
4137c5fc 646 e = subfile->line_vector->item + subfile->line_vector->nitems++;
c0302457
JG
647 e->line = line; e->pc = pc;
648}
4137c5fc
JG
649
650
651/* Needed in order to sort line tables from IBM xcoff files. Sigh! */
652
1ab3bf1b
JG
653static int
654compare_line_numbers (ln1p, ln2p)
655 const PTR ln1p;
656 const PTR ln2p;
4137c5fc 657{
1ab3bf1b
JG
658 return (((struct linetable_entry *) ln1p) -> line -
659 ((struct linetable_entry *) ln2p) -> line);
4137c5fc 660}
1ab3bf1b 661
c0302457
JG
662\f
663/* Start a new symtab for a new source file.
664 This is called when a dbx symbol of type N_SO is seen;
665 it indicates the start of data for one original source file. */
666
667void
668start_symtab (name, dirname, start_addr)
669 char *name;
670 char *dirname;
671 CORE_ADDR start_addr;
672{
673
674 last_source_file = name;
675 last_source_start_addr = start_addr;
676 file_symbols = 0;
677 global_symbols = 0;
4137c5fc 678 global_stabs = 0; /* AIX COFF */
c0302457
JG
679 within_function = 0;
680
a048c8f5
JG
681 /* Context stack is initially empty. Allocate first one with room for
682 10 levels; reuse it forever afterward. */
683 if (context_stack == 0) {
684 context_stack_size = INITIAL_CONTEXT_STACK_SIZE;
685 context_stack = (struct context_stack *)
686 xmalloc (context_stack_size * sizeof (struct context_stack));
687 }
c0302457
JG
688 context_stack_depth = 0;
689
1ab3bf1b
JG
690 /* Leave FILENUM of 0 free for builtin types and this file's types. */
691 n_this_object_header_files = 1;
c0302457 692
a048c8f5
JG
693 type_vector_length = 0;
694 type_vector = (struct type **) 0;
c0302457
JG
695
696 /* Initialize the list of sub source files with one entry
697 for this file (the top-level source file). */
698
699 subfiles = 0;
700 current_subfile = 0;
701 start_subfile (name, dirname);
702}
703
1ab3bf1b
JG
704/* for all the stabs in a given stab vector, build appropriate types
705 and fix their symbols in given symbol vector. */
706
707static void
708patch_block_stabs (symbols, stabs, objfile)
709 struct pending *symbols;
710 struct pending_stabs *stabs;
711 struct objfile *objfile;
712{
713 int ii;
714
715 if (stabs)
716 {
717
718 /* for all the stab entries, find their corresponding symbols and
719 patch their types! */
720
721 for (ii = 0; ii < stabs->count; ++ii)
722 {
723 char *name = stabs->stab[ii];
724 char *pp = (char*) strchr (name, ':');
725 struct symbol *sym = find_symbol_in_list (symbols, name, pp-name);
726 if (!sym)
727 {
1eeba686 728#ifndef IBM6000_TARGET
1ab3bf1b 729 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
6c6afbb9 730#endif
1ab3bf1b
JG
731 }
732 else
733 {
734 pp += 2;
735 if (*(pp-1) == 'F' || *(pp-1) == 'f')
736 {
737 SYMBOL_TYPE (sym) =
738 lookup_function_type (read_type (&pp, objfile));
739 }
740 else
741 {
742 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
743 }
744 }
745 }
746 }
747}
748
c0302457
JG
749/* Finish the symbol definitions for one main source file,
750 close off all the lexical contexts for that file
751 (creating struct block's for them), then make the struct symtab
752 for that file and put it in the list of all such.
753
754 END_ADDR is the address of the end of the file's text. */
755
756struct symtab *
a048c8f5 757end_symtab (end_addr, sort_pending, sort_linevec, objfile)
c0302457 758 CORE_ADDR end_addr;
4137c5fc
JG
759 int sort_pending;
760 int sort_linevec;
a048c8f5 761 struct objfile *objfile;
c0302457
JG
762{
763 register struct symtab *symtab;
764 register struct blockvector *blockvector;
765 register struct subfile *subfile;
c0302457
JG
766 struct subfile *nextsub;
767
768 /* Finish the lexical context of the last function in the file;
769 pop the context stack. */
770
771 if (context_stack_depth > 0)
772 {
773 register struct context_stack *cstk;
774 context_stack_depth--;
775 cstk = &context_stack[context_stack_depth];
776 /* Make a block for the local symbols within. */
777 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
1ab3bf1b 778 cstk->start_addr, end_addr, objfile);
a048c8f5
JG
779
780 /* Debug: if context stack still has something in it, we are in
781 trouble. */
782 if (context_stack_depth > 0)
783 abort ();
c0302457
JG
784 }
785
4137c5fc
JG
786 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
787 in this stage. Especially, blocks for static functions will show up at
788 the end. We need to sort them, so tools like `find_pc_function' and
789 `find_pc_block' can work reliably. */
a048c8f5 790 if (sort_pending && pending_blocks) {
4137c5fc
JG
791 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
792 int swapped;
793 do {
794 struct pending_block *pb, *pbnext;
795
796 pb = pending_blocks, pbnext = pb->next;
797 swapped = 0;
798
799 while ( pbnext ) {
800
801 /* swap blocks if unordered! */
802
803 if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block)) {
804 struct block *tmp = pb->block;
805 pb->block = pbnext->block;
806 pbnext->block = tmp;
807 swapped = 1;
808 }
809 pb = pbnext;
810 pbnext = pbnext->next;
811 }
812 } while (swapped);
813 }
814
c0302457
JG
815 /* Cleanup any undefined types that have been left hanging around
816 (this needs to be done before the finish_blocks so that
817 file_symbols is still good). */
818 cleanup_undefined_types ();
819
74f6fb08 820 if (global_stabs) {
1ab3bf1b 821 patch_block_stabs (global_symbols, global_stabs, objfile);
84ffdec2 822 free ((PTR)global_stabs);
74f6fb08
JG
823 global_stabs = 0;
824 }
825
a048c8f5
JG
826 if (pending_blocks == 0
827 && file_symbols == 0
828 && global_symbols == 0) {
829 /* Ignore symtabs that have no functions with real debugging info */
830 blockvector = NULL;
831 } else {
832 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
1ab3bf1b
JG
833 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr, objfile);
834 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr, objfile);
835 blockvector = make_blockvector (objfile);
a048c8f5 836 }
c0302457 837
818de002
PB
838#ifdef PROCESS_LINENUMBER_HOOK
839 PROCESS_LINENUMBER_HOOK (); /* Needed for aixcoff. */
840#endif
841
c0302457
JG
842 /* Now create the symtab objects proper, one for each subfile. */
843 /* (The main file is the last one on the chain.) */
844
845 for (subfile = subfiles; subfile; subfile = nextsub)
846 {
1ab3bf1b 847 int linetablesize;
a048c8f5
JG
848 /* If we have blocks of symbols, make a symtab.
849 Otherwise, just ignore this file and any line number info in it. */
850 symtab = 0;
851 if (blockvector) {
852 if (subfile->line_vector) {
853 /* First, shrink the linetable to make more memory. */
1ab3bf1b
JG
854 linetablesize = sizeof (struct linetable) +
855 subfile->line_vector->nitems * sizeof (struct linetable_entry);
a048c8f5 856 subfile->line_vector = (struct linetable *)
1ab3bf1b 857 xrealloc ((char *) subfile->line_vector, linetablesize);
a048c8f5
JG
858
859 if (sort_linevec)
860 qsort (subfile->line_vector->item, subfile->line_vector->nitems,
861 sizeof (struct linetable_entry), compare_line_numbers);
862 }
4137c5fc 863
a048c8f5
JG
864 /* Now, allocate a symbol table. */
865 symtab = allocate_symtab (subfile->name, objfile);
866
867 /* Fill in its components. */
868 symtab->blockvector = blockvector;
1ab3bf1b
JG
869 if (subfile->line_vector)
870 {
871 /* Reallocate the line table on the symbol obstack */
872 symtab->linetable = (struct linetable *)
873 obstack_alloc (&objfile -> symbol_obstack, linetablesize);
874 memcpy (symtab->linetable, subfile->line_vector, linetablesize);
875 }
876 else
877 {
878 symtab->linetable = NULL;
879 }
a048c8f5
JG
880 symtab->dirname = subfile->dirname;
881 symtab->free_code = free_linetable;
882 symtab->free_ptr = 0;
2b5a8d9c 883
1eeba686 884#ifdef IBM6000_TARGET
2b5a8d9c
PB
885 /* In case we need to duplicate symbol tables (to represent include
886 files), and in case our system needs relocation, we want to
887 relocate the main symbol table node only (for the main file,
888 not for the include files). */
889
890 symtab->nonreloc = TRUE;
891#endif
4137c5fc 892 }
1ab3bf1b 893 if (subfile->line_vector)
84ffdec2 894 free ((PTR)subfile->line_vector);
4137c5fc 895
c0302457 896 nextsub = subfile->next;
84ffdec2 897 free ((PTR)subfile);
c0302457
JG
898 }
899
1eeba686 900#ifdef IBM6000_TARGET
2b5a8d9c
PB
901 /* all include symbol tables are non-relocatable, except the main source
902 file's. */
1eeba686
PB
903 if (symtab)
904 symtab->nonreloc = FALSE;
2b5a8d9c
PB
905#endif
906
a048c8f5
JG
907 if (type_vector)
908 free ((char *) type_vector);
c0302457 909 type_vector = 0;
a048c8f5 910 type_vector_length = 0;
4137c5fc 911
c0302457 912 last_source_file = 0;
4137c5fc 913 current_subfile = 0;
7e258d18 914 previous_stab_code = 0;
c0302457
JG
915
916 return symtab;
917}
a048c8f5
JG
918
919
920/* Push a context block. Args are an identifying nesting level (checkable
921 when you pop it), and the starting PC address of this context. */
922
923struct context_stack *
924push_context (desc, valu)
925 int desc;
926 CORE_ADDR valu;
927{
928 register struct context_stack *new;
929
930 if (context_stack_depth == context_stack_size)
931 {
932 context_stack_size *= 2;
933 context_stack = (struct context_stack *)
1ab3bf1b
JG
934 xrealloc ((char *) context_stack,
935 (context_stack_size * sizeof (struct context_stack)));
a048c8f5
JG
936 }
937
938 new = &context_stack[context_stack_depth++];
939 new->depth = desc;
940 new->locals = local_symbols;
941 new->old_blocks = pending_blocks;
942 new->start_addr = valu;
943 new->name = 0;
944
945 local_symbols = 0;
946
947 return new;
948}
c0302457
JG
949\f
950/* Initialize anything that needs initializing when starting to read
951 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
952 to a psymtab. */
953
954void
955buildsym_init ()
956{
957 free_pendings = 0;
958 file_symbols = 0;
959 global_symbols = 0;
960 pending_blocks = 0;
961}
962
963/* Initialize anything that needs initializing when a completely new
964 symbol file is specified (not just adding some symbols from another
965 file, e.g. a shared library). */
966
967void
968buildsym_new_init ()
969{
970 /* Empty the hash table of global syms looking for values. */
971 bzero (global_sym_chain, sizeof global_sym_chain);
972
973 buildsym_init ();
974}
975
976/* Scan through all of the global symbols defined in the object file,
977 assigning values to the debugging symbols that need to be assigned
1ab3bf1b 978 to. Get these symbols from the minimal symbol table. */
c0302457
JG
979
980void
1ab3bf1b
JG
981scan_file_globals (objfile)
982 struct objfile *objfile;
c0302457
JG
983{
984 int hash;
1ab3bf1b
JG
985 struct minimal_symbol *msymbol;
986 struct symbol *sym, *prev;
c0302457 987
1ab3bf1b 988 for (msymbol = objfile -> msymbols; msymbol -> name != NULL; msymbol++)
c0302457 989 {
c0302457
JG
990 QUIT;
991
992 prev = (struct symbol *) 0;
993
994 /* Get the hash index and check all the symbols
995 under that hash index. */
996
1ab3bf1b 997 hash = hashname (msymbol -> name);
c0302457
JG
998
999 for (sym = global_sym_chain[hash]; sym;)
1000 {
1ab3bf1b
JG
1001 if (*(msymbol -> name) == SYMBOL_NAME (sym)[0]
1002 && !strcmp(msymbol -> name + 1, SYMBOL_NAME (sym) + 1))
c0302457
JG
1003 {
1004 /* Splice this symbol out of the hash chain and
1005 assign the value we have to it. */
1006 if (prev)
1007 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1008 else
1009 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1010
1011 /* Check to see whether we need to fix up a common block. */
1012 /* Note: this code might be executed several times for
1013 the same symbol if there are multiple references. */
1014 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
1ab3bf1b 1015 fix_common_block (sym, msymbol -> address);
c0302457 1016 else
1ab3bf1b 1017 SYMBOL_VALUE_ADDRESS (sym) = msymbol -> address;
c0302457
JG
1018
1019 if (prev)
1020 sym = SYMBOL_VALUE_CHAIN (prev);
1021 else
1022 sym = global_sym_chain[hash];
1023 }
1024 else
1025 {
1026 prev = sym;
1027 sym = SYMBOL_VALUE_CHAIN (sym);
1028 }
1029 }
1030 }
1031}
1032
1033\f
1034/* Read a number by which a type is referred to in dbx data,
1035 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1036 Just a single number N is equivalent to (0,N).
1037 Return the two numbers by storing them in the vector TYPENUMS.
1038 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1039
1040void
1041read_type_number (pp, typenums)
1042 register char **pp;
1043 register int *typenums;
1044{
1045 if (**pp == '(')
1046 {
1047 (*pp)++;
1048 typenums[0] = read_number (pp, ',');
1049 typenums[1] = read_number (pp, ')');
1050 }
1051 else
1052 {
1053 typenums[0] = 0;
1054 typenums[1] = read_number (pp, 0);
1055 }
1056}
1057\f
1058/* To handle GNU C++ typename abbreviation, we need to be able to
1059 fill in a type's name as soon as space for that type is allocated.
1060 `type_synonym_name' is the name of the type being allocated.
1061 It is cleared as soon as it is used (lest all allocated types
1062 get this name). */
1063static char *type_synonym_name;
1064
1065/* ARGSUSED */
abefb1f1 1066struct symbol *
1ab3bf1b 1067define_symbol (valu, string, desc, type, objfile)
c0302457
JG
1068 unsigned int valu;
1069 char *string;
1070 int desc;
1071 int type;
1ab3bf1b 1072 struct objfile *objfile;
c0302457
JG
1073{
1074 register struct symbol *sym;
1075 char *p = (char *) strchr (string, ':');
1076 int deftype;
1077 int synonym = 0;
1078 register int i;
1ab3bf1b 1079 struct type *temptype;
c0302457 1080
095db7ce
PB
1081 /* We would like to eliminate nameless symbols, but keep their types.
1082 E.g. stab entry ":t10=*2" should produce a type 10, which is a pointer
1083 to type 2, but, should not creat a symbol to address that type. Since
1084 the symbol will be nameless, there is no way any user can refer to it. */
1085
1086 int nameless;
095db7ce 1087
c0302457
JG
1088 /* Ignore syms with empty names. */
1089 if (string[0] == 0)
1090 return 0;
1091
1092 /* Ignore old-style symbols from cc -go */
1093 if (p == 0)
1094 return 0;
1095
095db7ce
PB
1096 /* If a nameless stab entry, all we need is the type, not the symbol.
1097 e.g. ":t10=*2" */
1098 nameless = (p == string);
095db7ce 1099
1ab3bf1b 1100 sym = (struct symbol *)obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
c0302457
JG
1101
1102 if (processing_gcc_compilation) {
1103 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1104 number of bytes occupied by a type or object, which we ignore. */
1105 SYMBOL_LINE(sym) = desc;
1106 } else {
1107 SYMBOL_LINE(sym) = 0; /* unknown */
1108 }
1109
1110 if (string[0] == CPLUS_MARKER)
1111 {
1112 /* Special GNU C++ names. */
1113 switch (string[1])
1114 {
1115 case 't':
1ab3bf1b
JG
1116 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1117 &objfile -> symbol_obstack);
c0302457
JG
1118 break;
1119 case 'v': /* $vtbl_ptr_type */
1120 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1121 goto normal;
1122 case 'e':
1ab3bf1b
JG
1123 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1124 &objfile -> symbol_obstack);
c0302457
JG
1125 break;
1126
1127 case '_':
1128 /* This was an anonymous type that was never fixed up. */
1129 goto normal;
1130
1131 default:
1132 abort ();
1133 }
1134 }
1135 else
1136 {
1137 normal:
1138 SYMBOL_NAME (sym)
1ab3bf1b 1139 = (char *) obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
c0302457
JG
1140 /* Open-coded bcopy--saves function call time. */
1141 {
1142 register char *p1 = string;
1143 register char *p2 = SYMBOL_NAME (sym);
1144 while (p1 != p)
1145 *p2++ = *p1++;
1146 *p2++ = '\0';
1147 }
1148 }
1149 p++;
1150 /* Determine the type of name being defined. */
1151 /* The Acorn RISC machine's compiler can put out locals that don't
1152 start with "234=" or "(3,4)=", so assume anything other than the
1153 deftypes we know how to handle is a local. */
1154 /* (Peter Watkins @ Computervision)
1155 Handle Sun-style local fortran array types 'ar...' .
1156 (gnu@cygnus.com) -- this strchr() handles them properly?
1157 (tiemann@cygnus.com) -- 'C' is for catch. */
095db7ce
PB
1158
1159#ifdef IBM6000_TARGET
1160
1161 /* 'R' is for register parameters. */
1162
1163 if (!strchr ("cfFGpPrStTvVXCR", *p))
1164#else
1165
c0302457 1166 if (!strchr ("cfFGpPrStTvVXC", *p))
095db7ce 1167#endif
c0302457
JG
1168 deftype = 'l';
1169 else
1170 deftype = *p++;
1171
1172 /* c is a special case, not followed by a type-number.
1173 SYMBOL:c=iVALUE for an integer constant symbol.
1174 SYMBOL:c=rVALUE for a floating constant symbol.
1175 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1176 e.g. "b:c=e6,0" for "const b = blob1"
1177 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1178 if (deftype == 'c')
1179 {
1180 if (*p++ != '=')
1181 error ("Invalid symbol data at symtab pos %d.", symnum);
1182 switch (*p++)
1183 {
1184 case 'r':
1185 {
1186 double d = atof (p);
1187 char *dbl_valu;
1188
1ab3bf1b
JG
1189 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1190 FT_DBL_PREC_FLOAT);
1191 dbl_valu = (char *)
1192 obstack_alloc (&objfile -> type_obstack,
1193 sizeof (double));
7e258d18 1194 memcpy (dbl_valu, &d, sizeof (double));
c0302457
JG
1195 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
1196 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1197 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1198 }
1199 break;
1200 case 'i':
1201 {
1ab3bf1b
JG
1202 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1203 FT_INTEGER);
c0302457
JG
1204 SYMBOL_VALUE (sym) = atoi (p);
1205 SYMBOL_CLASS (sym) = LOC_CONST;
1206 }
1207 break;
1208 case 'e':
1209 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1210 e.g. "b:c=e6,0" for "const b = blob1"
1211 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1212 {
1213 int typenums[2];
1214
1215 read_type_number (&p, typenums);
1216 if (*p++ != ',')
1217 error ("Invalid symbol data: no comma in enum const symbol");
1218
1219 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
1220 SYMBOL_VALUE (sym) = atoi (p);
1221 SYMBOL_CLASS (sym) = LOC_CONST;
1222 }
1223 break;
1224 default:
1225 error ("Invalid symbol data at symtab pos %d.", symnum);
1226 }
1227 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1228 add_symbol_to_list (sym, &file_symbols);
1229 return sym;
1230 }
1231
1232 /* Now usually comes a number that says which data type,
1233 and possibly more stuff to define the type
1234 (all of which is handled by read_type) */
1235
1236 if (deftype == 'p' && *p == 'F')
1237 /* pF is a two-letter code that means a function parameter in Fortran.
1238 The type-number specifies the type of the return value.
1239 Translate it into a pointer-to-function type. */
1240 {
1241 p++;
1242 SYMBOL_TYPE (sym)
1ab3bf1b 1243 = lookup_pointer_type (lookup_function_type (read_type (&p, objfile)));
c0302457 1244 }
095db7ce
PB
1245
1246#ifdef IBM6000_TARGET
1247 else if (deftype == 'R')
9b6f92db 1248 SYMBOL_TYPE (sym) = read_type (&p, objfile);
095db7ce
PB
1249#endif
1250
c0302457
JG
1251 else
1252 {
1253 struct type *type_read;
1254 synonym = *p == 't';
1255
1256 if (synonym)
1257 {
1258 p += 1;
1259 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
1ab3bf1b
JG
1260 strlen (SYMBOL_NAME (sym)),
1261 &objfile -> symbol_obstack);
c0302457
JG
1262 }
1263
2a5ec41d
JG
1264 /* Here we save the name of the symbol for read_range_type, which
1265 ends up reading in the basic types. In stabs, unfortunately there
1266 is no distinction between "int" and "long" types except their
1267 names. Until we work out a saner type policy (eliminating most
1268 builtin types and using the names specified in the files), we
1269 save away the name so that far away from here in read_range_type,
1270 we can examine it to decide between "int" and "long". FIXME. */
1271 long_kludge_name = SYMBOL_NAME (sym);
ea1549b3 1272
1ab3bf1b 1273 type_read = read_type (&p, objfile);
c0302457 1274
93297ea0
JG
1275 if ((deftype == 'F' || deftype == 'f') && *p == ';') {
1276 /* Sun acc puts declared types of aguments here. We don't care
1277 about their actual types (FIXME -- we should remember the whole
1278 function prototype), but the list
1279 may define some new types that we have to remember, so we must
1280 scan them now. */
1281 while (*p == ';') {
1282 p++;
0dce456e 1283 read_type (&p, objfile);
93297ea0
JG
1284 }
1285 }
1286
c0302457
JG
1287 if ((deftype == 'F' || deftype == 'f')
1288 && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
1289 {
1290#if 0
1291/* This code doesn't work -- it needs to realloc and can't. */
93297ea0 1292/* Attempt to set up to record a function prototype... */
c0302457 1293 struct type *new = (struct type *)
1ab3bf1b
JG
1294 obstack_alloc (&objfile -> type_obstack,
1295 sizeof (struct type));
c0302457
JG
1296
1297 /* Generate a template for the type of this function. The
1298 types of the arguments will be added as we read the symbol
1299 table. */
1300 *new = *lookup_function_type (type_read);
1301 SYMBOL_TYPE(sym) = new;
1ab3bf1b 1302 TYPE_OBJFILE (new) = objfile;
c0302457
JG
1303 in_function_type = new;
1304#else
1305 SYMBOL_TYPE (sym) = lookup_function_type (type_read);
1306#endif
1307 }
1308 else
1309 SYMBOL_TYPE (sym) = type_read;
1310 }
1311
1312 switch (deftype)
1313 {
1314 case 'C':
1315 /* The name of a caught exception. */
1316 SYMBOL_CLASS (sym) = LOC_LABEL;
1317 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1318 SYMBOL_VALUE_ADDRESS (sym) = valu;
1319 add_symbol_to_list (sym, &local_symbols);
1320 break;
1321
1322 case 'f':
1323 SYMBOL_CLASS (sym) = LOC_BLOCK;
1324 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1325 add_symbol_to_list (sym, &file_symbols);
1326 break;
1327
1328 case 'F':
1329 SYMBOL_CLASS (sym) = LOC_BLOCK;
1330 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1331 add_symbol_to_list (sym, &global_symbols);
1332 break;
1333
1334 case 'G':
1335 /* For a class G (global) symbol, it appears that the
1336 value is not correct. It is necessary to search for the
1337 corresponding linker definition to find the value.
1338 These definitions appear at the end of the namelist. */
1339 i = hashname (SYMBOL_NAME (sym));
1340 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1341 global_sym_chain[i] = sym;
1342 SYMBOL_CLASS (sym) = LOC_STATIC;
1343 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1344 add_symbol_to_list (sym, &global_symbols);
1345 break;
1346
1347 /* This case is faked by a conditional above,
1348 when there is no code letter in the dbx data.
1349 Dbx data never actually contains 'l'. */
1350 case 'l':
1351 SYMBOL_CLASS (sym) = LOC_LOCAL;
1352 SYMBOL_VALUE (sym) = valu;
1353 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1354 add_symbol_to_list (sym, &local_symbols);
1355 break;
1356
1357 case 'p':
1358 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1359 can also be a LOC_LOCAL_ARG depending on symbol type. */
1360#ifndef DBX_PARM_SYMBOL_CLASS
1361#define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1362#endif
1363 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1364 SYMBOL_VALUE (sym) = valu;
1365 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1366#if 0
1367 /* This doesn't work yet. */
1368 add_param_to_type (&in_function_type, sym);
1369#endif
1370 add_symbol_to_list (sym, &local_symbols);
1371
1372 /* If it's gcc-compiled, if it says `short', believe it. */
1373 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1374 break;
1375
1376#if defined(BELIEVE_PCC_PROMOTION_TYPE)
1377 /* This macro is defined on machines (e.g. sparc) where
1378 we should believe the type of a PCC 'short' argument,
1379 but shouldn't believe the address (the address is
1380 the address of the corresponding int). Note that
1381 this is only different from the BELIEVE_PCC_PROMOTION
1382 case on big-endian machines.
1383
1384 My guess is that this correction, as opposed to changing
1385 the parameter to an 'int' (as done below, for PCC
1386 on most machines), is the right thing to do
1387 on all machines, but I don't want to risk breaking
1388 something that already works. On most PCC machines,
1389 the sparc problem doesn't come up because the calling
1390 function has to zero the top bytes (not knowing whether
1391 the called function wants an int or a short), so there
1392 is no practical difference between an int and a short
1393 (except perhaps what happens when the GDB user types
1394 "print short_arg = 0x10000;").
1395
1396 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1397 actually produces the correct address (we don't need to fix it
1398 up). I made this code adapt so that it will offset the symbol
1399 if it was pointing at an int-aligned location and not
1400 otherwise. This way you can use the same gdb for 4.0.x and
2a5ec41d
JG
1401 4.1 systems.
1402
1403 If the parameter is shorter than an int, and is integral
1404 (e.g. char, short, or unsigned equivalent), and is claimed to
1405 be passed on an integer boundary, don't believe it! Offset the
1406 parameter's address to the tail-end of that integer. */
1407
1ab3bf1b
JG
1408 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
1409 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1410 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1411 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
1412 {
1413 SYMBOL_VALUE (sym) += TYPE_LENGTH (temptype)
1414 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1415 }
c0302457
JG
1416 break;
1417
1418#else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1419
1420 /* If PCC says a parameter is a short or a char,
1421 it is really an int. */
1ab3bf1b
JG
1422 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
1423 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1424 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1425 {
1426 SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1427 ? lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER)
1428 : temptype;
2a5ec41d 1429 }
c0302457
JG
1430 break;
1431
1432#endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1433
1434 case 'P':
84ffdec2 1435 /* Parameter which is in a register. */
93297ea0
JG
1436
1437 /* acc seems to use P to delare the types of functions that
1438 are called by this file. gdb is not prepared to deal
1439 with this extra information. */
1440 if (processing_acc_compilation)
1441 break;
1442
c0302457
JG
1443 SYMBOL_CLASS (sym) = LOC_REGPARM;
1444 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
84ffdec2
JG
1445 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1446 {
1447 complain (&reg_value_complaint, SYMBOL_NAME (sym));
1448 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1449 }
c0302457
JG
1450 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1451 add_symbol_to_list (sym, &local_symbols);
1452 break;
1453
095db7ce
PB
1454#ifdef IBM6000_TARGET
1455 case 'R':
1456#endif
c0302457 1457 case 'r':
84ffdec2 1458 /* Register variable (either global or local). */
c0302457
JG
1459 SYMBOL_CLASS (sym) = LOC_REGISTER;
1460 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
84ffdec2
JG
1461 if (SYMBOL_VALUE (sym) >= NUM_REGS)
1462 {
1463 complain (&reg_value_complaint, SYMBOL_NAME (sym));
1464 SYMBOL_VALUE (sym) = SP_REGNUM; /* Known safe, though useless */
1465 }
c0302457 1466 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
84ffdec2
JG
1467 if (within_function)
1468 add_symbol_to_list (sym, &local_symbols);
1469 else
1470 add_symbol_to_list (sym, &file_symbols);
c0302457
JG
1471 break;
1472
1473 case 'S':
1474 /* Static symbol at top level of file */
1475 SYMBOL_CLASS (sym) = LOC_STATIC;
1476 SYMBOL_VALUE_ADDRESS (sym) = valu;
1477 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1478 add_symbol_to_list (sym, &file_symbols);
1479 break;
1480
1481 case 't':
095db7ce
PB
1482 /* For a nameless type, we don't want a create a symbol, thus we
1483 did not use `sym'. Return without further processing. */
095db7ce 1484 if (nameless) return NULL;
2778e915 1485
c0302457
JG
1486 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1487 SYMBOL_VALUE (sym) = valu;
1488 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
ea1549b3
JG
1489 /* C++ vagaries: we may have a type which is derived from
1490 a base type which did not have its name defined when the
1491 derived class was output. We fill in the derived class's
1492 base part member's name here in that case. */
1493 if (TYPE_NAME (SYMBOL_TYPE (sym)) != NULL)
1494 if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
c0302457
JG
1495 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1496 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1497 {
1498 int j;
1499 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1500 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1501 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1502 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1503 }
1504
1505 add_symbol_to_list (sym, &file_symbols);
1506 break;
1507
1508 case 'T':
2778e915
JG
1509 /* For a nameless type, we don't want a create a symbol, thus we
1510 did not use `sym'. Return without further processing. */
1511 if (nameless) return NULL;
1512
c0302457
JG
1513 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1514 SYMBOL_VALUE (sym) = valu;
1515 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1ab3bf1b 1516 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
c0302457 1517 TYPE_NAME (SYMBOL_TYPE (sym))
1ab3bf1b 1518 = obconcat (&objfile -> type_obstack, "",
c0302457
JG
1519 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
1520 ? "enum "
1521 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1522 ? "struct " : "union ")),
1523 SYMBOL_NAME (sym));
1524 add_symbol_to_list (sym, &file_symbols);
1525
1526 if (synonym)
1527 {
1ab3bf1b
JG
1528 register struct symbol *typedef_sym = (struct symbol *)
1529 obstack_alloc (&objfile -> type_obstack,
1530 sizeof (struct symbol));
c0302457
JG
1531 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
1532 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
1533
1534 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1535 SYMBOL_VALUE (typedef_sym) = valu;
1536 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1537 add_symbol_to_list (typedef_sym, &file_symbols);
1538 }
1539 break;
1540
1541 case 'V':
1542 /* Static symbol of local scope */
1543 SYMBOL_CLASS (sym) = LOC_STATIC;
1544 SYMBOL_VALUE_ADDRESS (sym) = valu;
1545 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1546 add_symbol_to_list (sym, &local_symbols);
1547 break;
1548
1549 case 'v':
1550 /* Reference parameter */
1551 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1552 SYMBOL_VALUE (sym) = valu;
1553 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1554 add_symbol_to_list (sym, &local_symbols);
1555 break;
1556
1557 case 'X':
1558 /* This is used by Sun FORTRAN for "function result value".
1559 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1560 that Pascal uses it too, but when I tried it Pascal used
1561 "x:3" (local symbol) instead. */
1562 SYMBOL_CLASS (sym) = LOC_LOCAL;
1563 SYMBOL_VALUE (sym) = valu;
1564 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1565 add_symbol_to_list (sym, &local_symbols);
1566 break;
1567
1568 default:
1569 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
1570 }
1571 return sym;
1572}
1573\f
1574/* What about types defined as forward references inside of a small lexical
1575 scope? */
1576/* Add a type to the list of undefined types to be checked through
1577 once this file has been read in. */
a048c8f5 1578void
c0302457
JG
1579add_undefined_type (type)
1580 struct type *type;
1581{
1582 if (undef_types_length == undef_types_allocated)
1583 {
1584 undef_types_allocated *= 2;
1585 undef_types = (struct type **)
1ab3bf1b 1586 xrealloc ((char *) undef_types,
c0302457
JG
1587 undef_types_allocated * sizeof (struct type *));
1588 }
1589 undef_types[undef_types_length++] = type;
1590}
1591
2a5ec41d
JG
1592/* Go through each undefined type, see if it's still undefined, and fix it
1593 up if possible. We have two kinds of undefined types:
1594
1595 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1596 Fix: update array length using the element bounds
1597 and the target type's length.
1598 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1599 yet defined at the time a pointer to it was made.
1600 Fix: Do a full lookup on the struct/union tag. */
c0302457
JG
1601static void
1602cleanup_undefined_types ()
1603{
1604 struct type **type;
1605
2a5ec41d
JG
1606 for (type = undef_types; type < undef_types + undef_types_length; type++) {
1607 switch (TYPE_CODE (*type)) {
c0302457 1608
2a5ec41d
JG
1609 case TYPE_CODE_STRUCT:
1610 case TYPE_CODE_UNION:
59d97f7f 1611 case TYPE_CODE_ENUM:
2a5ec41d
JG
1612 {
1613 /* Reasonable test to see if it's been defined since. */
1614 if (TYPE_NFIELDS (*type) == 0)
1615 {
1616 struct pending *ppt;
1617 int i;
1618 /* Name of the type, without "struct" or "union" */
1619 char *typename = TYPE_NAME (*type);
1620
1621 if (!strncmp (typename, "struct ", 7))
1622 typename += 7;
1623 if (!strncmp (typename, "union ", 6))
1624 typename += 6;
59d97f7f
SG
1625 if (!strncmp (typename, "enum ", 5))
1626 typename += 5;
2a5ec41d
JG
1627
1628 for (ppt = file_symbols; ppt; ppt = ppt->next)
1629 for (i = 0; i < ppt->nsyms; i++)
1630 {
1631 struct symbol *sym = ppt->symbol[i];
1632
1633 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1634 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1635 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
1636 TYPE_CODE (*type))
1637 && !strcmp (SYMBOL_NAME (sym), typename))
7e258d18 1638 memcpy (*type, SYMBOL_TYPE (sym), sizeof (struct type));
2a5ec41d
JG
1639 }
1640 }
1641 else
1642 /* It has been defined; don't mark it as a stub. */
1643 TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
1644 }
1645 break;
c0302457 1646
2a5ec41d
JG
1647 case TYPE_CODE_ARRAY:
1648 {
1649 struct type *range_type;
1650 int lower, upper;
1651
1652 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
1653 goto badtype;
1654 if (TYPE_NFIELDS (*type) != 1)
1655 goto badtype;
1656 range_type = TYPE_FIELD_TYPE (*type, 0);
1657 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
1658 goto badtype;
1659
1660 /* Now recompute the length of the array type, based on its
1661 number of elements and the target type's length. */
1662 lower = TYPE_FIELD_BITPOS (range_type, 0);
1663 upper = TYPE_FIELD_BITPOS (range_type, 1);
1664 TYPE_LENGTH (*type) = (upper - lower + 1)
1665 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
c0302457 1666 }
2a5ec41d
JG
1667 break;
1668
1669 default:
1670 badtype:
59d97f7f
SG
1671 error ("GDB internal error. cleanup_undefined_types with bad\
1672 type %d.", TYPE_CODE (*type));
2a5ec41d 1673 break;
c0302457 1674 }
2a5ec41d 1675 }
c0302457
JG
1676 undef_types_length = 0;
1677}
1678\f
1679/* Skip rest of this symbol and return an error type.
1680
1681 General notes on error recovery: error_type always skips to the
1682 end of the symbol (modulo cretinous dbx symbol name continuation).
1683 Thus code like this:
1684
1685 if (*(*pp)++ != ';')
1686 return error_type (pp);
1687
1688 is wrong because if *pp starts out pointing at '\0' (typically as the
1689 result of an earlier error), it will be incremented to point to the
1690 start of the next symbol, which might produce strange results, at least
1691 if you run off the end of the string table. Instead use
1692
1693 if (**pp != ';')
1694 return error_type (pp);
1695 ++*pp;
1696
1697 or
1698
1699 if (**pp != ';')
1700 foo = error_type (pp);
1701 else
1702 ++*pp;
1703
1704 And in case it isn't obvious, the point of all this hair is so the compiler
1705 can define new types and new syntaxes, and old versions of the
1706 debugger will be able to read the new symbol tables. */
1707
1708struct type *
1709error_type (pp)
1710 char **pp;
1711{
1712 complain (&error_type_complaint, 0);
1713 while (1)
1714 {
1715 /* Skip to end of symbol. */
1716 while (**pp != '\0')
1717 (*pp)++;
1718
1719 /* Check for and handle cretinous dbx symbol name continuation! */
1720 if ((*pp)[-1] == '\\')
1721 *pp = next_symbol_text ();
1722 else
1723 break;
1724 }
1725 return builtin_type_error;
1726}
1727\f
1728/* Read a dbx type reference or definition;
1729 return the type that is meant.
1730 This can be just a number, in which case it references
1731 a type already defined and placed in type_vector.
1732 Or the number can be followed by an =, in which case
1733 it means to define a new type according to the text that
1734 follows the =. */
1735
1736struct type *
1ab3bf1b 1737read_type (pp, objfile)
c0302457 1738 register char **pp;
1ab3bf1b 1739 struct objfile *objfile;
c0302457
JG
1740{
1741 register struct type *type = 0;
1742 struct type *type1;
1743 int typenums[2];
1744 int xtypenums[2];
1745
1746 /* Read type number if present. The type number may be omitted.
1747 for instance in a two-dimensional array declared with type
1748 "ar1;1;10;ar1;1;10;4". */
1749 if ((**pp >= '0' && **pp <= '9')
1750 || **pp == '(')
1751 {
1752 read_type_number (pp, typenums);
1753
a048c8f5
JG
1754 /* Type is not being defined here. Either it already exists,
1755 or this is a forward reference to it. dbx_alloc_type handles
1756 both cases. */
c0302457 1757 if (**pp != '=')
1ab3bf1b 1758 return dbx_alloc_type (typenums, objfile);
c0302457 1759
a048c8f5
JG
1760 /* Type is being defined here. */
1761#if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1762 {
1763 struct type *tt;
1764
1765 /* if such a type already exists, this is an unnecessary duplication
1766 of the stab string, which is common in (RS/6000) xlc generated
1767 objects. In that case, simply return NULL and let the caller take
1768 care of it. */
1769
1770 tt = *dbx_lookup_type (typenums);
1771 if (tt && tt->length && tt->code)
1772 return NULL;
1773 }
1774#endif
1775
c0302457
JG
1776 *pp += 2;
1777 }
1778 else
1779 {
1780 /* 'typenums=' not present, type is anonymous. Read and return
1781 the definition, but don't put it in the type vector. */
1782 typenums[0] = typenums[1] = -1;
1783 *pp += 1;
1784 }
a048c8f5 1785
c0302457
JG
1786 switch ((*pp)[-1])
1787 {
1788 case 'x':
1789 {
1790 enum type_code code;
1791
1792 /* Used to index through file_symbols. */
1793 struct pending *ppt;
1794 int i;
1795
1796 /* Name including "struct", etc. */
1797 char *type_name;
1798
1799 /* Name without "struct", etc. */
1800 char *type_name_only;
1801
1802 {
1803 char *prefix;
1804 char *from, *to;
1805
1806 /* Set the type code according to the following letter. */
1807 switch ((*pp)[0])
1808 {
1809 case 's':
1810 code = TYPE_CODE_STRUCT;
1811 prefix = "struct ";
1812 break;
1813 case 'u':
1814 code = TYPE_CODE_UNION;
1815 prefix = "union ";
1816 break;
1817 case 'e':
1818 code = TYPE_CODE_ENUM;
1819 prefix = "enum ";
1820 break;
1821 default:
1822 return error_type (pp);
1823 }
1824
1825 to = type_name = (char *)
1ab3bf1b 1826 obstack_alloc (&objfile -> type_obstack,
c0302457
JG
1827 (strlen (prefix) +
1828 ((char *) strchr (*pp, ':') - (*pp)) + 1));
1829
1830 /* Copy the prefix. */
1831 from = prefix;
1832 while (*to++ = *from++)
1833 ;
1834 to--;
1835
1836 type_name_only = to;
1837
1838 /* Copy the name. */
1839 from = *pp + 1;
1840 while ((*to++ = *from++) != ':')
1841 ;
1842 *--to = '\0';
1843
1844 /* Set the pointer ahead of the name which we just read. */
1845 *pp = from;
1846
1847#if 0
1848 /* The following hack is clearly wrong, because it doesn't
1849 check whether we are in a baseclass. I tried to reproduce
1850 the case that it is trying to fix, but I couldn't get
1851 g++ to put out a cross reference to a basetype. Perhaps
1852 it doesn't do it anymore. */
1853 /* Note: for C++, the cross reference may be to a base type which
1854 has not yet been seen. In this case, we skip to the comma,
1855 which will mark the end of the base class name. (The ':'
1856 at the end of the base class name will be skipped as well.)
1857 But sometimes (ie. when the cross ref is the last thing on
1858 the line) there will be no ','. */
1859 from = (char *) strchr (*pp, ',');
1860 if (from)
1861 *pp = from;
1862#endif /* 0 */
1863 }
1864
1865 /* Now check to see whether the type has already been declared. */
1866 /* This is necessary at least in the case where the
1867 program says something like
1868 struct foo bar[5];
1869 The compiler puts out a cross-reference; we better find
1870 set the length of the structure correctly so we can
1871 set the length of the array. */
1872 for (ppt = file_symbols; ppt; ppt = ppt->next)
1873 for (i = 0; i < ppt->nsyms; i++)
1874 {
1875 struct symbol *sym = ppt->symbol[i];
1876
1877 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1878 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1879 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1880 && !strcmp (SYMBOL_NAME (sym), type_name_only))
1881 {
1ab3bf1b 1882 obstack_free (&objfile -> type_obstack, type_name);
c0302457
JG
1883 type = SYMBOL_TYPE (sym);
1884 return type;
1885 }
1886 }
1887
1888 /* Didn't find the type to which this refers, so we must
1889 be dealing with a forward reference. Allocate a type
1890 structure for it, and keep track of it so we can
1891 fill in the rest of the fields when we get the full
1892 type. */
1ab3bf1b 1893 type = dbx_alloc_type (typenums, objfile);
c0302457
JG
1894 TYPE_CODE (type) = code;
1895 TYPE_NAME (type) = type_name;
aab77d5f 1896 INIT_CPLUS_SPECIFIC(type);
c0302457
JG
1897 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1898
1899 add_undefined_type (type);
1900 return type;
1901 }
1902
74f6fb08
JG
1903 case '-': /* RS/6000 built-in type */
1904 (*pp)--;
1905 type = builtin_type (pp); /* (in xcoffread.c) */
1906 goto after_digits;
1907
c0302457
JG
1908 case '0':
1909 case '1':
1910 case '2':
1911 case '3':
1912 case '4':
1913 case '5':
1914 case '6':
1915 case '7':
1916 case '8':
1917 case '9':
1918 case '(':
1919 (*pp)--;
1920 read_type_number (pp, xtypenums);
1921 type = *dbx_lookup_type (xtypenums);
a048c8f5
JG
1922 /* fall through */
1923
1924 after_digits:
c0302457 1925 if (type == 0)
1ab3bf1b 1926 type = lookup_fundamental_type (objfile, FT_VOID);
c0302457
JG
1927 if (typenums[0] != -1)
1928 *dbx_lookup_type (typenums) = type;
1929 break;
1930
ea1549b3
JG
1931 /* In the following types, we must be sure to overwrite any existing
1932 type that the typenums refer to, rather than allocating a new one
1933 and making the typenums point to the new one. This is because there
1934 may already be pointers to the existing type (if it had been
1935 forward-referenced), and we must change it to a pointer, function,
1936 reference, or whatever, *in-place*. */
1937
c0302457 1938 case '*':
1ab3bf1b 1939 type1 = read_type (pp, objfile);
ea1549b3 1940 type = make_pointer_type (type1, dbx_lookup_type (typenums));
a048c8f5 1941 break;
ea1549b3
JG
1942
1943 case '&': /* Reference to another type */
1944 type1 = read_type (pp, objfile);
1945 type = make_reference_type (type1, dbx_lookup_type (typenums));
1946 break;
1947
1948 case 'f': /* Function returning another type */
1949 type1 = read_type (pp, objfile);
1950 type = make_function_type (type1, dbx_lookup_type (typenums));
c0302457
JG
1951 break;
1952
ea1549b3
JG
1953/* FIXME -- we should be doing smash_to_XXX types here. */
1954 case '@': /* Member (class & variable) type */
c0302457 1955 {
1ab3bf1b 1956 struct type *domain = read_type (pp, objfile);
c0302457
JG
1957 struct type *memtype;
1958
1959 if (**pp != ',')
1960 /* Invalid member type data format. */
1961 return error_type (pp);
1962 ++*pp;
1963
1ab3bf1b
JG
1964 memtype = read_type (pp, objfile);
1965 type = dbx_alloc_type (typenums, objfile);
c0302457
JG
1966 smash_to_member_type (type, domain, memtype);
1967 }
1968 break;
1969
ea1549b3 1970 case '#': /* Method (class & fn) type */
c0302457
JG
1971 if ((*pp)[0] == '#')
1972 {
1973 /* We'll get the parameter types from the name. */
1974 struct type *return_type;
1975
1976 *pp += 1;
1ab3bf1b 1977 return_type = read_type (pp, objfile);
c0302457 1978 if (*(*pp)++ != ';')
1ab3bf1b 1979 complain (&invalid_member_complaint, (char *) symnum);
c0302457
JG
1980 type = allocate_stub_method (return_type);
1981 if (typenums[0] != -1)
1982 *dbx_lookup_type (typenums) = type;
1983 }
1984 else
1985 {
1ab3bf1b 1986 struct type *domain = read_type (pp, objfile);
c0302457
JG
1987 struct type *return_type;
1988 struct type **args;
1989
1990 if (*(*pp)++ != ',')
1991 error ("invalid member type data format, at symtab pos %d.",
1992 symnum);
1993
1ab3bf1b
JG
1994 return_type = read_type (pp, objfile);
1995 args = read_args (pp, ';', objfile);
1996 type = dbx_alloc_type (typenums, objfile);
c0302457
JG
1997 smash_to_method_type (type, domain, return_type, args);
1998 }
1999 break;
2000
ea1549b3 2001 case 'r': /* Range type */
1ab3bf1b 2002 type = read_range_type (pp, typenums, objfile);
c0302457
JG
2003 if (typenums[0] != -1)
2004 *dbx_lookup_type (typenums) = type;
2005 break;
2006
93297ea0
JG
2007 case 'b': /* Sun ACC builtin int type */
2008 type = read_sun_builtin_type (pp, typenums, objfile);
2009 if (typenums[0] != -1)
2010 *dbx_lookup_type (typenums) = type;
2011 break;
2012
2013 case 'R': /* Sun ACC builtin float type */
2014 type = read_sun_floating_type (pp, typenums, objfile);
2015 if (typenums[0] != -1)
2016 *dbx_lookup_type (typenums) = type;
2017 break;
2018
ea1549b3 2019 case 'e': /* Enumeration type */
1ab3bf1b
JG
2020 type = dbx_alloc_type (typenums, objfile);
2021 type = read_enum_type (pp, type, objfile);
c0302457
JG
2022 *dbx_lookup_type (typenums) = type;
2023 break;
2024
ea1549b3 2025 case 's': /* Struct type */
1ab3bf1b 2026 type = dbx_alloc_type (typenums, objfile);
2b5a8d9c
PB
2027 if (!TYPE_NAME (type))
2028 TYPE_NAME (type) = type_synonym_name;
c0302457 2029 type_synonym_name = 0;
1ab3bf1b 2030 type = read_struct_type (pp, type, objfile);
c0302457
JG
2031 break;
2032
ea1549b3 2033 case 'u': /* Union type */
1ab3bf1b 2034 type = dbx_alloc_type (typenums, objfile);
2b5a8d9c
PB
2035 if (!TYPE_NAME (type))
2036 TYPE_NAME (type) = type_synonym_name;
c0302457 2037 type_synonym_name = 0;
1ab3bf1b 2038 type = read_struct_type (pp, type, objfile);
c0302457
JG
2039 TYPE_CODE (type) = TYPE_CODE_UNION;
2040 break;
2041
ea1549b3 2042 case 'a': /* Array type */
c0302457
JG
2043 if (**pp != 'r')
2044 return error_type (pp);
2045 ++*pp;
2046
1ab3bf1b
JG
2047 type = dbx_alloc_type (typenums, objfile);
2048 type = read_array_type (pp, type, objfile);
c0302457
JG
2049 break;
2050
2051 default:
2052 --*pp; /* Go back to the symbol in error */
2053 /* Particularly important if it was \0! */
2054 return error_type (pp);
2055 }
2056
2057 if (type == 0)
2058 abort ();
2059
c0302457
JG
2060 return type;
2061}
2062\f
2063/* This page contains subroutines of read_type. */
2064
2065/* Read the description of a structure (or union type)
2066 and return an object describing the type. */
2067
1ab3bf1b
JG
2068static struct type *
2069read_struct_type (pp, type, objfile)
c0302457
JG
2070 char **pp;
2071 register struct type *type;
1ab3bf1b 2072 struct objfile *objfile;
c0302457
JG
2073{
2074 /* Total number of methods defined in this class.
2075 If the class defines two `f' methods, and one `g' method,
2076 then this will have the value 3. */
2077 int total_length = 0;
2078
2079 struct nextfield
2080 {
2081 struct nextfield *next;
2082 int visibility; /* 0=public, 1=protected, 2=public */
2083 struct field field;
2084 };
2085
2086 struct next_fnfield
2087 {
2088 struct next_fnfield *next;
c0302457
JG
2089 struct fn_field fn_field;
2090 };
2091
2092 struct next_fnfieldlist
2093 {
2094 struct next_fnfieldlist *next;
2095 struct fn_fieldlist fn_fieldlist;
2096 };
2097
2098 register struct nextfield *list = 0;
2099 struct nextfield *new;
2100 register char *p;
2101 int nfields = 0;
7e258d18 2102 int non_public_fields = 0;
c0302457
JG
2103 register int n;
2104
2105 register struct next_fnfieldlist *mainlist = 0;
2106 int nfn_fields = 0;
2107
c0302457 2108 TYPE_CODE (type) = TYPE_CODE_STRUCT;
aab77d5f 2109 INIT_CPLUS_SPECIFIC(type);
c0302457
JG
2110
2111 /* First comes the total size in bytes. */
2112
2113 TYPE_LENGTH (type) = read_number (pp, 0);
2114
2115 /* C++: Now, if the class is a derived class, then the next character
2116 will be a '!', followed by the number of base classes derived from.
2117 Each element in the list contains visibility information,
2118 the offset of this base class in the derived structure,
2119 and then the base type. */
2120 if (**pp == '!')
2121 {
2122 int i, n_baseclasses, offset;
2123 struct type *baseclass;
2124 int via_public;
2125
2126 /* Nonzero if it is a virtual baseclass, i.e.,
2127
2128 struct A{};
2129 struct B{};
2130 struct C : public B, public virtual A {};
2131
2132 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
2133 2.0 language feature. */
2134 int via_virtual;
2135
2136 *pp += 1;
2137
7e258d18
PB
2138 ALLOCATE_CPLUS_STRUCT_TYPE(type);
2139
c0302457
JG
2140 n_baseclasses = read_number (pp, ',');
2141 TYPE_FIELD_VIRTUAL_BITS (type) =
1ab3bf1b
JG
2142 (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2143 B_BYTES (n_baseclasses));
c0302457
JG
2144 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
2145
2146 for (i = 0; i < n_baseclasses; i++)
2147 {
2148 if (**pp == '\\')
2149 *pp = next_symbol_text ();
2150
2151 switch (**pp)
2152 {
2153 case '0':
2154 via_virtual = 0;
2155 break;
2156 case '1':
2157 via_virtual = 1;
2158 break;
2159 default:
2160 /* Bad visibility format. */
2161 return error_type (pp);
2162 }
2163 ++*pp;
2164
2165 switch (**pp)
2166 {
2167 case '0':
2168 via_public = 0;
7e258d18 2169 non_public_fields++;
c0302457
JG
2170 break;
2171 case '2':
2172 via_public = 2;
2173 break;
2174 default:
2175 /* Bad visibility format. */
2176 return error_type (pp);
2177 }
2178 if (via_virtual)
2179 SET_TYPE_FIELD_VIRTUAL (type, i);
2180 ++*pp;
2181
2182 /* Offset of the portion of the object corresponding to
2183 this baseclass. Always zero in the absence of
2184 multiple inheritance. */
2185 offset = read_number (pp, ',');
1ab3bf1b 2186 baseclass = read_type (pp, objfile);
c0302457
JG
2187 *pp += 1; /* skip trailing ';' */
2188
2189 /* Make this baseclass visible for structure-printing purposes. */
2190 new = (struct nextfield *) alloca (sizeof (struct nextfield));
2191 new->next = list;
2192 list = new;
2193 list->visibility = via_public;
2194 list->field.type = baseclass;
2195 list->field.name = type_name_no_tag (baseclass);
2196 list->field.bitpos = offset;
2197 list->field.bitsize = 0; /* this should be an unpacked field! */
2198 nfields++;
2199 }
2200 TYPE_N_BASECLASSES (type) = n_baseclasses;
2201 }
2202
2203 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2204 At the end, we see a semicolon instead of a field.
2205
2206 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2207 a static field.
2208
2209 The `?' is a placeholder for one of '/2' (public visibility),
2210 '/1' (protected visibility), '/0' (private visibility), or nothing
2211 (C style symbol table, public visibility). */
2212
2213 /* We better set p right now, in case there are no fields at all... */
2214 p = *pp;
2215
2216 while (**pp != ';')
2217 {
2218 /* Check for and handle cretinous dbx symbol name continuation! */
2219 if (**pp == '\\') *pp = next_symbol_text ();
2220
2221 /* Get space to record the next field's data. */
2222 new = (struct nextfield *) alloca (sizeof (struct nextfield));
2223 new->next = list;
2224 list = new;
2225
2226 /* Get the field name. */
2227 p = *pp;
2228 if (*p == CPLUS_MARKER)
2229 {
2230 /* Special GNU C++ name. */
2231 if (*++p == 'v')
2232 {
2233 const char *prefix;
2234 char *name = 0;
2235 struct type *context;
2236
2237 switch (*++p)
2238 {
2239 case 'f':
2240 prefix = vptr_name;
2241 break;
2242 case 'b':
2243 prefix = vb_name;
2244 break;
2245 default:
f1d77e90
JG
2246 complain (&invalid_cpp_abbrev_complaint, *pp);
2247 prefix = "INVALID_C++_ABBREV";
2248 break;
c0302457
JG
2249 }
2250 *pp = p + 1;
1ab3bf1b 2251 context = read_type (pp, objfile);
abefb1f1
PB
2252 name = type_name_no_tag (context);
2253 if (name == 0)
c0302457 2254 {
1ab3bf1b 2255 complain (&invalid_cpp_type_complaint, (char *) symnum);
03c93c66 2256 name = "FOO";
c0302457 2257 }
1ab3bf1b
JG
2258 list->field.name = obconcat (&objfile -> type_obstack,
2259 prefix, name, "");
c0302457
JG
2260 p = ++(*pp);
2261 if (p[-1] != ':')
f1d77e90 2262 complain (&invalid_cpp_abbrev_complaint, *pp);
1ab3bf1b 2263 list->field.type = read_type (pp, objfile);
c0302457
JG
2264 (*pp)++; /* Skip the comma. */
2265 list->field.bitpos = read_number (pp, ';');
2266 /* This field is unpacked. */
2267 list->field.bitsize = 0;
7e258d18
PB
2268 list->visibility = 0; /* private */
2269 non_public_fields++;
c0302457
JG
2270 }
2271 /* GNU C++ anonymous type. */
2272 else if (*p == '_')
2273 break;
2274 else
f1d77e90 2275 complain (&invalid_cpp_abbrev_complaint, *pp);
c0302457
JG
2276
2277 nfields++;
2278 continue;
2279 }
2280
2281 while (*p != ':') p++;
1ab3bf1b
JG
2282 list->field.name = obsavestring (*pp, p - *pp,
2283 &objfile -> type_obstack);
c0302457
JG
2284
2285 /* C++: Check to see if we have hit the methods yet. */
2286 if (p[1] == ':')
2287 break;
2288
2289 *pp = p + 1;
2290
2291 /* This means we have a visibility for a field coming. */
2292 if (**pp == '/')
2293 {
2294 switch (*++*pp)
2295 {
2296 case '0':
2297 list->visibility = 0; /* private */
7e258d18 2298 non_public_fields++;
c0302457
JG
2299 *pp += 1;
2300 break;
2301
2302 case '1':
2303 list->visibility = 1; /* protected */
7e258d18 2304 non_public_fields++;
c0302457
JG
2305 *pp += 1;
2306 break;
2307
2308 case '2':
2309 list->visibility = 2; /* public */
2310 *pp += 1;
2311 break;
2312 }
2313 }
2314 else /* normal dbx-style format. */
2315 list->visibility = 2; /* public */
2316
1ab3bf1b 2317 list->field.type = read_type (pp, objfile);
c0302457
JG
2318 if (**pp == ':')
2319 {
2320 /* Static class member. */
2321 list->field.bitpos = (long)-1;
2322 p = ++(*pp);
2323 while (*p != ';') p++;
2324 list->field.bitsize = (long) savestring (*pp, p - *pp);
2325 *pp = p + 1;
2326 nfields++;
2327 continue;
2328 }
2329 else if (**pp != ',')
2330 /* Bad structure-type format. */
2331 return error_type (pp);
2332
2333 (*pp)++; /* Skip the comma. */
2334 list->field.bitpos = read_number (pp, ',');
2335 list->field.bitsize = read_number (pp, ';');
2336
2337#if 0
2338 /* FIXME-tiemann: Can't the compiler put out something which
2339 lets us distinguish these? (or maybe just not put out anything
2340 for the field). What is the story here? What does the compiler
2341 really do? Also, patch gdb.texinfo for this case; I document
2342 it as a possible problem there. Search for "DBX-style". */
2343
2344 /* This is wrong because this is identical to the symbols
2345 produced for GCC 0-size arrays. For example:
2346 typedef union {
2347 int num;
2348 char str[0];
2349 } foo;
2350 The code which dumped core in such circumstances should be
2351 fixed not to dump core. */
2352
2353 /* g++ -g0 can put out bitpos & bitsize zero for a static
2354 field. This does not give us any way of getting its
2355 class, so we can't know its name. But we can just
2356 ignore the field so we don't dump core and other nasty
2357 stuff. */
2358 if (list->field.bitpos == 0
2359 && list->field.bitsize == 0)
2360 {
2361 complain (&dbx_class_complaint, 0);
2362 /* Ignore this field. */
2363 list = list->next;
2364 }
2365 else
2366#endif /* 0 */
2367 {
2368 /* Detect an unpacked field and mark it as such.
2369 dbx gives a bit size for all fields.
2370 Note that forward refs cannot be packed,
2371 and treat enums as if they had the width of ints. */
2372 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
2373 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
2374 list->field.bitsize = 0;
2375 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
2376 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
2377 && (list->field.bitsize
1ab3bf1b 2378 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile, FT_INTEGER)))
c0302457
JG
2379 )
2380 )
2381 &&
2382 list->field.bitpos % 8 == 0)
2383 list->field.bitsize = 0;
2384 nfields++;
2385 }
2386 }
2387
2388 if (p[1] == ':')
2389 /* chill the list of fields: the last entry (at the head)
2390 is a partially constructed entry which we now scrub. */
2391 list = list->next;
2392
2393 /* Now create the vector of fields, and record how big it is.
2394 We need this info to record proper virtual function table information
2395 for this class's virtual functions. */
2396
2397 TYPE_NFIELDS (type) = nfields;
1ab3bf1b
JG
2398 TYPE_FIELDS (type) = (struct field *)
2399 obstack_alloc (&objfile -> type_obstack, sizeof (struct field) * nfields);
c0302457 2400
7e258d18
PB
2401 if (non_public_fields)
2402 {
2403 ALLOCATE_CPLUS_STRUCT_TYPE (type);
c0302457 2404
7e258d18 2405 TYPE_FIELD_PRIVATE_BITS (type) =
1ab3bf1b
JG
2406 (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2407 B_BYTES (nfields));
7e258d18
PB
2408 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2409
2410 TYPE_FIELD_PROTECTED_BITS (type) =
1ab3bf1b
JG
2411 (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2412 B_BYTES (nfields));
7e258d18
PB
2413 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2414 }
c0302457
JG
2415
2416 /* Copy the saved-up fields into the field vector. */
2417
2418 for (n = nfields; list; list = list->next)
2419 {
2420 n -= 1;
2421 TYPE_FIELD (type, n) = list->field;
2422 if (list->visibility == 0)
2423 SET_TYPE_FIELD_PRIVATE (type, n);
2424 else if (list->visibility == 1)
2425 SET_TYPE_FIELD_PROTECTED (type, n);
2426 }
2427
2428 /* Now come the method fields, as NAME::methods
2429 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2430 At the end, we see a semicolon instead of a field.
2431
2432 For the case of overloaded operators, the format is
256269fc 2433 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
c0302457
JG
2434 `*' holds the place for an operator name (such as `+=')
2435 and `.' marks the end of the operator name. */
2436 if (p[1] == ':')
2437 {
2438 /* Now, read in the methods. To simplify matters, we
2439 "unread" the name that has been read, so that we can
2440 start from the top. */
2441
7e258d18 2442 ALLOCATE_CPLUS_STRUCT_TYPE (type);
c0302457
JG
2443 /* For each list of method lists... */
2444 do
2445 {
2446 int i;
2447 struct next_fnfield *sublist = 0;
2448 struct type *look_ahead_type = NULL;
2449 int length = 0;
2450 struct next_fnfieldlist *new_mainlist =
2451 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
2452 char *main_fn_name;
2453
2454 p = *pp;
2455
2456 /* read in the name. */
2457 while (*p != ':') p++;
2458 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
2459 {
f1d77e90
JG
2460 /* This is a completely wierd case. In order to stuff in the
2461 names that might contain colons (the usual name delimiter),
2462 Mike Tiemann defined a different name format which is
2463 signalled if the identifier is "op$". In that case, the
2464 format is "op$::XXXX." where XXXX is the name. This is
2465 used for names like "+" or "=". YUUUUUUUK! FIXME! */
c0302457
JG
2466 /* This lets the user type "break operator+".
2467 We could just put in "+" as the name, but that wouldn't
2468 work for "*". */
2469 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2470 char *o = opname + 3;
2471
2472 /* Skip past '::'. */
abefb1f1
PB
2473 *pp = p + 2;
2474 if (**pp == '\\') *pp = next_symbol_text ();
2475 p = *pp;
c0302457
JG
2476 while (*p != '.')
2477 *o++ = *p++;
abefb1f1 2478 main_fn_name = savestring (opname, o - opname);
c0302457
JG
2479 /* Skip past '.' */
2480 *pp = p + 1;
2481 }
2482 else
256269fc 2483 {
c0302457 2484 main_fn_name = savestring (*pp, p - *pp);
256269fc
JG
2485 /* Skip past '::'. */
2486 *pp = p + 2;
2487 }
c0302457
JG
2488 new_mainlist->fn_fieldlist.name = main_fn_name;
2489
2490 do
2491 {
2492 struct next_fnfield *new_sublist =
2493 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
2494
2495 /* Check for and handle cretinous dbx symbol name continuation! */
2496 if (look_ahead_type == NULL) /* Normal case. */
2497 {
2498 if (**pp == '\\') *pp = next_symbol_text ();
2499
1ab3bf1b 2500 new_sublist->fn_field.type = read_type (pp, objfile);
c0302457
JG
2501 if (**pp != ':')
2502 /* Invalid symtab info for method. */
2503 return error_type (pp);
2504 }
2505 else
2506 { /* g++ version 1 kludge */
2507 new_sublist->fn_field.type = look_ahead_type;
2508 look_ahead_type = NULL;
2509 }
2510
2511 *pp += 1;
2512 p = *pp;
2513 while (*p != ';') p++;
7fb4dfc0 2514
c0302457
JG
2515 /* If this is just a stub, then we don't have the
2516 real name here. */
7fb4dfc0
MT
2517 if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
2518 new_sublist->fn_field.is_stub = 1;
c0302457
JG
2519 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
2520 *pp = p + 1;
7fb4dfc0
MT
2521
2522 /* Set this method's visibility fields. */
2523 switch (*(*pp)++ - '0')
2524 {
2525 case 0:
2526 new_sublist->fn_field.is_private = 1;
2527 break;
2528 case 1:
2529 new_sublist->fn_field.is_protected = 1;
2530 break;
2531 }
2532
c0302457
JG
2533 if (**pp == '\\') *pp = next_symbol_text ();
2534 switch (**pp)
2535 {
2536 case 'A': /* Normal functions. */
2537 new_sublist->fn_field.is_const = 0;
2538 new_sublist->fn_field.is_volatile = 0;
2539 (*pp)++;
2540 break;
2541 case 'B': /* `const' member functions. */
2542 new_sublist->fn_field.is_const = 1;
2543 new_sublist->fn_field.is_volatile = 0;
2544 (*pp)++;
2545 break;
2546 case 'C': /* `volatile' member function. */
2547 new_sublist->fn_field.is_const = 0;
2548 new_sublist->fn_field.is_volatile = 1;
2549 (*pp)++;
2550 break;
2551 case 'D': /* `const volatile' member function. */
2552 new_sublist->fn_field.is_const = 1;
2553 new_sublist->fn_field.is_volatile = 1;
2554 (*pp)++;
2555 break;
f1d77e90
JG
2556 case '*': /* File compiled with g++ version 1 -- no info */
2557 case '?':
2558 case '.':
2559 break;
c0302457 2560 default:
1ab3bf1b 2561 complain (&const_vol_complaint, (char *) (long) **pp);
f1d77e90 2562 break;
c0302457
JG
2563 }
2564
2565 switch (*(*pp)++)
2566 {
2567 case '*':
2568 /* virtual member function, followed by index. */
2569 /* The sign bit is set to distinguish pointers-to-methods
2570 from virtual function indicies. Since the array is
2571 in words, the quantity must be shifted left by 1
2572 on 16 bit machine, and by 2 on 32 bit machine, forcing
2573 the sign bit out, and usable as a valid index into
2574 the array. Remove the sign bit here. */
2575 new_sublist->fn_field.voffset =
2576 (0x7fffffff & read_number (pp, ';')) + 2;
2577
2578 if (**pp == '\\') *pp = next_symbol_text ();
2579
2580 if (**pp == ';' || **pp == '\0')
2581 /* Must be g++ version 1. */
2582 new_sublist->fn_field.fcontext = 0;
2583 else
2584 {
2585 /* Figure out from whence this virtual function came.
2586 It may belong to virtual function table of
2587 one of its baseclasses. */
1ab3bf1b 2588 look_ahead_type = read_type (pp, objfile);
c0302457
JG
2589 if (**pp == ':')
2590 { /* g++ version 1 overloaded methods. */ }
2591 else
2592 {
2593 new_sublist->fn_field.fcontext = look_ahead_type;
2594 if (**pp != ';')
2595 return error_type (pp);
2596 else
2597 ++*pp;
2598 look_ahead_type = NULL;
2599 }
2600 }
2601 break;
2602
2603 case '?':
2604 /* static member function. */
2605 new_sublist->fn_field.voffset = VOFFSET_STATIC;
7fb4dfc0
MT
2606 if (strncmp (new_sublist->fn_field.physname,
2607 main_fn_name, strlen (main_fn_name)))
2608 new_sublist->fn_field.is_stub = 1;
c0302457 2609 break;
f1d77e90 2610
c0302457 2611 default:
f1d77e90 2612 /* error */
1ab3bf1b 2613 complain (&member_fn_complaint, (char *) (long) (*pp)[-1]);
f1d77e90
JG
2614 /* Fall through into normal member function. */
2615
2616 case '.':
c0302457
JG
2617 /* normal member function. */
2618 new_sublist->fn_field.voffset = 0;
2619 new_sublist->fn_field.fcontext = 0;
2620 break;
2621 }
2622
2623 new_sublist->next = sublist;
2624 sublist = new_sublist;
2625 length++;
2626 if (**pp == '\\') *pp = next_symbol_text ();
2627 }
2628 while (**pp != ';' && **pp != '\0');
2629
2630 *pp += 1;
2631
2632 new_mainlist->fn_fieldlist.fn_fields =
1ab3bf1b 2633 (struct fn_field *) obstack_alloc (&objfile -> type_obstack,
c0302457 2634 sizeof (struct fn_field) * length);
c0302457 2635 for (i = length; (i--, sublist); sublist = sublist->next)
7fb4dfc0 2636 new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
c0302457
JG
2637
2638 new_mainlist->fn_fieldlist.length = length;
2639 new_mainlist->next = mainlist;
2640 mainlist = new_mainlist;
2641 nfn_fields++;
2642 total_length += length;
be1384b0 2643 if (**pp == '\\') *pp = next_symbol_text ();
c0302457
JG
2644 }
2645 while (**pp != ';');
2646 }
2647
2648 *pp += 1;
2649
c0302457 2650
7e258d18
PB
2651 if (nfn_fields)
2652 {
0eb0a820 2653 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
1ab3bf1b
JG
2654 obstack_alloc (&objfile -> type_obstack,
2655 sizeof (struct fn_fieldlist) * nfn_fields);
7e258d18
PB
2656 TYPE_NFN_FIELDS (type) = nfn_fields;
2657 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2658 }
c0302457
JG
2659
2660 {
2661 int i;
2662 for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
2663 TYPE_NFN_FIELDS_TOTAL (type) +=
2664 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
2665 }
2666
5a4e7215
JG
2667 for (n = nfn_fields; mainlist; mainlist = mainlist->next) {
2668 --n; /* Circumvent Sun3 compiler bug */
2669 TYPE_FN_FIELDLISTS (type)[n] = mainlist->fn_fieldlist;
2670 }
c0302457
JG
2671
2672 if (**pp == '~')
2673 {
2674 *pp += 1;
2675
0e2a896c 2676 if (**pp == '=' || **pp == '+' || **pp == '-')
c0302457 2677 {
0e2a896c
PB
2678 /* Obsolete flags that used to indicate the presence
2679 of constructors and/or destructors. */
c0302457
JG
2680 *pp += 1;
2681 }
2682
2683 /* Read either a '%' or the final ';'. */
2684 if (*(*pp)++ == '%')
2685 {
572acbbe
MT
2686 /* We'd like to be able to derive the vtable pointer field
2687 from the type information, but when it's inherited, that's
2688 hard. A reason it's hard is because we may read in the
2689 info about a derived class before we read in info about
2690 the base class that provides the vtable pointer field.
2691 Once the base info has been read, we could fill in the info
2692 for the derived classes, but for the fact that by then,
2693 we don't remember who needs what. */
2694
84ffdec2 2695#if 0
572acbbe 2696 int predicted_fieldno = -1;
84ffdec2 2697#endif
572acbbe 2698
c0302457
JG
2699 /* Now we must record the virtual function table pointer's
2700 field information. */
2701
2702 struct type *t;
2703 int i;
2704
572acbbe
MT
2705
2706#if 0
2707 {
2708 /* In version 2, we derive the vfield ourselves. */
2709 for (n = 0; n < nfields; n++)
2710 {
2711 if (! strncmp (TYPE_FIELD_NAME (type, n), vptr_name,
2712 sizeof (vptr_name) -1))
2713 {
2714 predicted_fieldno = n;
2715 break;
2716 }
2717 }
2718 if (predicted_fieldno < 0)
2719 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2720 if (! TYPE_FIELD_VIRTUAL (type, n)
2721 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n)) >= 0)
2722 {
2723 predicted_fieldno = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n));
2724 break;
2725 }
2726 }
2727#endif
2728
1ab3bf1b 2729 t = read_type (pp, objfile);
c0302457
JG
2730 p = (*pp)++;
2731 while (*p != '\0' && *p != ';')
2732 p++;
2733 if (*p == '\0')
2734 /* Premature end of symbol. */
2735 return error_type (pp);
2736
2737 TYPE_VPTR_BASETYPE (type) = t;
2738 if (type == t)
2739 {
2740 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
2741 {
2742 /* FIXME-tiemann: what's this? */
2743#if 0
2744 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
2745#else
2746 error_type (pp);
2747#endif
2748 }
2749 else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
2750 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
572acbbe 2751 sizeof (vptr_name) -1))
c0302457
JG
2752 {
2753 TYPE_VPTR_FIELDNO (type) = i;
2754 break;
2755 }
2756 if (i < 0)
2757 /* Virtual function table field not found. */
2758 return error_type (pp);
2759 }
2760 else
2761 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
572acbbe
MT
2762
2763#if 0
2764 if (TYPE_VPTR_FIELDNO (type) != predicted_fieldno)
2765 error ("TYPE_VPTR_FIELDNO miscalculated");
2766#endif
2767
c0302457
JG
2768 *pp = p + 1;
2769 }
2770 }
2771
2772 return type;
2773}
2774
2775/* Read a definition of an array type,
2776 and create and return a suitable type object.
2777 Also creates a range type which represents the bounds of that
2778 array. */
1ab3bf1b
JG
2779static struct type *
2780read_array_type (pp, type, objfile)
c0302457
JG
2781 register char **pp;
2782 register struct type *type;
1ab3bf1b 2783 struct objfile *objfile;
c0302457
JG
2784{
2785 struct type *index_type, *element_type, *range_type;
2786 int lower, upper;
2787 int adjustable = 0;
2788
2789 /* Format of an array type:
2790 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2791 to handle this.
2792
2793 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2794 for these, produce a type like float[][]. */
2795
1ab3bf1b 2796 index_type = read_type (pp, objfile);
c0302457
JG
2797 if (**pp != ';')
2798 /* Improper format of array type decl. */
2799 return error_type (pp);
2800 ++*pp;
2801
2802 if (!(**pp >= '0' && **pp <= '9'))
2803 {
2804 *pp += 1;
2805 adjustable = 1;
2806 }
2807 lower = read_number (pp, ';');
2808
2809 if (!(**pp >= '0' && **pp <= '9'))
2810 {
2811 *pp += 1;
2812 adjustable = 1;
2813 }
2814 upper = read_number (pp, ';');
2815
1ab3bf1b 2816 element_type = read_type (pp, objfile);
c0302457
JG
2817
2818 if (adjustable)
2819 {
2820 lower = 0;
2821 upper = -1;
2822 }
2823
2824 {
2825 /* Create range type. */
1ab3bf1b
JG
2826 range_type = (struct type *)
2827 obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
2828 bzero (range_type, sizeof (struct type));
2829 TYPE_OBJFILE (range_type) = objfile;
c0302457
JG
2830 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
2831 TYPE_TARGET_TYPE (range_type) = index_type;
2832
2833 /* This should never be needed. */
2834 TYPE_LENGTH (range_type) = sizeof (int);
2835
2836 TYPE_NFIELDS (range_type) = 2;
2837 TYPE_FIELDS (range_type) =
1ab3bf1b 2838 (struct field *) obstack_alloc (&objfile -> type_obstack,
c0302457
JG
2839 2 * sizeof (struct field));
2840 TYPE_FIELD_BITPOS (range_type, 0) = lower;
2841 TYPE_FIELD_BITPOS (range_type, 1) = upper;
2842 }
2843
2844 TYPE_CODE (type) = TYPE_CODE_ARRAY;
2845 TYPE_TARGET_TYPE (type) = element_type;
2846 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
2847 TYPE_NFIELDS (type) = 1;
2848 TYPE_FIELDS (type) =
1ab3bf1b 2849 (struct field *) obstack_alloc (&objfile -> type_obstack,
c0302457
JG
2850 sizeof (struct field));
2851 TYPE_FIELD_TYPE (type, 0) = range_type;
2852
2a5ec41d
JG
2853 /* If we have an array whose element type is not yet known, but whose
2854 bounds *are* known, record it to be adjusted at the end of the file. */
2855 if (TYPE_LENGTH (element_type) == 0 && !adjustable)
2856 add_undefined_type (type);
2857
c0302457
JG
2858 return type;
2859}
2860
2861
2862/* Read a definition of an enumeration type,
2863 and create and return a suitable type object.
2864 Also defines the symbols that represent the values of the type. */
2865
1ab3bf1b
JG
2866static struct type *
2867read_enum_type (pp, type, objfile)
c0302457
JG
2868 register char **pp;
2869 register struct type *type;
1ab3bf1b 2870 struct objfile *objfile;
c0302457
JG
2871{
2872 register char *p;
2873 char *name;
2874 register long n;
2875 register struct symbol *sym;
2876 int nsyms = 0;
2877 struct pending **symlist;
2878 struct pending *osyms, *syms;
2879 int o_nsyms;
2880
ea1549b3
JG
2881#if 0
2882 /* FIXME! The stabs produced by Sun CC merrily define things that ought
2883 to be file-scope, between N_FN entries, using N_LSYM. What's a mother
2884 to do? For now, force all enum values to file scope. */
c0302457
JG
2885 if (within_function)
2886 symlist = &local_symbols;
2887 else
ea1549b3 2888#endif
c0302457
JG
2889 symlist = &file_symbols;
2890 osyms = *symlist;
2891 o_nsyms = osyms ? osyms->nsyms : 0;
2892
2893 /* Read the value-names and their values.
2894 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
1ab3bf1b 2895 A semicolon or comma instead of a NAME means the end. */
c0302457
JG
2896 while (**pp && **pp != ';' && **pp != ',')
2897 {
2898 /* Check for and handle cretinous dbx symbol name continuation! */
2899 if (**pp == '\\') *pp = next_symbol_text ();
2900
2901 p = *pp;
2902 while (*p != ':') p++;
1ab3bf1b 2903 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
c0302457
JG
2904 *pp = p + 1;
2905 n = read_number (pp, ',');
2906
1ab3bf1b 2907 sym = (struct symbol *) obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
c0302457
JG
2908 bzero (sym, sizeof (struct symbol));
2909 SYMBOL_NAME (sym) = name;
2910 SYMBOL_CLASS (sym) = LOC_CONST;
2911 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2912 SYMBOL_VALUE (sym) = n;
2913 add_symbol_to_list (sym, symlist);
2914 nsyms++;
2915 }
2916
2917 if (**pp == ';')
2918 (*pp)++; /* Skip the semicolon. */
2919
2920 /* Now fill in the fields of the type-structure. */
2921
2922 TYPE_LENGTH (type) = sizeof (int);
2923 TYPE_CODE (type) = TYPE_CODE_ENUM;
2924 TYPE_NFIELDS (type) = nsyms;
1ab3bf1b
JG
2925 TYPE_FIELDS (type) = (struct field *)
2926 obstack_alloc (&objfile -> type_obstack,
2927 sizeof (struct field) * nsyms);
c0302457
JG
2928
2929 /* Find the symbols for the values and put them into the type.
2930 The symbols can be found in the symlist that we put them on
2931 to cause them to be defined. osyms contains the old value
2932 of that symlist; everything up to there was defined by us. */
2933 /* Note that we preserve the order of the enum constants, so
2934 that in something like "enum {FOO, LAST_THING=FOO}" we print
2935 FOO, not LAST_THING. */
2936
2937 for (syms = *symlist, n = 0; syms; syms = syms->next)
2938 {
2939 int j = 0;
2940 if (syms == osyms)
2941 j = o_nsyms;
2942 for (; j < syms->nsyms; j++,n++)
2943 {
2944 struct symbol *xsym = syms->symbol[j];
2945 SYMBOL_TYPE (xsym) = type;
2946 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2947 TYPE_FIELD_VALUE (type, n) = 0;
2948 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2949 TYPE_FIELD_BITSIZE (type, n) = 0;
2950 }
2951 if (syms == osyms)
2952 break;
2953 }
2954
2955#if 0
2956 /* This screws up perfectly good C programs with enums. FIXME. */
2957 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2958 if(TYPE_NFIELDS(type) == 2 &&
2959 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2960 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2961 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2962 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2963 TYPE_CODE(type) = TYPE_CODE_BOOL;
2964#endif
2965
2966 return type;
93297ea0
JG
2967}
2968
2969/* this is for the initial typedefs in every file (for int, long, etc) */
2970static struct type *
2971read_sun_builtin_type (pp, typenums, objfile)
2972 char **pp;
2973 int typenums[2];
2974 struct objfile *objfile;
2975{
2976 int nbits;
2977 int signed_type;
2978
2979 switch (**pp) {
2980 case 's':
2981 signed_type = 1;
2982 break;
2983 case 'u':
2984 signed_type = 0;
2985 break;
2986 default:
2987 return error_type (pp);
2988 }
2989 (*pp)++;
2990
2991 /* The first number appears to be the number of bytes occupied
2992 by this type, except that unsigned short is 4 instead of 2.
2993 Since this information is redundant with the third number,
2994 we will ignore it. */
2995 read_number (pp, ';');
2996
2997 /* The second number is always 0, so ignore it too. */
2998 read_number (pp, ';');
2999
3000 /* The third number is the number of bits for this type. */
3001 nbits = read_number (pp, 0);
3002
3003 /* FIXME. Here we should just be able to make a type of the right
3004 number of bits and signedness. FIXME. */
3005
3006 if (nbits == TARGET_LONG_LONG_BIT)
3007 return (lookup_fundamental_type (objfile,
3008 signed_type? FT_LONG_LONG: FT_UNSIGNED_LONG_LONG));
3009
3010 if (nbits == TARGET_INT_BIT) {
3011 /* FIXME -- the only way to distinguish `int' from `long'
3012 is to look at its name! */
3013 if (signed_type) {
3014 if (long_kludge_name && long_kludge_name[0] == 'l' /* long */)
3015 return lookup_fundamental_type (objfile, FT_LONG);
3016 else
3017 return lookup_fundamental_type (objfile, FT_INTEGER);
3018 } else {
3019 if (long_kludge_name
3020 && ((long_kludge_name[0] == 'u' /* unsigned */ &&
3021 long_kludge_name[9] == 'l' /* long */)
3022 || (long_kludge_name[0] == 'l' /* long unsigned */)))
3023 return lookup_fundamental_type (objfile, FT_UNSIGNED_LONG);
3024 else
3025 return lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
3026 }
3027 }
3028
3029 if (nbits == TARGET_SHORT_BIT)
3030 return (lookup_fundamental_type (objfile,
3031 signed_type? FT_SHORT: FT_UNSIGNED_SHORT));
3032
3033 if (nbits == TARGET_CHAR_BIT)
3034 return (lookup_fundamental_type (objfile,
3035 signed_type? FT_CHAR: FT_UNSIGNED_CHAR));
3036
3037 if (nbits == 0)
3038 return lookup_fundamental_type (objfile, FT_VOID);
3039
3040 return error_type (pp);
3041}
3042
3043static struct type *
3044read_sun_floating_type (pp, typenums, objfile)
3045 char **pp;
3046 int typenums[2];
3047 struct objfile *objfile;
3048{
3049 int nbytes;
3050
3051 /* The first number has more details about the type, for example
3052 FN_COMPLEX. See the sun stab.h. */
3053 read_number (pp, ';');
3054
3055 /* The second number is the number of bytes occupied by this type */
3056 nbytes = read_number (pp, ';');
3057
3058 if (**pp != 0)
3059 return error_type (pp);
3060
3061 if (nbytes == TARGET_FLOAT_BIT / TARGET_CHAR_BIT)
3062 return lookup_fundamental_type (objfile, FT_FLOAT);
3063
3064 if (nbytes == TARGET_DOUBLE_BIT / TARGET_CHAR_BIT)
3065 return lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
3066
3067 if (nbytes == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT)
3068 return lookup_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
3069
3070 return error_type (pp);
c0302457
JG
3071}
3072
3073/* Read a number from the string pointed to by *PP.
3074 The value of *PP is advanced over the number.
3075 If END is nonzero, the character that ends the
3076 number must match END, or an error happens;
3077 and that character is skipped if it does match.
3078 If END is zero, *PP is left pointing to that character.
3079
3080 If the number fits in a long, set *VALUE and set *BITS to 0.
3081 If not, set *BITS to be the number of bits in the number.
3082
3083 If encounter garbage, set *BITS to -1. */
3084
1ab3bf1b 3085static void
c0302457
JG
3086read_huge_number (pp, end, valu, bits)
3087 char **pp;
3088 int end;
3089 long *valu;
3090 int *bits;
3091{
3092 char *p = *pp;
3093 int sign = 1;
3094 long n = 0;
3095 int radix = 10;
3096 char overflow = 0;
3097 int nbits = 0;
3098 int c;
3099 long upper_limit;
3100
3101 if (*p == '-')
3102 {
3103 sign = -1;
3104 p++;
3105 }
3106
3107 /* Leading zero means octal. GCC uses this to output values larger
3108 than an int (because that would be hard in decimal). */
3109 if (*p == '0')
3110 {
3111 radix = 8;
3112 p++;
3113 }
3114
3115 upper_limit = LONG_MAX / radix;
3116 while ((c = *p++) >= '0' && c <= ('0' + radix))
3117 {
3118 if (n <= upper_limit)
3119 {
3120 n *= radix;
3121 n += c - '0'; /* FIXME this overflows anyway */
3122 }
3123 else
3124 overflow = 1;
3125
3126 /* This depends on large values being output in octal, which is
3127 what GCC does. */
3128 if (radix == 8)
3129 {
3130 if (nbits == 0)
3131 {
3132 if (c == '0')
3133 /* Ignore leading zeroes. */
3134 ;
3135 else if (c == '1')
3136 nbits = 1;
3137 else if (c == '2' || c == '3')
3138 nbits = 2;
3139 else
3140 nbits = 3;
3141 }
3142 else
3143 nbits += 3;
3144 }
3145 }
3146 if (end)
3147 {
3148 if (c && c != end)
3149 {
3150 if (bits != NULL)
3151 *bits = -1;
3152 return;
3153 }
3154 }
3155 else
3156 --p;
3157
3158 *pp = p;
3159 if (overflow)
3160 {
3161 if (nbits == 0)
3162 {
3163 /* Large decimal constants are an error (because it is hard to
3164 count how many bits are in them). */
3165 if (bits != NULL)
3166 *bits = -1;
3167 return;
3168 }
3169
3170 /* -0x7f is the same as 0x80. So deal with it by adding one to
3171 the number of bits. */
3172 if (sign == -1)
3173 ++nbits;
3174 if (bits)
3175 *bits = nbits;
3176 }
3177 else
3178 {
3179 if (valu)
3180 *valu = n * sign;
3181 if (bits)
3182 *bits = 0;
3183 }
3184}
3185
1ab3bf1b
JG
3186static struct type *
3187read_range_type (pp, typenums, objfile)
c0302457
JG
3188 char **pp;
3189 int typenums[2];
1ab3bf1b 3190 struct objfile *objfile;
c0302457
JG
3191{
3192 int rangenums[2];
3193 long n2, n3;
3194 int n2bits, n3bits;
3195 int self_subrange;
3196 struct type *result_type;
3197
3198 /* First comes a type we are a subrange of.
3199 In C it is usually 0, 1 or the type being defined. */
3200 read_type_number (pp, rangenums);
3201 self_subrange = (rangenums[0] == typenums[0] &&
3202 rangenums[1] == typenums[1]);
3203
3204 /* A semicolon should now follow; skip it. */
3205 if (**pp == ';')
3206 (*pp)++;
3207
3208 /* The remaining two operands are usually lower and upper bounds
3209 of the range. But in some special cases they mean something else. */
3210 read_huge_number (pp, ';', &n2, &n2bits);
3211 read_huge_number (pp, ';', &n3, &n3bits);
3212
3213 if (n2bits == -1 || n3bits == -1)
3214 return error_type (pp);
3215
3216 /* If limits are huge, must be large integral type. */
3217 if (n2bits != 0 || n3bits != 0)
3218 {
3219 char got_signed = 0;
3220 char got_unsigned = 0;
3221 /* Number of bits in the type. */
3222 int nbits;
3223
3224 /* Range from 0 to <large number> is an unsigned large integral type. */
3225 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
3226 {
3227 got_unsigned = 1;
3228 nbits = n3bits;
3229 }
3230 /* Range from <large number> to <large number>-1 is a large signed
3231 integral type. */
3232 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
3233 {
3234 got_signed = 1;
3235 nbits = n2bits;
3236 }
3237
3238 /* Check for "long long". */
3239 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
1ab3bf1b 3240 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
c0302457 3241 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
1ab3bf1b 3242 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
c0302457
JG
3243
3244 if (got_signed || got_unsigned)
3245 {
1ab3bf1b
JG
3246 result_type = (struct type *)
3247 obstack_alloc (&objfile -> type_obstack,
3248 sizeof (struct type));
c0302457 3249 bzero (result_type, sizeof (struct type));
1ab3bf1b 3250 TYPE_OBJFILE (result_type) = objfile;
c0302457 3251 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
c0302457
JG
3252 TYPE_CODE (result_type) = TYPE_CODE_INT;
3253 if (got_unsigned)
3254 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
3255 return result_type;
3256 }
3257 else
3258 return error_type (pp);
3259 }
3260
3261 /* A type defined as a subrange of itself, with bounds both 0, is void. */
3262 if (self_subrange && n2 == 0 && n3 == 0)
1ab3bf1b 3263 return (lookup_fundamental_type (objfile, FT_VOID));
c0302457
JG
3264
3265 /* If n3 is zero and n2 is not, we want a floating type,
3266 and n2 is the width in bytes.
3267
3268 Fortran programs appear to use this for complex types also,
3269 and they give no way to distinguish between double and single-complex!
3270 We don't have complex types, so we would lose on all fortran files!
3271 So return type `double' for all of those. It won't work right
2a5ec41d
JG
3272 for the complex values, but at least it makes the file loadable.
3273
3274 FIXME, we may be able to distinguish these by their names. FIXME. */
c0302457
JG
3275
3276 if (n3 == 0 && n2 > 0)
3277 {
3278 if (n2 == sizeof (float))
1ab3bf1b
JG
3279 return (lookup_fundamental_type (objfile, FT_FLOAT));
3280 return (lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT));
c0302457
JG
3281 }
3282
3283 /* If the upper bound is -1, it must really be an unsigned int. */
3284
3285 else if (n2 == 0 && n3 == -1)
3286 {
2a5ec41d
JG
3287 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3288 long' is to look at its name! */
3289 if (
3290 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
3291 long_kludge_name[9] == 'l' /* long */)
3292 || (long_kludge_name[0] == 'l' /* long unsigned */)))
1ab3bf1b 3293 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
2a5ec41d 3294 else
1ab3bf1b 3295 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
c0302457
JG
3296 }
3297
3298 /* Special case: char is defined (Who knows why) as a subrange of
3299 itself with range 0-127. */
3300 else if (self_subrange && n2 == 0 && n3 == 127)
1ab3bf1b 3301 return (lookup_fundamental_type (objfile, FT_CHAR));
c0302457
JG
3302
3303 /* Assumptions made here: Subrange of self is equivalent to subrange
a048c8f5 3304 of int. FIXME: Host and target type-sizes assumed the same. */
2a5ec41d
JG
3305 /* FIXME: This is the *only* place in GDB that depends on comparing
3306 some type to a builtin type with ==. Fix it! */
c0302457
JG
3307 else if (n2 == 0
3308 && (self_subrange ||
1ab3bf1b 3309 *dbx_lookup_type (rangenums) == lookup_fundamental_type (objfile, FT_INTEGER)))
c0302457
JG
3310 {
3311 /* an unsigned type */
3312#ifdef LONG_LONG
3313 if (n3 == - sizeof (long long))
1ab3bf1b 3314 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
c0302457 3315#endif
2a5ec41d
JG
3316 /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3317 long' is to look at its name! */
3318 if (n3 == (unsigned long)~0L &&
3319 long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
3320 long_kludge_name[9] == 'l' /* long */)
3321 || (long_kludge_name[0] == 'l' /* long unsigned */)))
1ab3bf1b 3322 return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
c0302457 3323 if (n3 == (unsigned int)~0L)
1ab3bf1b 3324 return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
c0302457 3325 if (n3 == (unsigned short)~0L)
1ab3bf1b 3326 return (lookup_fundamental_type (objfile, FT_UNSIGNED_SHORT));
c0302457 3327 if (n3 == (unsigned char)~0L)
1ab3bf1b 3328 return (lookup_fundamental_type (objfile, FT_UNSIGNED_CHAR));
c0302457
JG
3329 }
3330#ifdef LONG_LONG
3331 else if (n3 == 0 && n2 == -sizeof (long long))
1ab3bf1b 3332 return (lookup_fundamental_type (objfile, FT_LONG_LONG));
c0302457
JG
3333#endif
3334 else if (n2 == -n3 -1)
3335 {
3336 /* a signed type */
2a5ec41d
JG
3337 /* FIXME -- the only way to distinguish `int' from `long' is to look
3338 at its name! */
84ffdec2 3339 if ((n3 ==(long)(((unsigned long)1 << (8 * sizeof (long) - 1)) - 1)) &&
2a5ec41d 3340 long_kludge_name && long_kludge_name[0] == 'l' /* long */)
1ab3bf1b 3341 return (lookup_fundamental_type (objfile, FT_LONG));
84ffdec2 3342 if (n3 == (long)(((unsigned long)1 << (8 * sizeof (int) - 1)) - 1))
1ab3bf1b 3343 return (lookup_fundamental_type (objfile, FT_INTEGER));
84ffdec2 3344 if (n3 == ( 1 << (8 * sizeof (short) - 1)) - 1)
1ab3bf1b 3345 return (lookup_fundamental_type (objfile, FT_SHORT));
84ffdec2 3346 if (n3 == ( 1 << (8 * sizeof (char) - 1)) - 1)
1ab3bf1b 3347 return (lookup_fundamental_type (objfile, FT_CHAR));
c0302457
JG
3348 }
3349
3350 /* We have a real range type on our hands. Allocate space and
3351 return a real pointer. */
3352
3353 /* At this point I don't have the faintest idea how to deal with
3354 a self_subrange type; I'm going to assume that this is used
3355 as an idiom, and that all of them are special cases. So . . . */
3356 if (self_subrange)
3357 return error_type (pp);
3358
1ab3bf1b
JG
3359 result_type = (struct type *)
3360 obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
c0302457 3361 bzero (result_type, sizeof (struct type));
1ab3bf1b 3362 TYPE_OBJFILE (result_type) = objfile;
c0302457
JG
3363
3364 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
3365
3366 TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
3367 if (TYPE_TARGET_TYPE (result_type) == 0) {
1ab3bf1b
JG
3368 complain (&range_type_base_complaint, (char *) rangenums[1]);
3369 TYPE_TARGET_TYPE (result_type) = lookup_fundamental_type (objfile, FT_INTEGER);
c0302457
JG
3370 }
3371
3372 TYPE_NFIELDS (result_type) = 2;
3373 TYPE_FIELDS (result_type) =
1ab3bf1b
JG
3374 (struct field *) obstack_alloc (&objfile -> type_obstack,
3375 2 * sizeof (struct field));
c0302457
JG
3376 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
3377 TYPE_FIELD_BITPOS (result_type, 0) = n2;
3378 TYPE_FIELD_BITPOS (result_type, 1) = n3;
3379
c0302457
JG
3380 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
3381
3382 return result_type;
3383}
3384
3385/* Read a number from the string pointed to by *PP.
3386 The value of *PP is advanced over the number.
3387 If END is nonzero, the character that ends the
3388 number must match END, or an error happens;
3389 and that character is skipped if it does match.
3390 If END is zero, *PP is left pointing to that character. */
3391
3392long
3393read_number (pp, end)
3394 char **pp;
3395 int end;
3396{
3397 register char *p = *pp;
3398 register long n = 0;
3399 register int c;
3400 int sign = 1;
3401
3402 /* Handle an optional leading minus sign. */
3403
3404 if (*p == '-')
3405 {
3406 sign = -1;
3407 p++;
3408 }
3409
3410 /* Read the digits, as far as they go. */
3411
3412 while ((c = *p++) >= '0' && c <= '9')
3413 {
3414 n *= 10;
3415 n += c - '0';
3416 }
3417 if (end)
3418 {
3419 if (c && c != end)
3420 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
3421 }
3422 else
3423 --p;
3424
3425 *pp = p;
3426 return n * sign;
3427}
3428
3429/* Read in an argument list. This is a list of types, separated by commas
3430 and terminated with END. Return the list of types read in, or (struct type
3431 **)-1 if there is an error. */
1ab3bf1b
JG
3432static struct type **
3433read_args (pp, end, objfile)
c0302457
JG
3434 char **pp;
3435 int end;
1ab3bf1b 3436 struct objfile *objfile;
c0302457 3437{
a048c8f5 3438 /* FIXME! Remove this arbitrary limit! */
c0302457
JG
3439 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
3440 int n = 0;
3441
3442 while (**pp != end)
3443 {
3444 if (**pp != ',')
3445 /* Invalid argument list: no ','. */
3446 return (struct type **)-1;
3447 *pp += 1;
3448
3449 /* Check for and handle cretinous dbx symbol name continuation! */
3450 if (**pp == '\\')
3451 *pp = next_symbol_text ();
3452
1ab3bf1b 3453 types[n++] = read_type (pp, objfile);
c0302457
JG
3454 }
3455 *pp += 1; /* get past `end' (the ':' character) */
3456
3457 if (n == 1)
3458 {
3459 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3460 }
3461 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3462 {
3463 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3464 bzero (rval + n, sizeof (struct type *));
3465 }
3466 else
3467 {
3468 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3469 }
7e258d18 3470 memcpy (rval, types, n * sizeof (struct type *));
c0302457
JG
3471 return rval;
3472}
3473
3474/* Add a common block's start address to the offset of each symbol
3475 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3476 the common block name). */
3477
3478static void
3479fix_common_block (sym, valu)
3480 struct symbol *sym;
3481 int valu;
3482{
3483 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
3484 for ( ; next; next = next->next)
3485 {
3486 register int j;
3487 for (j = next->nsyms - 1; j >= 0; j--)
3488 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3489 }
3490}
3491
3492/* Initializer for this module */
3493void
3494_initialize_buildsym ()
3495{
3496 undef_types_allocated = 20;
3497 undef_types_length = 0;
3498 undef_types = (struct type **) xmalloc (undef_types_allocated *
3499 sizeof (struct type *));
3500}
This page took 0.190653 seconds and 4 git commands to generate.