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