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