]> Git Repo - binutils.git/blob - gdb/buildsym.c
Remove tm-es1800.h and remote-es1800.c from distribution files until
[binutils.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      ([email protected]) -- this strchr() handles them properly?
1165      ([email protected]) -- '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 [email protected].  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           /* Reasonable test to see if it's been defined since.  */
1626           if (TYPE_NFIELDS (*type) == 0)
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           else
1654             /* It has been defined; don't mark it as a stub.  */
1655             TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
1656         }
1657         break;
1658
1659       case TYPE_CODE_ARRAY:
1660         {
1661           struct type *range_type;
1662           int lower, upper;
1663
1664           if (TYPE_LENGTH (*type) != 0)         /* Better be unknown */
1665             goto badtype;
1666           if (TYPE_NFIELDS (*type) != 1)
1667             goto badtype;
1668           range_type = TYPE_FIELD_TYPE (*type, 0);
1669           if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
1670             goto badtype;
1671
1672           /* Now recompute the length of the array type, based on its
1673              number of elements and the target type's length.  */
1674           lower = TYPE_FIELD_BITPOS (range_type, 0);
1675           upper = TYPE_FIELD_BITPOS (range_type, 1);
1676           TYPE_LENGTH (*type) = (upper - lower + 1)
1677                           * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
1678         }
1679         break;
1680
1681       default:
1682       badtype:
1683         error ("GDB internal error.  cleanup_undefined_types with bad\
1684  type %d.", TYPE_CODE (*type));
1685         break;
1686     }
1687   }
1688   undef_types_length = 0;
1689 }
1690 \f
1691 /* Skip rest of this symbol and return an error type.
1692
1693    General notes on error recovery:  error_type always skips to the
1694    end of the symbol (modulo cretinous dbx symbol name continuation).
1695    Thus code like this:
1696
1697    if (*(*pp)++ != ';')
1698      return error_type (pp);
1699
1700    is wrong because if *pp starts out pointing at '\0' (typically as the
1701    result of an earlier error), it will be incremented to point to the
1702    start of the next symbol, which might produce strange results, at least
1703    if you run off the end of the string table.  Instead use
1704
1705    if (**pp != ';')
1706      return error_type (pp);
1707    ++*pp;
1708
1709    or
1710
1711    if (**pp != ';')
1712      foo = error_type (pp);
1713    else
1714      ++*pp;
1715
1716    And in case it isn't obvious, the point of all this hair is so the compiler
1717    can define new types and new syntaxes, and old versions of the
1718    debugger will be able to read the new symbol tables.  */
1719
1720 struct type *
1721 error_type (pp)
1722      char **pp;
1723 {
1724   complain (&error_type_complaint, 0);
1725   while (1)
1726     {
1727       /* Skip to end of symbol.  */
1728       while (**pp != '\0')
1729         (*pp)++;
1730
1731       /* Check for and handle cretinous dbx symbol name continuation!  */
1732       if ((*pp)[-1] == '\\')
1733         *pp = next_symbol_text ();
1734       else
1735         break;
1736     }
1737   return builtin_type_error;
1738 }
1739 \f
1740 /* Read a dbx type reference or definition;
1741    return the type that is meant.
1742    This can be just a number, in which case it references
1743    a type already defined and placed in type_vector.
1744    Or the number can be followed by an =, in which case
1745    it means to define a new type according to the text that
1746    follows the =.  */
1747
1748 struct type *
1749 read_type (pp, objfile)
1750      register char **pp;
1751      struct objfile *objfile;
1752 {
1753   register struct type *type = 0;
1754   struct type *type1;
1755   int typenums[2];
1756   int xtypenums[2];
1757
1758   /* Read type number if present.  The type number may be omitted.
1759      for instance in a two-dimensional array declared with type
1760      "ar1;1;10;ar1;1;10;4".  */
1761   if ((**pp >= '0' && **pp <= '9')
1762       || **pp == '(')
1763     {
1764       read_type_number (pp, typenums);
1765       
1766       /* Type is not being defined here.  Either it already exists,
1767          or this is a forward reference to it.  dbx_alloc_type handles
1768          both cases.  */
1769       if (**pp != '=')
1770         return dbx_alloc_type (typenums, objfile);
1771
1772       /* Type is being defined here.  */
1773 #if 0 /* Callers aren't prepared for a NULL result!  FIXME -- metin!  */
1774       {
1775         struct type *tt;
1776
1777         /* if such a type already exists, this is an unnecessary duplication
1778            of the stab string, which is common in (RS/6000) xlc generated
1779            objects.  In that case, simply return NULL and let the caller take
1780            care of it. */
1781
1782         tt = *dbx_lookup_type (typenums);
1783         if (tt && tt->length && tt->code)
1784           return NULL;
1785       }
1786 #endif
1787
1788       *pp += 2;
1789     }
1790   else
1791     {
1792       /* 'typenums=' not present, type is anonymous.  Read and return
1793          the definition, but don't put it in the type vector.  */
1794       typenums[0] = typenums[1] = -1;
1795       *pp += 1;
1796     }
1797
1798   switch ((*pp)[-1])
1799     {
1800     case 'x':
1801       {
1802         enum type_code code;
1803
1804         /* Used to index through file_symbols.  */
1805         struct pending *ppt;
1806         int i;
1807         
1808         /* Name including "struct", etc.  */
1809         char *type_name;
1810         
1811         /* Name without "struct", etc.  */
1812         char *type_name_only;
1813
1814         {
1815           char *prefix;
1816           char *from, *to;
1817           
1818           /* Set the type code according to the following letter.  */
1819           switch ((*pp)[0])
1820             {
1821             case 's':
1822               code = TYPE_CODE_STRUCT;
1823               prefix = "struct ";
1824               break;
1825             case 'u':
1826               code = TYPE_CODE_UNION;
1827               prefix = "union ";
1828               break;
1829             case 'e':
1830               code = TYPE_CODE_ENUM;
1831               prefix = "enum ";
1832               break;
1833             default:
1834               return error_type (pp);
1835             }
1836           
1837           to = type_name = (char *)
1838             obstack_alloc (&objfile -> type_obstack,
1839                            (strlen (prefix) +
1840                             ((char *) strchr (*pp, ':') - (*pp)) + 1));
1841         
1842           /* Copy the prefix.  */
1843           from = prefix;
1844           while (*to++ = *from++)
1845             ;
1846           to--; 
1847         
1848           type_name_only = to;
1849
1850           /* Copy the name.  */
1851           from = *pp + 1;
1852           while ((*to++ = *from++) != ':')
1853             ;
1854           *--to = '\0';
1855           
1856           /* Set the pointer ahead of the name which we just read.  */
1857           *pp = from;
1858         
1859 #if 0
1860           /* The following hack is clearly wrong, because it doesn't
1861              check whether we are in a baseclass.  I tried to reproduce
1862              the case that it is trying to fix, but I couldn't get
1863              g++ to put out a cross reference to a basetype.  Perhaps
1864              it doesn't do it anymore.  */
1865           /* Note: for C++, the cross reference may be to a base type which
1866              has not yet been seen.  In this case, we skip to the comma,
1867              which will mark the end of the base class name.  (The ':'
1868              at the end of the base class name will be skipped as well.)
1869              But sometimes (ie. when the cross ref is the last thing on
1870              the line) there will be no ','.  */
1871           from = (char *) strchr (*pp, ',');
1872           if (from)
1873             *pp = from;
1874 #endif /* 0 */
1875         }
1876
1877         /* Now check to see whether the type has already been declared.  */
1878         /* This is necessary at least in the case where the
1879            program says something like
1880              struct foo bar[5];
1881            The compiler puts out a cross-reference; we better find
1882            set the length of the structure correctly so we can
1883            set the length of the array.  */
1884         for (ppt = file_symbols; ppt; ppt = ppt->next)
1885           for (i = 0; i < ppt->nsyms; i++)
1886             {
1887               struct symbol *sym = ppt->symbol[i];
1888
1889               if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1890                   && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1891                   && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1892                   && !strcmp (SYMBOL_NAME (sym), type_name_only))
1893                 {
1894                   obstack_free (&objfile -> type_obstack, type_name);
1895                   type = SYMBOL_TYPE (sym);
1896                   return type;
1897                 }
1898             }
1899         
1900         /* Didn't find the type to which this refers, so we must
1901            be dealing with a forward reference.  Allocate a type
1902            structure for it, and keep track of it so we can
1903            fill in the rest of the fields when we get the full
1904            type.  */
1905         type = dbx_alloc_type (typenums, objfile);
1906         TYPE_CODE (type) = code;
1907         TYPE_NAME (type) = type_name;
1908         INIT_CPLUS_SPECIFIC(type);
1909         TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1910
1911         add_undefined_type (type);
1912         return type;
1913       }
1914
1915     case '-':                           /* RS/6000 built-in type */
1916       (*pp)--;
1917       type = builtin_type (pp);         /* (in xcoffread.c) */
1918       goto after_digits;
1919
1920     case '0':
1921     case '1':
1922     case '2':
1923     case '3':
1924     case '4':
1925     case '5':
1926     case '6':
1927     case '7':
1928     case '8':
1929     case '9':
1930     case '(':
1931       (*pp)--;
1932       read_type_number (pp, xtypenums);
1933       type = *dbx_lookup_type (xtypenums);
1934       /* fall through */
1935
1936     after_digits:
1937       if (type == 0)
1938         type = lookup_fundamental_type (objfile, FT_VOID);
1939       if (typenums[0] != -1)
1940         *dbx_lookup_type (typenums) = type;
1941       break;
1942
1943     /* In the following types, we must be sure to overwrite any existing
1944        type that the typenums refer to, rather than allocating a new one
1945        and making the typenums point to the new one.  This is because there
1946        may already be pointers to the existing type (if it had been
1947        forward-referenced), and we must change it to a pointer, function,
1948        reference, or whatever, *in-place*.  */
1949
1950     case '*':
1951       type1 = read_type (pp, objfile);
1952       type = make_pointer_type (type1, dbx_lookup_type (typenums));
1953       break;
1954
1955     case '&':                           /* Reference to another type */
1956       type1 = read_type (pp, objfile);
1957       type = make_reference_type (type1, dbx_lookup_type (typenums));
1958       break;
1959
1960     case 'f':                           /* Function returning another type */
1961       type1 = read_type (pp, objfile);
1962       type = make_function_type (type1, dbx_lookup_type (typenums));
1963       break;
1964
1965     case 'k':                           /* Const qualifier on some type (Sun) */
1966       type = read_type (pp, objfile);
1967       /* FIXME! For now, we ignore const and volatile qualifiers.  */
1968       break;
1969
1970     case 'B':                           /* Volatile qual on some type (Sun) */
1971       type = read_type (pp, objfile);
1972       /* FIXME! For now, we ignore const and volatile qualifiers.  */
1973       break;
1974
1975 /* FIXME -- we should be doing smash_to_XXX types here.  */
1976     case '@':                           /* Member (class & variable) type */
1977       {
1978         struct type *domain = read_type (pp, objfile);
1979         struct type *memtype;
1980
1981         if (**pp != ',')
1982           /* Invalid member type data format.  */
1983           return error_type (pp);
1984         ++*pp;
1985
1986         memtype = read_type (pp, objfile);
1987         type = dbx_alloc_type (typenums, objfile);
1988         smash_to_member_type (type, domain, memtype);
1989       }
1990       break;
1991
1992     case '#':                           /* Method (class & fn) type */
1993       if ((*pp)[0] == '#')
1994         {
1995           /* We'll get the parameter types from the name.  */
1996           struct type *return_type;
1997
1998           *pp += 1;
1999           return_type = read_type (pp, objfile);
2000           if (*(*pp)++ != ';')
2001             complain (&invalid_member_complaint, (char *) symnum);
2002           type = allocate_stub_method (return_type);
2003           if (typenums[0] != -1)
2004             *dbx_lookup_type (typenums) = type;
2005         }
2006       else
2007         {
2008           struct type *domain = read_type (pp, objfile);
2009           struct type *return_type;
2010           struct type **args;
2011
2012           if (*(*pp)++ != ',')
2013             error ("invalid member type data format, at symtab pos %d.",
2014                    symnum);
2015
2016           return_type = read_type (pp, objfile);
2017           args = read_args (pp, ';', objfile);
2018           type = dbx_alloc_type (typenums, objfile);
2019           smash_to_method_type (type, domain, return_type, args);
2020         }
2021       break;
2022
2023     case 'r':                           /* Range type */
2024       type = read_range_type (pp, typenums, objfile);
2025       if (typenums[0] != -1)
2026         *dbx_lookup_type (typenums) = type;
2027       break;
2028
2029     case 'b':                           /* Sun ACC builtin int type */
2030       type = read_sun_builtin_type (pp, typenums, objfile);
2031       if (typenums[0] != -1)
2032         *dbx_lookup_type (typenums) = type;
2033       break;
2034
2035     case 'R':                           /* Sun ACC builtin float type */
2036       type = read_sun_floating_type (pp, typenums, objfile);
2037       if (typenums[0] != -1)
2038         *dbx_lookup_type (typenums) = type;
2039       break;
2040     
2041     case 'e':                           /* Enumeration type */
2042       type = dbx_alloc_type (typenums, objfile);
2043       type = read_enum_type (pp, type, objfile);
2044       *dbx_lookup_type (typenums) = type;
2045       break;
2046
2047     case 's':                           /* Struct type */
2048       type = dbx_alloc_type (typenums, objfile);
2049       if (!TYPE_NAME (type))
2050         TYPE_NAME (type) = type_synonym_name;
2051       type_synonym_name = 0;
2052       type = read_struct_type (pp, type, objfile);
2053       break;
2054
2055     case 'u':                           /* Union type */
2056       type = dbx_alloc_type (typenums, objfile);
2057       if (!TYPE_NAME (type))
2058         TYPE_NAME (type) = type_synonym_name;
2059       type_synonym_name = 0;
2060       type = read_struct_type (pp, type, objfile);
2061       TYPE_CODE (type) = TYPE_CODE_UNION;
2062       break;
2063
2064     case 'a':                           /* Array type */
2065       if (**pp != 'r')
2066         return error_type (pp);
2067       ++*pp;
2068       
2069       type = dbx_alloc_type (typenums, objfile);
2070       type = read_array_type (pp, type, objfile);
2071       break;
2072
2073     default:
2074       --*pp;                    /* Go back to the symbol in error */
2075                                 /* Particularly important if it was \0! */
2076       return error_type (pp);
2077     }
2078
2079   if (type == 0)
2080     abort ();
2081
2082   return type;
2083 }
2084 \f
2085 /* This page contains subroutines of read_type.  */
2086
2087 /* Read the description of a structure (or union type)
2088    and return an object describing the type.  */
2089
2090 static struct type *
2091 read_struct_type (pp, type, objfile)
2092      char **pp;
2093      register struct type *type;
2094      struct objfile *objfile;
2095 {
2096   /* Total number of methods defined in this class.
2097      If the class defines two `f' methods, and one `g' method,
2098      then this will have the value 3.  */
2099   int total_length = 0;
2100
2101   struct nextfield
2102     {
2103       struct nextfield *next;
2104       int visibility;                   /* 0=public, 1=protected, 2=public */
2105       struct field field;
2106     };
2107
2108   struct next_fnfield
2109     {
2110       struct next_fnfield *next;
2111       struct fn_field fn_field;
2112     };
2113
2114   struct next_fnfieldlist
2115     {
2116       struct next_fnfieldlist *next;
2117       struct fn_fieldlist fn_fieldlist;
2118     };
2119
2120   register struct nextfield *list = 0;
2121   struct nextfield *new;
2122   register char *p;
2123   int nfields = 0;
2124   int non_public_fields = 0;
2125   register int n;
2126
2127   register struct next_fnfieldlist *mainlist = 0;
2128   int nfn_fields = 0;
2129
2130   TYPE_CODE (type) = TYPE_CODE_STRUCT;
2131   INIT_CPLUS_SPECIFIC(type);
2132
2133   /* First comes the total size in bytes.  */
2134
2135   TYPE_LENGTH (type) = read_number (pp, 0);
2136
2137   /* C++: Now, if the class is a derived class, then the next character
2138      will be a '!', followed by the number of base classes derived from.
2139      Each element in the list contains visibility information,
2140      the offset of this base class in the derived structure,
2141      and then the base type. */
2142   if (**pp == '!')
2143     {
2144       int i, n_baseclasses, offset;
2145       struct type *baseclass;
2146       int via_public;
2147
2148       /* Nonzero if it is a virtual baseclass, i.e.,
2149
2150          struct A{};
2151          struct B{};
2152          struct C : public B, public virtual A {};
2153
2154          B is a baseclass of C; A is a virtual baseclass for C.  This is a C++
2155          2.0 language feature.  */
2156       int via_virtual;
2157
2158       *pp += 1;
2159
2160       ALLOCATE_CPLUS_STRUCT_TYPE(type);
2161
2162       n_baseclasses = read_number (pp, ',');
2163       TYPE_FIELD_VIRTUAL_BITS (type) =
2164         (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2165                                   B_BYTES (n_baseclasses));
2166       B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
2167
2168       for (i = 0; i < n_baseclasses; i++)
2169         {
2170           if (**pp == '\\')
2171             *pp = next_symbol_text ();
2172
2173           switch (**pp)
2174             {
2175             case '0':
2176               via_virtual = 0;
2177               break;
2178             case '1':
2179               via_virtual = 1;
2180               break;
2181             default:
2182               /* Bad visibility format.  */
2183               return error_type (pp);
2184             }
2185           ++*pp;
2186
2187           switch (**pp)
2188             {
2189             case '0':
2190               via_public = 0;
2191               non_public_fields++;
2192               break;
2193             case '2':
2194               via_public = 2;
2195               break;
2196             default:
2197               /* Bad visibility format.  */
2198               return error_type (pp);
2199             }
2200           if (via_virtual) 
2201             SET_TYPE_FIELD_VIRTUAL (type, i);
2202           ++*pp;
2203
2204           /* Offset of the portion of the object corresponding to
2205              this baseclass.  Always zero in the absence of
2206              multiple inheritance.  */
2207           offset = read_number (pp, ',');
2208           baseclass = read_type (pp, objfile);
2209           *pp += 1;             /* skip trailing ';' */
2210
2211           /* Make this baseclass visible for structure-printing purposes.  */
2212           new = (struct nextfield *) alloca (sizeof (struct nextfield));
2213           new->next = list;
2214           list = new;
2215           list->visibility = via_public;
2216           list->field.type = baseclass;
2217           list->field.name = type_name_no_tag (baseclass);
2218           list->field.bitpos = offset;
2219           list->field.bitsize = 0;      /* this should be an unpacked field! */
2220           nfields++;
2221         }
2222       TYPE_N_BASECLASSES (type) = n_baseclasses;
2223     }
2224
2225   /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2226      At the end, we see a semicolon instead of a field.
2227
2228      In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2229      a static field.
2230
2231      The `?' is a placeholder for one of '/2' (public visibility),
2232      '/1' (protected visibility), '/0' (private visibility), or nothing
2233      (C style symbol table, public visibility).  */
2234
2235   /* We better set p right now, in case there are no fields at all...    */
2236   p = *pp;
2237
2238   while (**pp != ';')
2239     {
2240       /* Check for and handle cretinous dbx symbol name continuation!  */
2241       if (**pp == '\\') *pp = next_symbol_text ();
2242
2243       /* Get space to record the next field's data.  */
2244       new = (struct nextfield *) alloca (sizeof (struct nextfield));
2245       new->next = list;
2246       list = new;
2247
2248       /* Get the field name.  */
2249       p = *pp;
2250       if (*p == CPLUS_MARKER)
2251         {
2252           /* Special GNU C++ name.  */
2253           if (*++p == 'v')
2254             {
2255               const char *prefix;
2256               char *name = 0;
2257               struct type *context;
2258
2259               switch (*++p)
2260                 {
2261                 case 'f':
2262                   prefix = vptr_name;
2263                   break;
2264                 case 'b':
2265                   prefix = vb_name;
2266                   break;
2267                 default:
2268                   complain (&invalid_cpp_abbrev_complaint, *pp);
2269                   prefix = "INVALID_C++_ABBREV";
2270                   break;
2271                 }
2272               *pp = p + 1;
2273               context = read_type (pp, objfile);
2274               name = type_name_no_tag (context);
2275               if (name == 0)
2276                 {
2277                   complain (&invalid_cpp_type_complaint, (char *) symnum);
2278                   name = "FOO";
2279                 }
2280               list->field.name = obconcat (&objfile -> type_obstack,
2281                                            prefix, name, "");
2282               p = ++(*pp);
2283               if (p[-1] != ':')
2284                 complain (&invalid_cpp_abbrev_complaint, *pp);
2285               list->field.type = read_type (pp, objfile);
2286               (*pp)++;                  /* Skip the comma.  */
2287               list->field.bitpos = read_number (pp, ';');
2288               /* This field is unpacked.  */
2289               list->field.bitsize = 0;
2290               list->visibility = 0;     /* private */
2291               non_public_fields++;
2292             }
2293           /* GNU C++ anonymous type.  */
2294           else if (*p == '_')
2295             break;
2296           else
2297             complain (&invalid_cpp_abbrev_complaint, *pp);
2298
2299           nfields++;
2300           continue;
2301         }
2302
2303       while (*p != ':') p++;
2304       list->field.name = obsavestring (*pp, p - *pp,
2305                                        &objfile -> type_obstack);
2306
2307       /* C++: Check to see if we have hit the methods yet.  */
2308       if (p[1] == ':')
2309         break;
2310
2311       *pp = p + 1;
2312
2313       /* This means we have a visibility for a field coming. */
2314       if (**pp == '/')
2315         {
2316           switch (*++*pp)
2317             {
2318             case '0':
2319               list->visibility = 0;     /* private */
2320               non_public_fields++;
2321               *pp += 1;
2322               break;
2323
2324             case '1':
2325               list->visibility = 1;     /* protected */
2326               non_public_fields++;
2327               *pp += 1;
2328               break;
2329
2330             case '2':
2331               list->visibility = 2;     /* public */
2332               *pp += 1;
2333               break;
2334             }
2335         }
2336        else /* normal dbx-style format.  */
2337         list->visibility = 2;           /* public */
2338
2339       list->field.type = read_type (pp, objfile);
2340       if (**pp == ':')
2341         {
2342           /* Static class member.  */
2343           list->field.bitpos = (long)-1;
2344           p = ++(*pp);
2345           while (*p != ';') p++;
2346           list->field.bitsize = (long) savestring (*pp, p - *pp);
2347           *pp = p + 1;
2348           nfields++;
2349           continue;
2350         }
2351        else if (**pp != ',')
2352          /* Bad structure-type format.  */
2353          return error_type (pp);
2354
2355       (*pp)++;                  /* Skip the comma.  */
2356       list->field.bitpos = read_number (pp, ',');
2357       list->field.bitsize = read_number (pp, ';');
2358
2359 #if 0
2360       /* FIXME-tiemann: Can't the compiler put out something which
2361          lets us distinguish these? (or maybe just not put out anything
2362          for the field).  What is the story here?  What does the compiler
2363         really do?  Also, patch gdb.texinfo for this case; I document
2364         it as a possible problem there.  Search for "DBX-style".  */
2365
2366       /* This is wrong because this is identical to the symbols
2367          produced for GCC 0-size arrays.  For example:
2368          typedef union {
2369            int num;
2370            char str[0];
2371          } foo;
2372          The code which dumped core in such circumstances should be
2373          fixed not to dump core.  */
2374
2375       /* g++ -g0 can put out bitpos & bitsize zero for a static
2376          field.  This does not give us any way of getting its
2377          class, so we can't know its name.  But we can just
2378          ignore the field so we don't dump core and other nasty
2379          stuff.  */
2380       if (list->field.bitpos == 0
2381           && list->field.bitsize == 0)
2382         {
2383           complain (&dbx_class_complaint, 0);
2384           /* Ignore this field.  */
2385           list = list->next;
2386         }
2387       else
2388 #endif /* 0 */
2389         {
2390           /* Detect an unpacked field and mark it as such.
2391              dbx gives a bit size for all fields.
2392              Note that forward refs cannot be packed,
2393              and treat enums as if they had the width of ints.  */
2394           if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
2395               && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
2396             list->field.bitsize = 0;
2397           if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
2398                || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
2399                    && (list->field.bitsize
2400                        == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile, FT_INTEGER)))
2401                    )
2402                )
2403               &&
2404               list->field.bitpos % 8 == 0)
2405             list->field.bitsize = 0;
2406           nfields++;
2407         }
2408     }
2409
2410   if (p[1] == ':')
2411     /* chill the list of fields: the last entry (at the head)
2412        is a partially constructed entry which we now scrub.  */
2413     list = list->next;
2414
2415   /* Now create the vector of fields, and record how big it is.
2416      We need this info to record proper virtual function table information
2417      for this class's virtual functions.  */
2418
2419   TYPE_NFIELDS (type) = nfields;
2420   TYPE_FIELDS (type) = (struct field *)
2421     obstack_alloc (&objfile -> type_obstack, sizeof (struct field) * nfields);
2422
2423   if (non_public_fields)
2424     {
2425       ALLOCATE_CPLUS_STRUCT_TYPE (type);
2426
2427       TYPE_FIELD_PRIVATE_BITS (type) =
2428           (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2429                                     B_BYTES (nfields));
2430       B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2431
2432       TYPE_FIELD_PROTECTED_BITS (type) =
2433           (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2434                                     B_BYTES (nfields));
2435       B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2436     }
2437
2438   /* Copy the saved-up fields into the field vector.  */
2439
2440   for (n = nfields; list; list = list->next)
2441     {
2442       n -= 1;
2443       TYPE_FIELD (type, n) = list->field;
2444       if (list->visibility == 0)
2445         SET_TYPE_FIELD_PRIVATE (type, n);
2446       else if (list->visibility == 1)
2447         SET_TYPE_FIELD_PROTECTED (type, n);
2448     }
2449
2450   /* Now come the method fields, as NAME::methods
2451      where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2452      At the end, we see a semicolon instead of a field.
2453
2454      For the case of overloaded operators, the format is
2455      op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2456      `*' holds the place for an operator name (such as `+=')
2457      and `.' marks the end of the operator name.  */
2458   if (p[1] == ':')
2459     {
2460       /* Now, read in the methods.  To simplify matters, we
2461          "unread" the name that has been read, so that we can
2462          start from the top.  */
2463
2464       ALLOCATE_CPLUS_STRUCT_TYPE (type);
2465       /* For each list of method lists... */
2466       do
2467         {
2468           int i;
2469           struct next_fnfield *sublist = 0;
2470           struct type *look_ahead_type = NULL;
2471           int length = 0;
2472           struct next_fnfieldlist *new_mainlist =
2473             (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
2474           char *main_fn_name;
2475
2476           p = *pp;
2477
2478           /* read in the name.  */
2479           while (*p != ':') p++;
2480           if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
2481             {
2482               /* This is a completely wierd case.  In order to stuff in the
2483                  names that might contain colons (the usual name delimiter),
2484                  Mike Tiemann defined a different name format which is
2485                  signalled if the identifier is "op$".  In that case, the
2486                  format is "op$::XXXX." where XXXX is the name.  This is
2487                  used for names like "+" or "=".  YUUUUUUUK!  FIXME!  */
2488               /* This lets the user type "break operator+".
2489                  We could just put in "+" as the name, but that wouldn't
2490                  work for "*".  */
2491               static char opname[32] = {'o', 'p', CPLUS_MARKER};
2492               char *o = opname + 3;
2493
2494               /* Skip past '::'.  */
2495               *pp = p + 2;
2496               if (**pp == '\\') *pp = next_symbol_text ();
2497               p = *pp;
2498               while (*p != '.')
2499                 *o++ = *p++;
2500               main_fn_name = savestring (opname, o - opname);
2501               /* Skip past '.'  */
2502               *pp = p + 1;
2503             }
2504           else
2505             {
2506               main_fn_name = savestring (*pp, p - *pp);
2507               /* Skip past '::'.  */
2508               *pp = p + 2;
2509             }
2510           new_mainlist->fn_fieldlist.name = main_fn_name;
2511
2512           do
2513             {
2514               struct next_fnfield *new_sublist =
2515                 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
2516
2517               /* Check for and handle cretinous dbx symbol name continuation!  */
2518               if (look_ahead_type == NULL) /* Normal case. */
2519                 {
2520                   if (**pp == '\\') *pp = next_symbol_text ();
2521
2522                   new_sublist->fn_field.type = read_type (pp, objfile);
2523                   if (**pp != ':')
2524                     /* Invalid symtab info for method.  */
2525                     return error_type (pp);
2526                 }
2527               else
2528                 { /* g++ version 1 kludge */
2529                   new_sublist->fn_field.type = look_ahead_type;
2530                   look_ahead_type = NULL;
2531                 }
2532
2533               *pp += 1;
2534               p = *pp;
2535               while (*p != ';') p++;
2536
2537               /* If this is just a stub, then we don't have the
2538                  real name here.  */
2539               if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
2540                 new_sublist->fn_field.is_stub = 1;
2541               new_sublist->fn_field.physname = savestring (*pp, p - *pp);
2542               *pp = p + 1;
2543
2544               /* Set this method's visibility fields.  */
2545               switch (*(*pp)++ - '0')
2546                 {
2547                 case 0:
2548                   new_sublist->fn_field.is_private = 1;
2549                   break;
2550                 case 1:
2551                   new_sublist->fn_field.is_protected = 1;
2552                   break;
2553                 }
2554
2555               if (**pp == '\\') *pp = next_symbol_text ();
2556               switch (**pp)
2557                 {
2558                 case 'A': /* Normal functions. */
2559                   new_sublist->fn_field.is_const = 0;
2560                   new_sublist->fn_field.is_volatile = 0;
2561                   (*pp)++;
2562                   break;
2563                 case 'B': /* `const' member functions. */
2564                   new_sublist->fn_field.is_const = 1;
2565                   new_sublist->fn_field.is_volatile = 0;
2566                   (*pp)++;
2567                   break;
2568                 case 'C': /* `volatile' member function. */
2569                   new_sublist->fn_field.is_const = 0;
2570                   new_sublist->fn_field.is_volatile = 1;
2571                   (*pp)++;
2572                   break;
2573                 case 'D': /* `const volatile' member function. */
2574                   new_sublist->fn_field.is_const = 1;
2575                   new_sublist->fn_field.is_volatile = 1;
2576                   (*pp)++;
2577                   break;
2578                 case '*': /* File compiled with g++ version 1 -- no info */
2579                 case '?':
2580                 case '.':
2581                   break;
2582                 default:
2583                   complain (&const_vol_complaint, (char *) (long) **pp);
2584                   break;
2585                 }
2586
2587               switch (*(*pp)++)
2588                 {
2589                 case '*':
2590                   /* virtual member function, followed by index.  */
2591                   /* The sign bit is set to distinguish pointers-to-methods
2592                      from virtual function indicies.  Since the array is
2593                      in words, the quantity must be shifted left by 1
2594                      on 16 bit machine, and by 2 on 32 bit machine, forcing
2595                      the sign bit out, and usable as a valid index into
2596                      the array.  Remove the sign bit here.  */
2597                   new_sublist->fn_field.voffset =
2598                       (0x7fffffff & read_number (pp, ';')) + 2;
2599
2600                   if (**pp == '\\') *pp = next_symbol_text ();
2601
2602                   if (**pp == ';' || **pp == '\0')
2603                     /* Must be g++ version 1.  */
2604                     new_sublist->fn_field.fcontext = 0;
2605                   else
2606                     {
2607                       /* Figure out from whence this virtual function came.
2608                          It may belong to virtual function table of
2609                          one of its baseclasses.  */
2610                       look_ahead_type = read_type (pp, objfile);
2611                       if (**pp == ':')
2612                         { /* g++ version 1 overloaded methods. */ }
2613                       else
2614                         {
2615                           new_sublist->fn_field.fcontext = look_ahead_type;
2616                           if (**pp != ';')
2617                             return error_type (pp);
2618                           else
2619                             ++*pp;
2620                           look_ahead_type = NULL;
2621                         }
2622                     }
2623                   break;
2624
2625                 case '?':
2626                   /* static member function.  */
2627                   new_sublist->fn_field.voffset = VOFFSET_STATIC;
2628                   if (strncmp (new_sublist->fn_field.physname,
2629                                main_fn_name, strlen (main_fn_name)))
2630                     new_sublist->fn_field.is_stub = 1;
2631                   break;
2632
2633                 default:
2634                   /* error */
2635                   complain (&member_fn_complaint, (char *) (long) (*pp)[-1]);
2636                   /* Fall through into normal member function.  */
2637
2638                 case '.':
2639                   /* normal member function.  */
2640                   new_sublist->fn_field.voffset = 0;
2641                   new_sublist->fn_field.fcontext = 0;
2642                   break;
2643                 }
2644
2645               new_sublist->next = sublist;
2646               sublist = new_sublist;
2647               length++;
2648               if (**pp == '\\') *pp = next_symbol_text ();
2649             }
2650           while (**pp != ';' && **pp != '\0');
2651
2652           *pp += 1;
2653
2654           new_mainlist->fn_fieldlist.fn_fields =
2655             (struct fn_field *) obstack_alloc (&objfile -> type_obstack,
2656                                                sizeof (struct fn_field) * length);
2657           for (i = length; (i--, sublist); sublist = sublist->next)
2658             new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
2659
2660           new_mainlist->fn_fieldlist.length = length;
2661           new_mainlist->next = mainlist;
2662           mainlist = new_mainlist;
2663           nfn_fields++;
2664           total_length += length;
2665           if (**pp == '\\') *pp = next_symbol_text ();
2666         }
2667       while (**pp != ';');
2668     }
2669
2670   *pp += 1;
2671
2672
2673   if (nfn_fields)
2674     {
2675       TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2676         obstack_alloc (&objfile -> type_obstack,
2677                        sizeof (struct fn_fieldlist) * nfn_fields);
2678       TYPE_NFN_FIELDS (type) = nfn_fields;
2679       TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2680     }
2681
2682   {
2683     int i;
2684     for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
2685       TYPE_NFN_FIELDS_TOTAL (type) +=
2686         TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
2687   }
2688
2689   for (n = nfn_fields; mainlist; mainlist = mainlist->next) {
2690     --n;                      /* Circumvent Sun3 compiler bug */
2691     TYPE_FN_FIELDLISTS (type)[n] = mainlist->fn_fieldlist;
2692   }
2693
2694   if (**pp == '~')
2695     {
2696       *pp += 1;
2697
2698       if (**pp == '=' || **pp == '+' || **pp == '-')
2699         {
2700           /* Obsolete flags that used to indicate the presence
2701              of constructors and/or destructors. */
2702           *pp += 1;
2703         }
2704
2705       /* Read either a '%' or the final ';'.  */
2706       if (*(*pp)++ == '%')
2707         {
2708           /* We'd like to be able to derive the vtable pointer field
2709              from the type information, but when it's inherited, that's
2710              hard.  A reason it's hard is because we may read in the
2711              info about a derived class before we read in info about
2712              the base class that provides the vtable pointer field.
2713              Once the base info has been read, we could fill in the info
2714              for the derived classes, but for the fact that by then,
2715              we don't remember who needs what.  */
2716
2717 #if 0
2718           int predicted_fieldno = -1;
2719 #endif
2720
2721           /* Now we must record the virtual function table pointer's
2722              field information.  */
2723
2724           struct type *t;
2725           int i;
2726
2727
2728 #if 0
2729           {
2730             /* In version 2, we derive the vfield ourselves.  */
2731             for (n = 0; n < nfields; n++)
2732               {
2733                 if (! strncmp (TYPE_FIELD_NAME (type, n), vptr_name, 
2734                                sizeof (vptr_name) -1))
2735                   {
2736                     predicted_fieldno = n;
2737                     break;
2738                   }
2739               }
2740             if (predicted_fieldno < 0)
2741               for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2742                 if (! TYPE_FIELD_VIRTUAL (type, n)
2743                     && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n)) >= 0)
2744                   {
2745                     predicted_fieldno = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n));
2746                     break;
2747                   }
2748           }
2749 #endif
2750
2751           t = read_type (pp, objfile);
2752           p = (*pp)++;
2753           while (*p != '\0' && *p != ';')
2754             p++;
2755           if (*p == '\0')
2756             /* Premature end of symbol.  */
2757             return error_type (pp);
2758           
2759           TYPE_VPTR_BASETYPE (type) = t;
2760           if (type == t)
2761             {
2762               if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
2763                 {
2764                   /* FIXME-tiemann: what's this?  */
2765 #if 0
2766                   TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
2767 #else
2768                   error_type (pp);
2769 #endif
2770                 }
2771               else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
2772                 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name, 
2773                                sizeof (vptr_name) -1))
2774                   {
2775                     TYPE_VPTR_FIELDNO (type) = i;
2776                     break;
2777                   }
2778               if (i < 0)
2779                 /* Virtual function table field not found.  */
2780                 return error_type (pp);
2781             }
2782           else
2783             TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2784
2785 #if 0
2786           if (TYPE_VPTR_FIELDNO (type) != predicted_fieldno)
2787             error ("TYPE_VPTR_FIELDNO miscalculated");
2788 #endif
2789
2790           *pp = p + 1;
2791         }
2792     }
2793
2794   return type;
2795 }
2796
2797 /* Read a definition of an array type,
2798    and create and return a suitable type object.
2799    Also creates a range type which represents the bounds of that
2800    array.  */
2801 static struct type *
2802 read_array_type (pp, type, objfile)
2803      register char **pp;
2804      register struct type *type;
2805      struct objfile *objfile;
2806 {
2807   struct type *index_type, *element_type, *range_type;
2808   int lower, upper;
2809   int adjustable = 0;
2810
2811   /* Format of an array type:
2812      "ar<index type>;lower;upper;<array_contents_type>".  Put code in
2813      to handle this.
2814
2815      Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2816      for these, produce a type like float[][].  */
2817
2818   index_type = read_type (pp, objfile);
2819   if (**pp != ';')
2820     /* Improper format of array type decl.  */
2821     return error_type (pp);
2822   ++*pp;
2823
2824   if (!(**pp >= '0' && **pp <= '9'))
2825     {
2826       *pp += 1;
2827       adjustable = 1;
2828     }
2829   lower = read_number (pp, ';');
2830
2831   if (!(**pp >= '0' && **pp <= '9'))
2832     {
2833       *pp += 1;
2834       adjustable = 1;
2835     }
2836   upper = read_number (pp, ';');
2837   
2838   element_type = read_type (pp, objfile);
2839
2840   if (adjustable)
2841     {
2842       lower = 0;
2843       upper = -1;
2844     }
2845
2846   {
2847     /* Create range type.  */
2848     range_type = (struct type *)
2849       obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
2850     memset (range_type, 0, sizeof (struct type));
2851     TYPE_OBJFILE (range_type) = objfile;
2852     TYPE_CODE (range_type) = TYPE_CODE_RANGE;
2853     TYPE_TARGET_TYPE (range_type) = index_type;
2854
2855     /* This should never be needed.  */
2856     TYPE_LENGTH (range_type) = sizeof (int);
2857
2858     TYPE_NFIELDS (range_type) = 2;
2859     TYPE_FIELDS (range_type) =
2860       (struct field *) obstack_alloc (&objfile -> type_obstack,
2861                                       2 * sizeof (struct field));
2862     TYPE_FIELD_BITPOS (range_type, 0) = lower;
2863     TYPE_FIELD_BITPOS (range_type, 1) = upper;
2864   }
2865
2866   TYPE_CODE (type) = TYPE_CODE_ARRAY;
2867   TYPE_TARGET_TYPE (type) = element_type;
2868   TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
2869   TYPE_NFIELDS (type) = 1;
2870   TYPE_FIELDS (type) =
2871     (struct field *) obstack_alloc (&objfile -> type_obstack,
2872                                     sizeof (struct field));
2873   TYPE_FIELD_TYPE (type, 0) = range_type;
2874
2875   /* If we have an array whose element type is not yet known, but whose
2876      bounds *are* known, record it to be adjusted at the end of the file.  */
2877   if (TYPE_LENGTH (element_type) == 0 && !adjustable)
2878     add_undefined_type (type);
2879
2880   return type;
2881 }
2882
2883
2884 /* Read a definition of an enumeration type,
2885    and create and return a suitable type object.
2886    Also defines the symbols that represent the values of the type.  */
2887
2888 static struct type *
2889 read_enum_type (pp, type, objfile)
2890      register char **pp;
2891      register struct type *type;
2892      struct objfile *objfile;
2893 {
2894   register char *p;
2895   char *name;
2896   register long n;
2897   register struct symbol *sym;
2898   int nsyms = 0;
2899   struct pending **symlist;
2900   struct pending *osyms, *syms;
2901   int o_nsyms;
2902
2903 #if 0
2904   /* FIXME!  The stabs produced by Sun CC merrily define things that ought
2905      to be file-scope, between N_FN entries, using N_LSYM.  What's a mother
2906      to do?  For now, force all enum values to file scope.  */
2907   if (within_function)
2908     symlist = &local_symbols;
2909   else
2910 #endif
2911     symlist = &file_symbols;
2912   osyms = *symlist;
2913   o_nsyms = osyms ? osyms->nsyms : 0;
2914
2915   /* Read the value-names and their values.
2916      The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2917      A semicolon or comma instead of a NAME means the end.  */
2918   while (**pp && **pp != ';' && **pp != ',')
2919     {
2920       /* Check for and handle cretinous dbx symbol name continuation!  */
2921       if (**pp == '\\') *pp = next_symbol_text ();
2922
2923       p = *pp;
2924       while (*p != ':') p++;
2925       name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
2926       *pp = p + 1;
2927       n = read_number (pp, ',');
2928
2929       sym = (struct symbol *) obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
2930       memset (sym, 0, sizeof (struct symbol));
2931       SYMBOL_NAME (sym) = name;
2932       SYMBOL_CLASS (sym) = LOC_CONST;
2933       SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2934       SYMBOL_VALUE (sym) = n;
2935       add_symbol_to_list (sym, symlist);
2936       nsyms++;
2937     }
2938
2939   if (**pp == ';')
2940     (*pp)++;                    /* Skip the semicolon.  */
2941
2942   /* Now fill in the fields of the type-structure.  */
2943
2944   TYPE_LENGTH (type) = sizeof (int);
2945   TYPE_CODE (type) = TYPE_CODE_ENUM;
2946   TYPE_NFIELDS (type) = nsyms;
2947   TYPE_FIELDS (type) = (struct field *)
2948     obstack_alloc (&objfile -> type_obstack,
2949                    sizeof (struct field) * nsyms);
2950
2951   /* Find the symbols for the values and put them into the type.
2952      The symbols can be found in the symlist that we put them on
2953      to cause them to be defined.  osyms contains the old value
2954      of that symlist; everything up to there was defined by us.  */
2955   /* Note that we preserve the order of the enum constants, so
2956      that in something like "enum {FOO, LAST_THING=FOO}" we print
2957      FOO, not LAST_THING.  */
2958
2959   for (syms = *symlist, n = 0; syms; syms = syms->next)
2960     {
2961       int j = 0;
2962       if (syms == osyms)
2963         j = o_nsyms;
2964       for (; j < syms->nsyms; j++,n++)
2965         {
2966           struct symbol *xsym = syms->symbol[j];
2967           SYMBOL_TYPE (xsym) = type;
2968           TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2969           TYPE_FIELD_VALUE (type, n) = 0;
2970           TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2971           TYPE_FIELD_BITSIZE (type, n) = 0;
2972         }
2973       if (syms == osyms)
2974         break;
2975     }
2976
2977 #if 0
2978   /* This screws up perfectly good C programs with enums.  FIXME.  */
2979   /* Is this Modula-2's BOOLEAN type?  Flag it as such if so. */
2980   if(TYPE_NFIELDS(type) == 2 &&
2981      ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2982        !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2983       (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2984        !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2985      TYPE_CODE(type) = TYPE_CODE_BOOL;
2986 #endif
2987
2988   return type;
2989 }
2990
2991 /* Sun's ACC uses a somewhat saner method for specifying the builtin
2992    typedefs in every file (for int, long, etc):
2993
2994         type = b <signed> <width>; <offset>; <nbits>
2995         signed = u or s.  Possible c in addition to u or s (for char?).
2996         offset = offset from high order bit to start bit of type.
2997         width is # bytes in object of this type, nbits is # bits in type.
2998
2999    The width/offset stuff appears to be for small objects stored in
3000    larger ones (e.g. `shorts' in `int' registers).  We ignore it for now,
3001    FIXME.  */
3002
3003 static struct type *
3004 read_sun_builtin_type (pp, typenums, objfile)
3005      char **pp;
3006      int typenums[2];
3007      struct objfile *objfile;
3008 {
3009   int nbits;
3010   int signed_type;
3011
3012   switch (**pp) {
3013   case 's':
3014     signed_type = 1;
3015     break;
3016   case 'u':
3017     signed_type = 0;
3018     break;
3019   default:
3020     return error_type (pp);
3021   }
3022   (*pp)++;
3023
3024   /* For some odd reason, all forms of char put a c here.  This is strange
3025      because no other type has this honor.  We can safely ignore this because
3026      we actually determine 'char'acterness by the number of bits specified in
3027      the descriptor.  */
3028
3029   if (**pp == 'c')
3030     (*pp)++;
3031
3032   /* The first number appears to be the number of bytes occupied
3033      by this type, except that unsigned short is 4 instead of 2.
3034      Since this information is redundant with the third number,
3035      we will ignore it.  */
3036   read_number (pp, ';');
3037
3038   /* The second number is always 0, so ignore it too. */
3039   read_number (pp, ';');
3040
3041   /* The third number is the number of bits for this type. */
3042   nbits = read_number (pp, 0);
3043
3044   /* FIXME.  Here we should just be able to make a type of the right
3045      number of bits and signedness.  FIXME.  */
3046
3047   if (nbits == TARGET_LONG_LONG_BIT)
3048     return (lookup_fundamental_type (objfile,
3049                  signed_type? FT_LONG_LONG: FT_UNSIGNED_LONG_LONG));
3050   
3051   if (nbits == TARGET_INT_BIT) {
3052     /* FIXME -- the only way to distinguish `int' from `long'
3053        is to look at its name!  */
3054     if (signed_type) {
3055       if (long_kludge_name && long_kludge_name[0] == 'l' /* long */)
3056         return lookup_fundamental_type (objfile, FT_LONG);
3057       else
3058         return lookup_fundamental_type (objfile, FT_INTEGER);
3059     } else {
3060       if (long_kludge_name
3061           && ((long_kludge_name[0] == 'u' /* unsigned */ &&
3062                long_kludge_name[9] == 'l' /* long */)
3063               || (long_kludge_name[0] == 'l' /* long unsigned */)))
3064         return lookup_fundamental_type (objfile, FT_UNSIGNED_LONG);
3065       else
3066         return lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER);
3067     }
3068   }
3069     
3070   if (nbits == TARGET_SHORT_BIT)
3071     return (lookup_fundamental_type (objfile,
3072                  signed_type? FT_SHORT: FT_UNSIGNED_SHORT));
3073   
3074   if (nbits == TARGET_CHAR_BIT)
3075     return (lookup_fundamental_type (objfile,
3076                  signed_type? FT_CHAR: FT_UNSIGNED_CHAR));
3077   
3078   if (nbits == 0)
3079     return lookup_fundamental_type (objfile, FT_VOID);
3080   
3081   return error_type (pp);
3082 }
3083
3084 static struct type *
3085 read_sun_floating_type (pp, typenums, objfile)
3086      char **pp;
3087      int typenums[2];
3088      struct objfile *objfile;
3089 {
3090   int nbytes;
3091
3092   /* The first number has more details about the type, for example
3093      FN_COMPLEX.  See the sun stab.h.  */
3094   read_number (pp, ';');
3095
3096   /* The second number is the number of bytes occupied by this type */
3097   nbytes = read_number (pp, ';');
3098
3099   if (**pp != 0)
3100     return error_type (pp);
3101
3102   if (nbytes == TARGET_FLOAT_BIT / TARGET_CHAR_BIT)
3103     return lookup_fundamental_type (objfile, FT_FLOAT);
3104
3105   if (nbytes == TARGET_DOUBLE_BIT / TARGET_CHAR_BIT)
3106     return lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT);
3107
3108   if (nbytes == TARGET_LONG_DOUBLE_BIT / TARGET_CHAR_BIT)
3109     return lookup_fundamental_type (objfile, FT_EXT_PREC_FLOAT);
3110
3111   return error_type (pp);
3112 }
3113
3114 /* Read a number from the string pointed to by *PP.
3115    The value of *PP is advanced over the number.
3116    If END is nonzero, the character that ends the
3117    number must match END, or an error happens;
3118    and that character is skipped if it does match.
3119    If END is zero, *PP is left pointing to that character.
3120
3121    If the number fits in a long, set *VALUE and set *BITS to 0.
3122    If not, set *BITS to be the number of bits in the number.
3123
3124    If encounter garbage, set *BITS to -1.  */
3125
3126 static void
3127 read_huge_number (pp, end, valu, bits)
3128      char **pp;
3129      int end;
3130      long *valu;
3131      int *bits;
3132 {
3133   char *p = *pp;
3134   int sign = 1;
3135   long n = 0;
3136   int radix = 10;
3137   char overflow = 0;
3138   int nbits = 0;
3139   int c;
3140   long upper_limit;
3141   
3142   if (*p == '-')
3143     {
3144       sign = -1;
3145       p++;
3146     }
3147
3148   /* Leading zero means octal.  GCC uses this to output values larger
3149      than an int (because that would be hard in decimal).  */
3150   if (*p == '0')
3151     {
3152       radix = 8;
3153       p++;
3154     }
3155
3156   upper_limit = LONG_MAX / radix;
3157   while ((c = *p++) >= '0' && c <= ('0' + radix))
3158     {
3159       if (n <= upper_limit)
3160         {
3161           n *= radix;
3162           n += c - '0';         /* FIXME this overflows anyway */
3163         }
3164       else
3165         overflow = 1;
3166       
3167       /* This depends on large values being output in octal, which is
3168          what GCC does. */
3169       if (radix == 8)
3170         {
3171           if (nbits == 0)
3172             {
3173               if (c == '0')
3174                 /* Ignore leading zeroes.  */
3175                 ;
3176               else if (c == '1')
3177                 nbits = 1;
3178               else if (c == '2' || c == '3')
3179                 nbits = 2;
3180               else
3181                 nbits = 3;
3182             }
3183           else
3184             nbits += 3;
3185         }
3186     }
3187   if (end)
3188     {
3189       if (c && c != end)
3190         {
3191           if (bits != NULL)
3192             *bits = -1;
3193           return;
3194         }
3195     }
3196   else
3197     --p;
3198
3199   *pp = p;
3200   if (overflow)
3201     {
3202       if (nbits == 0)
3203         {
3204           /* Large decimal constants are an error (because it is hard to
3205              count how many bits are in them).  */
3206           if (bits != NULL)
3207             *bits = -1;
3208           return;
3209         }
3210       
3211       /* -0x7f is the same as 0x80.  So deal with it by adding one to
3212          the number of bits.  */
3213       if (sign == -1)
3214         ++nbits;
3215       if (bits)
3216         *bits = nbits;
3217     }
3218   else
3219     {
3220       if (valu)
3221         *valu = n * sign;
3222       if (bits)
3223         *bits = 0;
3224     }
3225 }
3226
3227 static struct type *
3228 read_range_type (pp, typenums, objfile)
3229      char **pp;
3230      int typenums[2];
3231      struct objfile *objfile;
3232 {
3233   int rangenums[2];
3234   long n2, n3;
3235   int n2bits, n3bits;
3236   int self_subrange;
3237   struct type *result_type;
3238
3239   /* First comes a type we are a subrange of.
3240      In C it is usually 0, 1 or the type being defined.  */
3241   read_type_number (pp, rangenums);
3242   self_subrange = (rangenums[0] == typenums[0] &&
3243                    rangenums[1] == typenums[1]);
3244
3245   /* A semicolon should now follow; skip it.  */
3246   if (**pp == ';')
3247     (*pp)++;
3248
3249   /* The remaining two operands are usually lower and upper bounds
3250      of the range.  But in some special cases they mean something else.  */
3251   read_huge_number (pp, ';', &n2, &n2bits);
3252   read_huge_number (pp, ';', &n3, &n3bits);
3253
3254   if (n2bits == -1 || n3bits == -1)
3255     return error_type (pp);
3256   
3257   /* If limits are huge, must be large integral type.  */
3258   if (n2bits != 0 || n3bits != 0)
3259     {
3260       char got_signed = 0;
3261       char got_unsigned = 0;
3262       /* Number of bits in the type.  */
3263       int nbits;
3264
3265       /* Range from 0 to <large number> is an unsigned large integral type.  */
3266       if ((n2bits == 0 && n2 == 0) && n3bits != 0)
3267         {
3268           got_unsigned = 1;
3269           nbits = n3bits;
3270         }
3271       /* Range from <large number> to <large number>-1 is a large signed
3272          integral type.  */
3273       else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
3274         {
3275           got_signed = 1;
3276           nbits = n2bits;
3277         }
3278
3279       /* Check for "long long".  */
3280       if (got_signed && nbits == TARGET_LONG_LONG_BIT)
3281         return (lookup_fundamental_type (objfile, FT_LONG_LONG));
3282       if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
3283         return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
3284
3285       if (got_signed || got_unsigned)
3286         {
3287           result_type = (struct type *)
3288             obstack_alloc (&objfile -> type_obstack,
3289                            sizeof (struct type));
3290           memset (result_type, 0, sizeof (struct type));
3291           TYPE_OBJFILE (result_type) = objfile;
3292           TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
3293           TYPE_CODE (result_type) = TYPE_CODE_INT;
3294           if (got_unsigned)
3295             TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
3296           return result_type;
3297         }
3298       else
3299         return error_type (pp);
3300     }
3301
3302   /* A type defined as a subrange of itself, with bounds both 0, is void.  */
3303   if (self_subrange && n2 == 0 && n3 == 0)
3304     return (lookup_fundamental_type (objfile, FT_VOID));
3305
3306   /* If n3 is zero and n2 is not, we want a floating type,
3307      and n2 is the width in bytes.
3308
3309      Fortran programs appear to use this for complex types also,
3310      and they give no way to distinguish between double and single-complex!
3311      We don't have complex types, so we would lose on all fortran files!
3312      So return type `double' for all of those.  It won't work right
3313      for the complex values, but at least it makes the file loadable.
3314
3315      FIXME, we may be able to distinguish these by their names. FIXME.  */
3316
3317   if (n3 == 0 && n2 > 0)
3318     {
3319       if (n2 == sizeof (float))
3320         return (lookup_fundamental_type (objfile, FT_FLOAT));
3321       return (lookup_fundamental_type (objfile, FT_DBL_PREC_FLOAT));
3322     }
3323
3324   /* If the upper bound is -1, it must really be an unsigned int.  */
3325
3326   else if (n2 == 0 && n3 == -1)
3327     {
3328       /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3329          long' is to look at its name!  */
3330       if (
3331        long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
3332                              long_kludge_name[9] == 'l' /* long */)
3333                          || (long_kludge_name[0] == 'l' /* long unsigned */)))
3334         return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
3335       else
3336         return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
3337     }
3338
3339   /* Special case: char is defined (Who knows why) as a subrange of
3340      itself with range 0-127.  */
3341   else if (self_subrange && n2 == 0 && n3 == 127)
3342     return (lookup_fundamental_type (objfile, FT_CHAR));
3343
3344   /* Assumptions made here: Subrange of self is equivalent to subrange
3345      of int.  FIXME:  Host and target type-sizes assumed the same.  */
3346   /* FIXME:  This is the *only* place in GDB that depends on comparing
3347      some type to a builtin type with ==.  Fix it! */
3348   else if (n2 == 0
3349            && (self_subrange ||
3350                *dbx_lookup_type (rangenums) == lookup_fundamental_type (objfile, FT_INTEGER)))
3351     {
3352       /* an unsigned type */
3353 #ifdef LONG_LONG
3354       if (n3 == - sizeof (long long))
3355         return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG_LONG));
3356 #endif
3357       /* FIXME -- the only way to distinguish `unsigned int' from `unsigned
3358          long' is to look at its name!  */
3359       if (n3 == (unsigned long)~0L &&
3360        long_kludge_name && ((long_kludge_name[0] == 'u' /* unsigned */ &&
3361                              long_kludge_name[9] == 'l' /* long */)
3362                          || (long_kludge_name[0] == 'l' /* long unsigned */)))
3363         return (lookup_fundamental_type (objfile, FT_UNSIGNED_LONG));
3364       if (n3 == (unsigned int)~0L)
3365         return (lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER));
3366       if (n3 == (unsigned short)~0L)
3367         return (lookup_fundamental_type (objfile, FT_UNSIGNED_SHORT));
3368       if (n3 == (unsigned char)~0L)
3369         return (lookup_fundamental_type (objfile, FT_UNSIGNED_CHAR));
3370     }
3371 #ifdef LONG_LONG
3372   else if (n3 == 0 && n2 == -sizeof (long long))
3373     return (lookup_fundamental_type (objfile, FT_LONG_LONG));
3374 #endif  
3375   else if (n2 == -n3 -1)
3376     {
3377       /* a signed type */
3378       /* FIXME -- the only way to distinguish `int' from `long' is to look
3379          at its name!  */
3380       if ((n3 ==(long)(((unsigned long)1 << (8 * sizeof (long)  - 1)) - 1)) &&
3381        long_kludge_name && long_kludge_name[0] == 'l' /* long */)
3382          return (lookup_fundamental_type (objfile, FT_LONG));
3383       if (n3 == (long)(((unsigned long)1 << (8 * sizeof (int)   - 1)) - 1))
3384         return (lookup_fundamental_type (objfile, FT_INTEGER));
3385       if (n3 ==        (               1 << (8 * sizeof (short) - 1)) - 1)
3386         return (lookup_fundamental_type (objfile, FT_SHORT));
3387       if (n3 ==        (               1 << (8 * sizeof (char)  - 1)) - 1)
3388         return (lookup_fundamental_type (objfile, FT_SIGNED_CHAR));
3389     }
3390
3391   /* We have a real range type on our hands.  Allocate space and
3392      return a real pointer.  */
3393
3394   /* At this point I don't have the faintest idea how to deal with
3395      a self_subrange type; I'm going to assume that this is used
3396      as an idiom, and that all of them are special cases.  So . . .  */
3397   if (self_subrange)
3398     return error_type (pp);
3399
3400   result_type = (struct type *)
3401     obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
3402   memset (result_type, 0, sizeof (struct type));
3403   TYPE_OBJFILE (result_type) = objfile;
3404
3405   TYPE_CODE (result_type) = TYPE_CODE_RANGE;
3406
3407   TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
3408   if (TYPE_TARGET_TYPE (result_type) == 0) {
3409     complain (&range_type_base_complaint, (char *) rangenums[1]);
3410     TYPE_TARGET_TYPE (result_type) = lookup_fundamental_type (objfile, FT_INTEGER);
3411   }
3412
3413   TYPE_NFIELDS (result_type) = 2;
3414   TYPE_FIELDS (result_type) =
3415     (struct field *) obstack_alloc (&objfile -> type_obstack,
3416                                     2 * sizeof (struct field));
3417   memset (TYPE_FIELDS (result_type), 0, 2 * sizeof (struct field));
3418   TYPE_FIELD_BITPOS (result_type, 0) = n2;
3419   TYPE_FIELD_BITPOS (result_type, 1) = n3;
3420
3421   TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
3422
3423   return result_type;
3424 }
3425
3426 /* Read a number from the string pointed to by *PP.
3427    The value of *PP is advanced over the number.
3428    If END is nonzero, the character that ends the
3429    number must match END, or an error happens;
3430    and that character is skipped if it does match.
3431    If END is zero, *PP is left pointing to that character.  */
3432
3433 long
3434 read_number (pp, end)
3435      char **pp;
3436      int end;
3437 {
3438   register char *p = *pp;
3439   register long n = 0;
3440   register int c;
3441   int sign = 1;
3442
3443   /* Handle an optional leading minus sign.  */
3444
3445   if (*p == '-')
3446     {
3447       sign = -1;
3448       p++;
3449     }
3450
3451   /* Read the digits, as far as they go.  */
3452
3453   while ((c = *p++) >= '0' && c <= '9')
3454     {
3455       n *= 10;
3456       n += c - '0';
3457     }
3458   if (end)
3459     {
3460       if (c && c != end)
3461         error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
3462     }
3463   else
3464     --p;
3465
3466   *pp = p;
3467   return n * sign;
3468 }
3469
3470 /* Read in an argument list.  This is a list of types, separated by commas
3471    and terminated with END.  Return the list of types read in, or (struct type
3472    **)-1 if there is an error.  */
3473 static struct type **
3474 read_args (pp, end, objfile)
3475      char **pp;
3476      int end;
3477      struct objfile *objfile;
3478 {
3479   /* FIXME!  Remove this arbitrary limit!  */
3480   struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
3481   int n = 0;
3482
3483   while (**pp != end)
3484     {
3485       if (**pp != ',')
3486         /* Invalid argument list: no ','.  */
3487         return (struct type **)-1;
3488       *pp += 1;
3489
3490       /* Check for and handle cretinous dbx symbol name continuation! */
3491       if (**pp == '\\')
3492         *pp = next_symbol_text ();
3493
3494       types[n++] = read_type (pp, objfile);
3495     }
3496   *pp += 1;                     /* get past `end' (the ':' character) */
3497
3498   if (n == 1)
3499     {
3500       rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3501     }
3502   else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3503     {
3504       rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3505       memset (rval + n, 0, sizeof (struct type *));
3506     }
3507   else
3508     {
3509       rval = (struct type **) xmalloc (n * sizeof (struct type *));
3510     }
3511   memcpy (rval, types, n * sizeof (struct type *));
3512   return rval;
3513 }
3514
3515 /* Add a common block's start address to the offset of each symbol
3516    declared to be in it (by being between a BCOMM/ECOMM pair that uses
3517    the common block name).  */
3518
3519 static void
3520 fix_common_block (sym, valu)
3521     struct symbol *sym;
3522     int valu;
3523 {
3524   struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
3525   for ( ; next; next = next->next)
3526     {
3527       register int j;
3528       for (j = next->nsyms - 1; j >= 0; j--)
3529         SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3530     }
3531 }
3532
3533 /* Initializer for this module */
3534 void
3535 _initialize_buildsym ()
3536 {
3537   undef_types_allocated = 20;
3538   undef_types_length = 0;
3539   undef_types = (struct type **) xmalloc (undef_types_allocated *
3540                                           sizeof (struct type *));
3541 }
This page took 0.217989 seconds and 4 git commands to generate.