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