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