Misc cleanups from code review.
[deliverable/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 "defs.h"
28 #include "obstack.h"
29 #include "symtab.h"
30 #include "gdbtypes.h"
31 #include "breakpoint.h"
32 #include "gdbcore.h" /* for bfd stuff for symfile.h */
33 #include "symfile.h" /* Needed for "struct complaint" */
34 #include "objfiles.h"
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 #ifndef IBM6000
730 printf ("ERROR! stab symbol not found!\n"); /* FIXME */
731 #endif
732 }
733 else
734 {
735 pp += 2;
736 if (*(pp-1) == 'F' || *(pp-1) == 'f')
737 {
738 SYMBOL_TYPE (sym) =
739 lookup_function_type (read_type (&pp, objfile));
740 }
741 else
742 {
743 SYMBOL_TYPE (sym) = read_type (&pp, objfile);
744 }
745 }
746 }
747 }
748 }
749
750 /* Finish the symbol definitions for one main source file,
751 close off all the lexical contexts for that file
752 (creating struct block's for them), then make the struct symtab
753 for that file and put it in the list of all such.
754
755 END_ADDR is the address of the end of the file's text. */
756
757 struct symtab *
758 end_symtab (end_addr, sort_pending, sort_linevec, objfile)
759 CORE_ADDR end_addr;
760 int sort_pending;
761 int sort_linevec;
762 struct objfile *objfile;
763 {
764 register struct symtab *symtab;
765 register struct blockvector *blockvector;
766 register struct subfile *subfile;
767 struct subfile *nextsub;
768
769 /* Finish the lexical context of the last function in the file;
770 pop the context stack. */
771
772 if (context_stack_depth > 0)
773 {
774 register struct context_stack *cstk;
775 context_stack_depth--;
776 cstk = &context_stack[context_stack_depth];
777 /* Make a block for the local symbols within. */
778 finish_block (cstk->name, &local_symbols, cstk->old_blocks,
779 cstk->start_addr, end_addr, objfile);
780
781 /* Debug: if context stack still has something in it, we are in
782 trouble. */
783 if (context_stack_depth > 0)
784 abort ();
785 }
786
787 /* It is unfortunate that in aixcoff, pending blocks might not be ordered
788 in this stage. Especially, blocks for static functions will show up at
789 the end. We need to sort them, so tools like `find_pc_function' and
790 `find_pc_block' can work reliably. */
791 if (sort_pending && pending_blocks) {
792 /* FIXME! Remove this horrid bubble sort and use qsort!!! */
793 int swapped;
794 do {
795 struct pending_block *pb, *pbnext;
796
797 pb = pending_blocks, pbnext = pb->next;
798 swapped = 0;
799
800 while ( pbnext ) {
801
802 /* swap blocks if unordered! */
803
804 if (BLOCK_START(pb->block) < BLOCK_START(pbnext->block)) {
805 struct block *tmp = pb->block;
806 pb->block = pbnext->block;
807 pbnext->block = tmp;
808 swapped = 1;
809 }
810 pb = pbnext;
811 pbnext = pbnext->next;
812 }
813 } while (swapped);
814 }
815
816 /* Cleanup any undefined types that have been left hanging around
817 (this needs to be done before the finish_blocks so that
818 file_symbols is still good). */
819 cleanup_undefined_types ();
820
821 if (global_stabs) {
822 patch_block_stabs (global_symbols, global_stabs, objfile);
823 free (global_stabs);
824 global_stabs = 0;
825 }
826
827 if (pending_blocks == 0
828 && file_symbols == 0
829 && global_symbols == 0) {
830 /* Ignore symtabs that have no functions with real debugging info */
831 blockvector = NULL;
832 } else {
833 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
834 finish_block (0, &file_symbols, 0, last_source_start_addr, end_addr, objfile);
835 finish_block (0, &global_symbols, 0, last_source_start_addr, end_addr, objfile);
836 blockvector = make_blockvector (objfile);
837 }
838
839 #ifdef PROCESS_LINENUMBER_HOOK
840 PROCESS_LINENUMBER_HOOK (); /* Needed for aixcoff. */
841 #endif
842
843 /* Now create the symtab objects proper, one for each subfile. */
844 /* (The main file is the last one on the chain.) */
845
846 for (subfile = subfiles; subfile; subfile = nextsub)
847 {
848 int linetablesize;
849 /* If we have blocks of symbols, make a symtab.
850 Otherwise, just ignore this file and any line number info in it. */
851 symtab = 0;
852 if (blockvector) {
853 if (subfile->line_vector) {
854 /* First, shrink the linetable to make more memory. */
855 linetablesize = sizeof (struct linetable) +
856 subfile->line_vector->nitems * sizeof (struct linetable_entry);
857 subfile->line_vector = (struct linetable *)
858 xrealloc ((char *) subfile->line_vector, linetablesize);
859
860 if (sort_linevec)
861 qsort (subfile->line_vector->item, subfile->line_vector->nitems,
862 sizeof (struct linetable_entry), compare_line_numbers);
863 }
864
865 /* Now, allocate a symbol table. */
866 symtab = allocate_symtab (subfile->name, objfile);
867
868 /* Fill in its components. */
869 symtab->blockvector = blockvector;
870 if (subfile->line_vector)
871 {
872 /* Reallocate the line table on the symbol obstack */
873 symtab->linetable = (struct linetable *)
874 obstack_alloc (&objfile -> symbol_obstack, linetablesize);
875 memcpy (symtab->linetable, subfile->line_vector, linetablesize);
876 }
877 else
878 {
879 symtab->linetable = NULL;
880 }
881 symtab->dirname = subfile->dirname;
882 symtab->free_code = free_linetable;
883 symtab->free_ptr = 0;
884
885 #if 0 /* defined(IBM6000) */
886 /* In case we need to duplicate symbol tables (to represent include
887 files), and in case our system needs relocation, we want to
888 relocate the main symbol table node only (for the main file,
889 not for the include files). */
890
891 symtab->nonreloc = TRUE;
892 #endif
893 }
894 if (subfile->line_vector)
895 free (subfile->line_vector);
896
897 nextsub = subfile->next;
898 free (subfile);
899 }
900
901 #if 0 /* defined(IBM6000) */
902 /* all include symbol tables are non-relocatable, except the main source
903 file's. */
904 if (symtab_list)
905 symtab_list->nonreloc = FALSE;
906 #endif
907
908 if (type_vector)
909 free ((char *) type_vector);
910 type_vector = 0;
911 type_vector_length = 0;
912
913 last_source_file = 0;
914 current_subfile = 0;
915 previous_stab_code = 0;
916
917 return symtab;
918 }
919
920
921 /* Push a context block. Args are an identifying nesting level (checkable
922 when you pop it), and the starting PC address of this context. */
923
924 struct context_stack *
925 push_context (desc, valu)
926 int desc;
927 CORE_ADDR valu;
928 {
929 register struct context_stack *new;
930
931 if (context_stack_depth == context_stack_size)
932 {
933 context_stack_size *= 2;
934 context_stack = (struct context_stack *)
935 xrealloc ((char *) context_stack,
936 (context_stack_size * sizeof (struct context_stack)));
937 }
938
939 new = &context_stack[context_stack_depth++];
940 new->depth = desc;
941 new->locals = local_symbols;
942 new->old_blocks = pending_blocks;
943 new->start_addr = valu;
944 new->name = 0;
945
946 local_symbols = 0;
947
948 return new;
949 }
950 \f
951 /* Initialize anything that needs initializing when starting to read
952 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
953 to a psymtab. */
954
955 void
956 buildsym_init ()
957 {
958 free_pendings = 0;
959 file_symbols = 0;
960 global_symbols = 0;
961 pending_blocks = 0;
962 }
963
964 /* Initialize anything that needs initializing when a completely new
965 symbol file is specified (not just adding some symbols from another
966 file, e.g. a shared library). */
967
968 void
969 buildsym_new_init ()
970 {
971 /* Empty the hash table of global syms looking for values. */
972 bzero (global_sym_chain, sizeof global_sym_chain);
973
974 buildsym_init ();
975 }
976
977 /* Scan through all of the global symbols defined in the object file,
978 assigning values to the debugging symbols that need to be assigned
979 to. Get these symbols from the minimal symbol table. */
980
981 void
982 scan_file_globals (objfile)
983 struct objfile *objfile;
984 {
985 int hash;
986 struct minimal_symbol *msymbol;
987 struct symbol *sym, *prev;
988
989 for (msymbol = objfile -> msymbols; msymbol -> name != NULL; msymbol++)
990 {
991 QUIT;
992
993 prev = (struct symbol *) 0;
994
995 /* Get the hash index and check all the symbols
996 under that hash index. */
997
998 hash = hashname (msymbol -> name);
999
1000 for (sym = global_sym_chain[hash]; sym;)
1001 {
1002 if (*(msymbol -> name) == SYMBOL_NAME (sym)[0]
1003 && !strcmp(msymbol -> name + 1, SYMBOL_NAME (sym) + 1))
1004 {
1005 /* Splice this symbol out of the hash chain and
1006 assign the value we have to it. */
1007 if (prev)
1008 SYMBOL_VALUE_CHAIN (prev) = SYMBOL_VALUE_CHAIN (sym);
1009 else
1010 global_sym_chain[hash] = SYMBOL_VALUE_CHAIN (sym);
1011
1012 /* Check to see whether we need to fix up a common block. */
1013 /* Note: this code might be executed several times for
1014 the same symbol if there are multiple references. */
1015 if (SYMBOL_CLASS (sym) == LOC_BLOCK)
1016 fix_common_block (sym, msymbol -> address);
1017 else
1018 SYMBOL_VALUE_ADDRESS (sym) = msymbol -> address;
1019
1020 if (prev)
1021 sym = SYMBOL_VALUE_CHAIN (prev);
1022 else
1023 sym = global_sym_chain[hash];
1024 }
1025 else
1026 {
1027 prev = sym;
1028 sym = SYMBOL_VALUE_CHAIN (sym);
1029 }
1030 }
1031 }
1032 }
1033
1034 \f
1035 /* Read a number by which a type is referred to in dbx data,
1036 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
1037 Just a single number N is equivalent to (0,N).
1038 Return the two numbers by storing them in the vector TYPENUMS.
1039 TYPENUMS will then be used as an argument to dbx_lookup_type. */
1040
1041 void
1042 read_type_number (pp, typenums)
1043 register char **pp;
1044 register int *typenums;
1045 {
1046 if (**pp == '(')
1047 {
1048 (*pp)++;
1049 typenums[0] = read_number (pp, ',');
1050 typenums[1] = read_number (pp, ')');
1051 }
1052 else
1053 {
1054 typenums[0] = 0;
1055 typenums[1] = read_number (pp, 0);
1056 }
1057 }
1058 \f
1059 /* To handle GNU C++ typename abbreviation, we need to be able to
1060 fill in a type's name as soon as space for that type is allocated.
1061 `type_synonym_name' is the name of the type being allocated.
1062 It is cleared as soon as it is used (lest all allocated types
1063 get this name). */
1064 static char *type_synonym_name;
1065
1066 /* ARGSUSED */
1067 struct symbol *
1068 define_symbol (valu, string, desc, type, objfile)
1069 unsigned int valu;
1070 char *string;
1071 int desc;
1072 int type;
1073 struct objfile *objfile;
1074 {
1075 register struct symbol *sym;
1076 char *p = (char *) strchr (string, ':');
1077 int deftype;
1078 int synonym = 0;
1079 register int i;
1080 struct type *temptype;
1081
1082 /* Ignore syms with empty names. */
1083 if (string[0] == 0)
1084 return 0;
1085
1086 /* Ignore old-style symbols from cc -go */
1087 if (p == 0)
1088 return 0;
1089
1090 sym = (struct symbol *)obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
1091
1092 if (processing_gcc_compilation) {
1093 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
1094 number of bytes occupied by a type or object, which we ignore. */
1095 SYMBOL_LINE(sym) = desc;
1096 } else {
1097 SYMBOL_LINE(sym) = 0; /* unknown */
1098 }
1099
1100 if (string[0] == CPLUS_MARKER)
1101 {
1102 /* Special GNU C++ names. */
1103 switch (string[1])
1104 {
1105 case 't':
1106 SYMBOL_NAME (sym) = obsavestring ("this", strlen ("this"),
1107 &objfile -> symbol_obstack);
1108 break;
1109 case 'v': /* $vtbl_ptr_type */
1110 /* Was: SYMBOL_NAME (sym) = "vptr"; */
1111 goto normal;
1112 case 'e':
1113 SYMBOL_NAME (sym) = obsavestring ("eh_throw", strlen ("eh_throw"),
1114 &objfile -> symbol_obstack);
1115 break;
1116
1117 case '_':
1118 /* This was an anonymous type that was never fixed up. */
1119 goto normal;
1120
1121 default:
1122 abort ();
1123 }
1124 }
1125 else
1126 {
1127 normal:
1128 SYMBOL_NAME (sym)
1129 = (char *) obstack_alloc (&objfile -> symbol_obstack, ((p - string) + 1));
1130 /* Open-coded bcopy--saves function call time. */
1131 {
1132 register char *p1 = string;
1133 register char *p2 = SYMBOL_NAME (sym);
1134 while (p1 != p)
1135 *p2++ = *p1++;
1136 *p2++ = '\0';
1137 }
1138 }
1139 p++;
1140 /* Determine the type of name being defined. */
1141 /* The Acorn RISC machine's compiler can put out locals that don't
1142 start with "234=" or "(3,4)=", so assume anything other than the
1143 deftypes we know how to handle is a local. */
1144 /* (Peter Watkins @ Computervision)
1145 Handle Sun-style local fortran array types 'ar...' .
1146 (gnu@cygnus.com) -- this strchr() handles them properly?
1147 (tiemann@cygnus.com) -- 'C' is for catch. */
1148 if (!strchr ("cfFGpPrStTvVXC", *p))
1149 deftype = 'l';
1150 else
1151 deftype = *p++;
1152
1153 /* c is a special case, not followed by a type-number.
1154 SYMBOL:c=iVALUE for an integer constant symbol.
1155 SYMBOL:c=rVALUE for a floating constant symbol.
1156 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1157 e.g. "b:c=e6,0" for "const b = blob1"
1158 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1159 if (deftype == 'c')
1160 {
1161 if (*p++ != '=')
1162 error ("Invalid symbol data at symtab pos %d.", symnum);
1163 switch (*p++)
1164 {
1165 case 'r':
1166 {
1167 double d = atof (p);
1168 char *dbl_valu;
1169
1170 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1171 FT_DBL_PREC_FLOAT);
1172 dbl_valu = (char *)
1173 obstack_alloc (&objfile -> type_obstack,
1174 sizeof (double));
1175 memcpy (dbl_valu, &d, sizeof (double));
1176 SWAP_TARGET_AND_HOST (dbl_valu, sizeof (double));
1177 SYMBOL_VALUE_BYTES (sym) = dbl_valu;
1178 SYMBOL_CLASS (sym) = LOC_CONST_BYTES;
1179 }
1180 break;
1181 case 'i':
1182 {
1183 SYMBOL_TYPE (sym) = lookup_fundamental_type (objfile,
1184 FT_INTEGER);
1185 SYMBOL_VALUE (sym) = atoi (p);
1186 SYMBOL_CLASS (sym) = LOC_CONST;
1187 }
1188 break;
1189 case 'e':
1190 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
1191 e.g. "b:c=e6,0" for "const b = blob1"
1192 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
1193 {
1194 int typenums[2];
1195
1196 read_type_number (&p, typenums);
1197 if (*p++ != ',')
1198 error ("Invalid symbol data: no comma in enum const symbol");
1199
1200 SYMBOL_TYPE (sym) = *dbx_lookup_type (typenums);
1201 SYMBOL_VALUE (sym) = atoi (p);
1202 SYMBOL_CLASS (sym) = LOC_CONST;
1203 }
1204 break;
1205 default:
1206 error ("Invalid symbol data at symtab pos %d.", symnum);
1207 }
1208 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1209 add_symbol_to_list (sym, &file_symbols);
1210 return sym;
1211 }
1212
1213 /* Now usually comes a number that says which data type,
1214 and possibly more stuff to define the type
1215 (all of which is handled by read_type) */
1216
1217 if (deftype == 'p' && *p == 'F')
1218 /* pF is a two-letter code that means a function parameter in Fortran.
1219 The type-number specifies the type of the return value.
1220 Translate it into a pointer-to-function type. */
1221 {
1222 p++;
1223 SYMBOL_TYPE (sym)
1224 = lookup_pointer_type (lookup_function_type (read_type (&p, objfile)));
1225 }
1226 else
1227 {
1228 struct type *type_read;
1229 synonym = *p == 't';
1230
1231 if (synonym)
1232 {
1233 p += 1;
1234 type_synonym_name = obsavestring (SYMBOL_NAME (sym),
1235 strlen (SYMBOL_NAME (sym)),
1236 &objfile -> symbol_obstack);
1237 }
1238
1239 /* Here we save the name of the symbol for read_range_type, which
1240 ends up reading in the basic types. In stabs, unfortunately there
1241 is no distinction between "int" and "long" types except their
1242 names. Until we work out a saner type policy (eliminating most
1243 builtin types and using the names specified in the files), we
1244 save away the name so that far away from here in read_range_type,
1245 we can examine it to decide between "int" and "long". FIXME. */
1246 long_kludge_name = SYMBOL_NAME (sym);
1247 type_read = read_type (&p, objfile);
1248
1249 if ((deftype == 'F' || deftype == 'f')
1250 && TYPE_CODE (type_read) != TYPE_CODE_FUNC)
1251 {
1252 #if 0
1253 /* This code doesn't work -- it needs to realloc and can't. */
1254 struct type *new = (struct type *)
1255 obstack_alloc (&objfile -> type_obstack,
1256 sizeof (struct type));
1257
1258 /* Generate a template for the type of this function. The
1259 types of the arguments will be added as we read the symbol
1260 table. */
1261 *new = *lookup_function_type (type_read);
1262 SYMBOL_TYPE(sym) = new;
1263 TYPE_OBJFILE (new) = objfile;
1264 in_function_type = new;
1265 #else
1266 SYMBOL_TYPE (sym) = lookup_function_type (type_read);
1267 #endif
1268 }
1269 else
1270 SYMBOL_TYPE (sym) = type_read;
1271 }
1272
1273 switch (deftype)
1274 {
1275 case 'C':
1276 /* The name of a caught exception. */
1277 SYMBOL_CLASS (sym) = LOC_LABEL;
1278 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1279 SYMBOL_VALUE_ADDRESS (sym) = valu;
1280 add_symbol_to_list (sym, &local_symbols);
1281 break;
1282
1283 case 'f':
1284 SYMBOL_CLASS (sym) = LOC_BLOCK;
1285 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1286 add_symbol_to_list (sym, &file_symbols);
1287 break;
1288
1289 case 'F':
1290 SYMBOL_CLASS (sym) = LOC_BLOCK;
1291 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1292 add_symbol_to_list (sym, &global_symbols);
1293 break;
1294
1295 case 'G':
1296 /* For a class G (global) symbol, it appears that the
1297 value is not correct. It is necessary to search for the
1298 corresponding linker definition to find the value.
1299 These definitions appear at the end of the namelist. */
1300 i = hashname (SYMBOL_NAME (sym));
1301 SYMBOL_VALUE_CHAIN (sym) = global_sym_chain[i];
1302 global_sym_chain[i] = sym;
1303 SYMBOL_CLASS (sym) = LOC_STATIC;
1304 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1305 add_symbol_to_list (sym, &global_symbols);
1306 break;
1307
1308 /* This case is faked by a conditional above,
1309 when there is no code letter in the dbx data.
1310 Dbx data never actually contains 'l'. */
1311 case 'l':
1312 SYMBOL_CLASS (sym) = LOC_LOCAL;
1313 SYMBOL_VALUE (sym) = valu;
1314 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1315 add_symbol_to_list (sym, &local_symbols);
1316 break;
1317
1318 case 'p':
1319 /* Normally this is a parameter, a LOC_ARG. On the i960, it
1320 can also be a LOC_LOCAL_ARG depending on symbol type. */
1321 #ifndef DBX_PARM_SYMBOL_CLASS
1322 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
1323 #endif
1324 SYMBOL_CLASS (sym) = DBX_PARM_SYMBOL_CLASS (type);
1325 SYMBOL_VALUE (sym) = valu;
1326 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1327 #if 0
1328 /* This doesn't work yet. */
1329 add_param_to_type (&in_function_type, sym);
1330 #endif
1331 add_symbol_to_list (sym, &local_symbols);
1332
1333 /* If it's gcc-compiled, if it says `short', believe it. */
1334 if (processing_gcc_compilation || BELIEVE_PCC_PROMOTION)
1335 break;
1336
1337 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
1338 /* This macro is defined on machines (e.g. sparc) where
1339 we should believe the type of a PCC 'short' argument,
1340 but shouldn't believe the address (the address is
1341 the address of the corresponding int). Note that
1342 this is only different from the BELIEVE_PCC_PROMOTION
1343 case on big-endian machines.
1344
1345 My guess is that this correction, as opposed to changing
1346 the parameter to an 'int' (as done below, for PCC
1347 on most machines), is the right thing to do
1348 on all machines, but I don't want to risk breaking
1349 something that already works. On most PCC machines,
1350 the sparc problem doesn't come up because the calling
1351 function has to zero the top bytes (not knowing whether
1352 the called function wants an int or a short), so there
1353 is no practical difference between an int and a short
1354 (except perhaps what happens when the GDB user types
1355 "print short_arg = 0x10000;").
1356
1357 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
1358 actually produces the correct address (we don't need to fix it
1359 up). I made this code adapt so that it will offset the symbol
1360 if it was pointing at an int-aligned location and not
1361 otherwise. This way you can use the same gdb for 4.0.x and
1362 4.1 systems.
1363
1364 If the parameter is shorter than an int, and is integral
1365 (e.g. char, short, or unsigned equivalent), and is claimed to
1366 be passed on an integer boundary, don't believe it! Offset the
1367 parameter's address to the tail-end of that integer. */
1368
1369 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
1370 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1371 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT
1372 && 0 == SYMBOL_VALUE (sym) % TYPE_LENGTH (temptype))
1373 {
1374 SYMBOL_VALUE (sym) += TYPE_LENGTH (temptype)
1375 - TYPE_LENGTH (SYMBOL_TYPE (sym));
1376 }
1377 break;
1378
1379 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1380
1381 /* If PCC says a parameter is a short or a char,
1382 it is really an int. */
1383 temptype = lookup_fundamental_type (objfile, FT_INTEGER);
1384 if (TYPE_LENGTH (SYMBOL_TYPE (sym)) < TYPE_LENGTH (temptype)
1385 && TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_INT)
1386 {
1387 SYMBOL_TYPE (sym) = TYPE_UNSIGNED (SYMBOL_TYPE (sym))
1388 ? lookup_fundamental_type (objfile, FT_UNSIGNED_INTEGER)
1389 : temptype;
1390 }
1391 break;
1392
1393 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1394
1395 case 'P':
1396 SYMBOL_CLASS (sym) = LOC_REGPARM;
1397 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1398 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1399 add_symbol_to_list (sym, &local_symbols);
1400 break;
1401
1402 case 'r':
1403 SYMBOL_CLASS (sym) = LOC_REGISTER;
1404 SYMBOL_VALUE (sym) = STAB_REG_TO_REGNUM (valu);
1405 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1406 add_symbol_to_list (sym, &local_symbols);
1407 break;
1408
1409 case 'S':
1410 /* Static symbol at top level of file */
1411 SYMBOL_CLASS (sym) = LOC_STATIC;
1412 SYMBOL_VALUE_ADDRESS (sym) = valu;
1413 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1414 add_symbol_to_list (sym, &file_symbols);
1415 break;
1416
1417 case 't':
1418 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1419 SYMBOL_VALUE (sym) = valu;
1420 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1421 if (TYPE_NAME (SYMBOL_TYPE (sym)) == NULL)
1422 TYPE_NAME (SYMBOL_TYPE (sym)) =
1423 obsavestring (SYMBOL_NAME (sym),
1424 strlen (SYMBOL_NAME (sym)),
1425 &objfile -> symbol_obstack);
1426 /* C++ vagaries: we may have a type which is derived from
1427 a base type which did not have its name defined when the
1428 derived class was output. We fill in the derived class's
1429 base part member's name here in that case. */
1430 else if ((TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1431 || TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_UNION)
1432 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)))
1433 {
1434 int j;
1435 for (j = TYPE_N_BASECLASSES (SYMBOL_TYPE (sym)) - 1; j >= 0; j--)
1436 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) == 0)
1437 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym), j) =
1438 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym), j));
1439 }
1440
1441 add_symbol_to_list (sym, &file_symbols);
1442 break;
1443
1444 case 'T':
1445 SYMBOL_CLASS (sym) = LOC_TYPEDEF;
1446 SYMBOL_VALUE (sym) = valu;
1447 SYMBOL_NAMESPACE (sym) = STRUCT_NAMESPACE;
1448 if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0)
1449 TYPE_NAME (SYMBOL_TYPE (sym))
1450 = obconcat (&objfile -> type_obstack, "",
1451 (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_ENUM
1452 ? "enum "
1453 : (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_STRUCT
1454 ? "struct " : "union ")),
1455 SYMBOL_NAME (sym));
1456 add_symbol_to_list (sym, &file_symbols);
1457
1458 if (synonym)
1459 {
1460 register struct symbol *typedef_sym = (struct symbol *)
1461 obstack_alloc (&objfile -> type_obstack,
1462 sizeof (struct symbol));
1463 SYMBOL_NAME (typedef_sym) = SYMBOL_NAME (sym);
1464 SYMBOL_TYPE (typedef_sym) = SYMBOL_TYPE (sym);
1465
1466 SYMBOL_CLASS (typedef_sym) = LOC_TYPEDEF;
1467 SYMBOL_VALUE (typedef_sym) = valu;
1468 SYMBOL_NAMESPACE (typedef_sym) = VAR_NAMESPACE;
1469 add_symbol_to_list (typedef_sym, &file_symbols);
1470 }
1471 break;
1472
1473 case 'V':
1474 /* Static symbol of local scope */
1475 SYMBOL_CLASS (sym) = LOC_STATIC;
1476 SYMBOL_VALUE_ADDRESS (sym) = valu;
1477 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1478 add_symbol_to_list (sym, &local_symbols);
1479 break;
1480
1481 case 'v':
1482 /* Reference parameter */
1483 SYMBOL_CLASS (sym) = LOC_REF_ARG;
1484 SYMBOL_VALUE (sym) = valu;
1485 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1486 add_symbol_to_list (sym, &local_symbols);
1487 break;
1488
1489 case 'X':
1490 /* This is used by Sun FORTRAN for "function result value".
1491 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1492 that Pascal uses it too, but when I tried it Pascal used
1493 "x:3" (local symbol) instead. */
1494 SYMBOL_CLASS (sym) = LOC_LOCAL;
1495 SYMBOL_VALUE (sym) = valu;
1496 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
1497 add_symbol_to_list (sym, &local_symbols);
1498 break;
1499
1500 default:
1501 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype, symnum);
1502 }
1503 return sym;
1504 }
1505 \f
1506 /* What about types defined as forward references inside of a small lexical
1507 scope? */
1508 /* Add a type to the list of undefined types to be checked through
1509 once this file has been read in. */
1510 void
1511 add_undefined_type (type)
1512 struct type *type;
1513 {
1514 if (undef_types_length == undef_types_allocated)
1515 {
1516 undef_types_allocated *= 2;
1517 undef_types = (struct type **)
1518 xrealloc ((char *) undef_types,
1519 undef_types_allocated * sizeof (struct type *));
1520 }
1521 undef_types[undef_types_length++] = type;
1522 }
1523
1524 /* Go through each undefined type, see if it's still undefined, and fix it
1525 up if possible. We have two kinds of undefined types:
1526
1527 TYPE_CODE_ARRAY: Array whose target type wasn't defined yet.
1528 Fix: update array length using the element bounds
1529 and the target type's length.
1530 TYPE_CODE_STRUCT, TYPE_CODE_UNION: Structure whose fields were not
1531 yet defined at the time a pointer to it was made.
1532 Fix: Do a full lookup on the struct/union tag. */
1533 static void
1534 cleanup_undefined_types ()
1535 {
1536 struct type **type;
1537
1538 for (type = undef_types; type < undef_types + undef_types_length; type++) {
1539 switch (TYPE_CODE (*type)) {
1540
1541 case TYPE_CODE_STRUCT:
1542 case TYPE_CODE_UNION:
1543 case TYPE_CODE_ENUM:
1544 {
1545 /* Reasonable test to see if it's been defined since. */
1546 if (TYPE_NFIELDS (*type) == 0)
1547 {
1548 struct pending *ppt;
1549 int i;
1550 /* Name of the type, without "struct" or "union" */
1551 char *typename = TYPE_NAME (*type);
1552
1553 if (!strncmp (typename, "struct ", 7))
1554 typename += 7;
1555 if (!strncmp (typename, "union ", 6))
1556 typename += 6;
1557 if (!strncmp (typename, "enum ", 5))
1558 typename += 5;
1559
1560 for (ppt = file_symbols; ppt; ppt = ppt->next)
1561 for (i = 0; i < ppt->nsyms; i++)
1562 {
1563 struct symbol *sym = ppt->symbol[i];
1564
1565 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1566 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1567 && (TYPE_CODE (SYMBOL_TYPE (sym)) ==
1568 TYPE_CODE (*type))
1569 && !strcmp (SYMBOL_NAME (sym), typename))
1570 memcpy (*type, SYMBOL_TYPE (sym), sizeof (struct type));
1571 }
1572 }
1573 else
1574 /* It has been defined; don't mark it as a stub. */
1575 TYPE_FLAGS (*type) &= ~TYPE_FLAG_STUB;
1576 }
1577 break;
1578
1579 case TYPE_CODE_ARRAY:
1580 {
1581 struct type *range_type;
1582 int lower, upper;
1583
1584 if (TYPE_LENGTH (*type) != 0) /* Better be unknown */
1585 goto badtype;
1586 if (TYPE_NFIELDS (*type) != 1)
1587 goto badtype;
1588 range_type = TYPE_FIELD_TYPE (*type, 0);
1589 if (TYPE_CODE (range_type) != TYPE_CODE_RANGE)
1590 goto badtype;
1591
1592 /* Now recompute the length of the array type, based on its
1593 number of elements and the target type's length. */
1594 lower = TYPE_FIELD_BITPOS (range_type, 0);
1595 upper = TYPE_FIELD_BITPOS (range_type, 1);
1596 TYPE_LENGTH (*type) = (upper - lower + 1)
1597 * TYPE_LENGTH (TYPE_TARGET_TYPE (*type));
1598 }
1599 break;
1600
1601 default:
1602 badtype:
1603 error ("GDB internal error. cleanup_undefined_types with bad\
1604 type %d.", TYPE_CODE (*type));
1605 break;
1606 }
1607 }
1608 undef_types_length = 0;
1609 }
1610 \f
1611 /* Skip rest of this symbol and return an error type.
1612
1613 General notes on error recovery: error_type always skips to the
1614 end of the symbol (modulo cretinous dbx symbol name continuation).
1615 Thus code like this:
1616
1617 if (*(*pp)++ != ';')
1618 return error_type (pp);
1619
1620 is wrong because if *pp starts out pointing at '\0' (typically as the
1621 result of an earlier error), it will be incremented to point to the
1622 start of the next symbol, which might produce strange results, at least
1623 if you run off the end of the string table. Instead use
1624
1625 if (**pp != ';')
1626 return error_type (pp);
1627 ++*pp;
1628
1629 or
1630
1631 if (**pp != ';')
1632 foo = error_type (pp);
1633 else
1634 ++*pp;
1635
1636 And in case it isn't obvious, the point of all this hair is so the compiler
1637 can define new types and new syntaxes, and old versions of the
1638 debugger will be able to read the new symbol tables. */
1639
1640 struct type *
1641 error_type (pp)
1642 char **pp;
1643 {
1644 complain (&error_type_complaint, 0);
1645 while (1)
1646 {
1647 /* Skip to end of symbol. */
1648 while (**pp != '\0')
1649 (*pp)++;
1650
1651 /* Check for and handle cretinous dbx symbol name continuation! */
1652 if ((*pp)[-1] == '\\')
1653 *pp = next_symbol_text ();
1654 else
1655 break;
1656 }
1657 return builtin_type_error;
1658 }
1659 \f
1660 /* Read a dbx type reference or definition;
1661 return the type that is meant.
1662 This can be just a number, in which case it references
1663 a type already defined and placed in type_vector.
1664 Or the number can be followed by an =, in which case
1665 it means to define a new type according to the text that
1666 follows the =. */
1667
1668 struct type *
1669 read_type (pp, objfile)
1670 register char **pp;
1671 struct objfile *objfile;
1672 {
1673 register struct type *type = 0;
1674 struct type *type1;
1675 int typenums[2];
1676 int xtypenums[2];
1677
1678 /* Read type number if present. The type number may be omitted.
1679 for instance in a two-dimensional array declared with type
1680 "ar1;1;10;ar1;1;10;4". */
1681 if ((**pp >= '0' && **pp <= '9')
1682 || **pp == '(')
1683 {
1684 read_type_number (pp, typenums);
1685
1686 /* Type is not being defined here. Either it already exists,
1687 or this is a forward reference to it. dbx_alloc_type handles
1688 both cases. */
1689 if (**pp != '=')
1690 return dbx_alloc_type (typenums, objfile);
1691
1692 /* Type is being defined here. */
1693 #if 0 /* Callers aren't prepared for a NULL result! FIXME -- metin! */
1694 {
1695 struct type *tt;
1696
1697 /* if such a type already exists, this is an unnecessary duplication
1698 of the stab string, which is common in (RS/6000) xlc generated
1699 objects. In that case, simply return NULL and let the caller take
1700 care of it. */
1701
1702 tt = *dbx_lookup_type (typenums);
1703 if (tt && tt->length && tt->code)
1704 return NULL;
1705 }
1706 #endif
1707
1708 *pp += 2;
1709 }
1710 else
1711 {
1712 /* 'typenums=' not present, type is anonymous. Read and return
1713 the definition, but don't put it in the type vector. */
1714 typenums[0] = typenums[1] = -1;
1715 *pp += 1;
1716 }
1717
1718 switch ((*pp)[-1])
1719 {
1720 case 'x':
1721 {
1722 enum type_code code;
1723
1724 /* Used to index through file_symbols. */
1725 struct pending *ppt;
1726 int i;
1727
1728 /* Name including "struct", etc. */
1729 char *type_name;
1730
1731 /* Name without "struct", etc. */
1732 char *type_name_only;
1733
1734 {
1735 char *prefix;
1736 char *from, *to;
1737
1738 /* Set the type code according to the following letter. */
1739 switch ((*pp)[0])
1740 {
1741 case 's':
1742 code = TYPE_CODE_STRUCT;
1743 prefix = "struct ";
1744 break;
1745 case 'u':
1746 code = TYPE_CODE_UNION;
1747 prefix = "union ";
1748 break;
1749 case 'e':
1750 code = TYPE_CODE_ENUM;
1751 prefix = "enum ";
1752 break;
1753 default:
1754 return error_type (pp);
1755 }
1756
1757 to = type_name = (char *)
1758 obstack_alloc (&objfile -> type_obstack,
1759 (strlen (prefix) +
1760 ((char *) strchr (*pp, ':') - (*pp)) + 1));
1761
1762 /* Copy the prefix. */
1763 from = prefix;
1764 while (*to++ = *from++)
1765 ;
1766 to--;
1767
1768 type_name_only = to;
1769
1770 /* Copy the name. */
1771 from = *pp + 1;
1772 while ((*to++ = *from++) != ':')
1773 ;
1774 *--to = '\0';
1775
1776 /* Set the pointer ahead of the name which we just read. */
1777 *pp = from;
1778
1779 #if 0
1780 /* The following hack is clearly wrong, because it doesn't
1781 check whether we are in a baseclass. I tried to reproduce
1782 the case that it is trying to fix, but I couldn't get
1783 g++ to put out a cross reference to a basetype. Perhaps
1784 it doesn't do it anymore. */
1785 /* Note: for C++, the cross reference may be to a base type which
1786 has not yet been seen. In this case, we skip to the comma,
1787 which will mark the end of the base class name. (The ':'
1788 at the end of the base class name will be skipped as well.)
1789 But sometimes (ie. when the cross ref is the last thing on
1790 the line) there will be no ','. */
1791 from = (char *) strchr (*pp, ',');
1792 if (from)
1793 *pp = from;
1794 #endif /* 0 */
1795 }
1796
1797 /* Now check to see whether the type has already been declared. */
1798 /* This is necessary at least in the case where the
1799 program says something like
1800 struct foo bar[5];
1801 The compiler puts out a cross-reference; we better find
1802 set the length of the structure correctly so we can
1803 set the length of the array. */
1804 for (ppt = file_symbols; ppt; ppt = ppt->next)
1805 for (i = 0; i < ppt->nsyms; i++)
1806 {
1807 struct symbol *sym = ppt->symbol[i];
1808
1809 if (SYMBOL_CLASS (sym) == LOC_TYPEDEF
1810 && SYMBOL_NAMESPACE (sym) == STRUCT_NAMESPACE
1811 && (TYPE_CODE (SYMBOL_TYPE (sym)) == code)
1812 && !strcmp (SYMBOL_NAME (sym), type_name_only))
1813 {
1814 obstack_free (&objfile -> type_obstack, type_name);
1815 type = SYMBOL_TYPE (sym);
1816 return type;
1817 }
1818 }
1819
1820 /* Didn't find the type to which this refers, so we must
1821 be dealing with a forward reference. Allocate a type
1822 structure for it, and keep track of it so we can
1823 fill in the rest of the fields when we get the full
1824 type. */
1825 type = dbx_alloc_type (typenums, objfile);
1826 TYPE_CODE (type) = code;
1827 TYPE_NAME (type) = type_name;
1828 INIT_CPLUS_SPECIFIC(type);
1829 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1830
1831 add_undefined_type (type);
1832 return type;
1833 }
1834
1835 case '-': /* RS/6000 built-in type */
1836 (*pp)--;
1837 type = builtin_type (pp); /* (in xcoffread.c) */
1838 goto after_digits;
1839
1840 case '0':
1841 case '1':
1842 case '2':
1843 case '3':
1844 case '4':
1845 case '5':
1846 case '6':
1847 case '7':
1848 case '8':
1849 case '9':
1850 case '(':
1851 (*pp)--;
1852 read_type_number (pp, xtypenums);
1853 type = *dbx_lookup_type (xtypenums);
1854 /* fall through */
1855
1856 after_digits:
1857 if (type == 0)
1858 type = lookup_fundamental_type (objfile, FT_VOID);
1859 if (typenums[0] != -1)
1860 *dbx_lookup_type (typenums) = type;
1861 break;
1862
1863 case '*':
1864 type1 = read_type (pp, objfile);
1865 /* FIXME -- we should be doing smash_to_XXX types here. */
1866 #if 0
1867 /* postponed type decoration should be allowed. */
1868 if (typenums[1] > 0 && typenums[1] < type_vector_length &&
1869 (type = type_vector[typenums[1]])) {
1870 smash_to_pointer_type (type, type1);
1871 break;
1872 }
1873 #endif
1874 type = lookup_pointer_type (type1);
1875 if (typenums[0] != -1)
1876 *dbx_lookup_type (typenums) = type;
1877 break;
1878
1879 case '@':
1880 {
1881 struct type *domain = read_type (pp, objfile);
1882 struct type *memtype;
1883
1884 if (**pp != ',')
1885 /* Invalid member type data format. */
1886 return error_type (pp);
1887 ++*pp;
1888
1889 memtype = read_type (pp, objfile);
1890 type = dbx_alloc_type (typenums, objfile);
1891 smash_to_member_type (type, domain, memtype);
1892 }
1893 break;
1894
1895 case '#':
1896 if ((*pp)[0] == '#')
1897 {
1898 /* We'll get the parameter types from the name. */
1899 struct type *return_type;
1900
1901 *pp += 1;
1902 return_type = read_type (pp, objfile);
1903 if (*(*pp)++ != ';')
1904 complain (&invalid_member_complaint, (char *) symnum);
1905 type = allocate_stub_method (return_type);
1906 if (typenums[0] != -1)
1907 *dbx_lookup_type (typenums) = type;
1908 }
1909 else
1910 {
1911 struct type *domain = read_type (pp, objfile);
1912 struct type *return_type;
1913 struct type **args;
1914
1915 if (*(*pp)++ != ',')
1916 error ("invalid member type data format, at symtab pos %d.",
1917 symnum);
1918
1919 return_type = read_type (pp, objfile);
1920 args = read_args (pp, ';', objfile);
1921 type = dbx_alloc_type (typenums, objfile);
1922 smash_to_method_type (type, domain, return_type, args);
1923 }
1924 break;
1925
1926 case '&':
1927 type1 = read_type (pp, objfile);
1928 type = lookup_reference_type (type1);
1929 if (typenums[0] != -1)
1930 *dbx_lookup_type (typenums) = type;
1931 break;
1932
1933 case 'f':
1934 type1 = read_type (pp, objfile);
1935 type = lookup_function_type (type1);
1936 if (typenums[0] != -1)
1937 *dbx_lookup_type (typenums) = type;
1938 break;
1939
1940 case 'r':
1941 type = read_range_type (pp, typenums, objfile);
1942 if (typenums[0] != -1)
1943 *dbx_lookup_type (typenums) = type;
1944 break;
1945
1946 case 'e':
1947 type = dbx_alloc_type (typenums, objfile);
1948 type = read_enum_type (pp, type, objfile);
1949 *dbx_lookup_type (typenums) = type;
1950 break;
1951
1952 case 's':
1953 type = dbx_alloc_type (typenums, objfile);
1954 if (!TYPE_NAME (type))
1955 TYPE_NAME (type) = type_synonym_name;
1956 type_synonym_name = 0;
1957 type = read_struct_type (pp, type, objfile);
1958 break;
1959
1960 case 'u':
1961 type = dbx_alloc_type (typenums, objfile);
1962 if (!TYPE_NAME (type))
1963 TYPE_NAME (type) = type_synonym_name;
1964 type_synonym_name = 0;
1965 type = read_struct_type (pp, type, objfile);
1966 TYPE_CODE (type) = TYPE_CODE_UNION;
1967 break;
1968
1969 case 'a':
1970 if (**pp != 'r')
1971 return error_type (pp);
1972 ++*pp;
1973
1974 type = dbx_alloc_type (typenums, objfile);
1975 type = read_array_type (pp, type, objfile);
1976 break;
1977
1978 default:
1979 --*pp; /* Go back to the symbol in error */
1980 /* Particularly important if it was \0! */
1981 return error_type (pp);
1982 }
1983
1984 if (type == 0)
1985 abort ();
1986
1987 #if 0
1988 /* If this is an overriding temporary alteration for a header file's
1989 contents, and this type number is unknown in the global definition,
1990 put this type into the global definition at this type number. */
1991 if (header_file_prev_index >= 0)
1992 {
1993 register struct type **tp
1994 = explicit_lookup_type (header_file_prev_index, typenums[1]);
1995 if (*tp == 0)
1996 *tp = type;
1997 }
1998 #endif
1999 return type;
2000 }
2001 \f
2002 /* This page contains subroutines of read_type. */
2003
2004 /* Read the description of a structure (or union type)
2005 and return an object describing the type. */
2006
2007 static struct type *
2008 read_struct_type (pp, type, objfile)
2009 char **pp;
2010 register struct type *type;
2011 struct objfile *objfile;
2012 {
2013 /* Total number of methods defined in this class.
2014 If the class defines two `f' methods, and one `g' method,
2015 then this will have the value 3. */
2016 int total_length = 0;
2017
2018 struct nextfield
2019 {
2020 struct nextfield *next;
2021 int visibility; /* 0=public, 1=protected, 2=public */
2022 struct field field;
2023 };
2024
2025 struct next_fnfield
2026 {
2027 struct next_fnfield *next;
2028 struct fn_field fn_field;
2029 };
2030
2031 struct next_fnfieldlist
2032 {
2033 struct next_fnfieldlist *next;
2034 struct fn_fieldlist fn_fieldlist;
2035 };
2036
2037 register struct nextfield *list = 0;
2038 struct nextfield *new;
2039 register char *p;
2040 int nfields = 0;
2041 int non_public_fields = 0;
2042 register int n;
2043
2044 register struct next_fnfieldlist *mainlist = 0;
2045 int nfn_fields = 0;
2046
2047 TYPE_CODE (type) = TYPE_CODE_STRUCT;
2048 INIT_CPLUS_SPECIFIC(type);
2049
2050 /* First comes the total size in bytes. */
2051
2052 TYPE_LENGTH (type) = read_number (pp, 0);
2053
2054 /* C++: Now, if the class is a derived class, then the next character
2055 will be a '!', followed by the number of base classes derived from.
2056 Each element in the list contains visibility information,
2057 the offset of this base class in the derived structure,
2058 and then the base type. */
2059 if (**pp == '!')
2060 {
2061 int i, n_baseclasses, offset;
2062 struct type *baseclass;
2063 int via_public;
2064
2065 /* Nonzero if it is a virtual baseclass, i.e.,
2066
2067 struct A{};
2068 struct B{};
2069 struct C : public B, public virtual A {};
2070
2071 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
2072 2.0 language feature. */
2073 int via_virtual;
2074
2075 *pp += 1;
2076
2077 ALLOCATE_CPLUS_STRUCT_TYPE(type);
2078
2079 n_baseclasses = read_number (pp, ',');
2080 TYPE_FIELD_VIRTUAL_BITS (type) =
2081 (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2082 B_BYTES (n_baseclasses));
2083 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
2084
2085 for (i = 0; i < n_baseclasses; i++)
2086 {
2087 if (**pp == '\\')
2088 *pp = next_symbol_text ();
2089
2090 switch (**pp)
2091 {
2092 case '0':
2093 via_virtual = 0;
2094 break;
2095 case '1':
2096 via_virtual = 1;
2097 break;
2098 default:
2099 /* Bad visibility format. */
2100 return error_type (pp);
2101 }
2102 ++*pp;
2103
2104 switch (**pp)
2105 {
2106 case '0':
2107 via_public = 0;
2108 non_public_fields++;
2109 break;
2110 case '2':
2111 via_public = 2;
2112 break;
2113 default:
2114 /* Bad visibility format. */
2115 return error_type (pp);
2116 }
2117 if (via_virtual)
2118 SET_TYPE_FIELD_VIRTUAL (type, i);
2119 ++*pp;
2120
2121 /* Offset of the portion of the object corresponding to
2122 this baseclass. Always zero in the absence of
2123 multiple inheritance. */
2124 offset = read_number (pp, ',');
2125 baseclass = read_type (pp, objfile);
2126 *pp += 1; /* skip trailing ';' */
2127
2128 /* Make this baseclass visible for structure-printing purposes. */
2129 new = (struct nextfield *) alloca (sizeof (struct nextfield));
2130 new->next = list;
2131 list = new;
2132 list->visibility = via_public;
2133 list->field.type = baseclass;
2134 list->field.name = type_name_no_tag (baseclass);
2135 list->field.bitpos = offset;
2136 list->field.bitsize = 0; /* this should be an unpacked field! */
2137 nfields++;
2138 }
2139 TYPE_N_BASECLASSES (type) = n_baseclasses;
2140 }
2141
2142 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
2143 At the end, we see a semicolon instead of a field.
2144
2145 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
2146 a static field.
2147
2148 The `?' is a placeholder for one of '/2' (public visibility),
2149 '/1' (protected visibility), '/0' (private visibility), or nothing
2150 (C style symbol table, public visibility). */
2151
2152 /* We better set p right now, in case there are no fields at all... */
2153 p = *pp;
2154
2155 while (**pp != ';')
2156 {
2157 /* Check for and handle cretinous dbx symbol name continuation! */
2158 if (**pp == '\\') *pp = next_symbol_text ();
2159
2160 /* Get space to record the next field's data. */
2161 new = (struct nextfield *) alloca (sizeof (struct nextfield));
2162 new->next = list;
2163 list = new;
2164
2165 /* Get the field name. */
2166 p = *pp;
2167 if (*p == CPLUS_MARKER)
2168 {
2169 /* Special GNU C++ name. */
2170 if (*++p == 'v')
2171 {
2172 const char *prefix;
2173 char *name = 0;
2174 struct type *context;
2175
2176 switch (*++p)
2177 {
2178 case 'f':
2179 prefix = vptr_name;
2180 break;
2181 case 'b':
2182 prefix = vb_name;
2183 break;
2184 default:
2185 complain (&invalid_cpp_abbrev_complaint, *pp);
2186 prefix = "INVALID_C++_ABBREV";
2187 break;
2188 }
2189 *pp = p + 1;
2190 context = read_type (pp, objfile);
2191 name = type_name_no_tag (context);
2192 if (name == 0)
2193 {
2194 complain (&invalid_cpp_type_complaint, (char *) symnum);
2195 TYPE_NAME (context) = name;
2196 }
2197 list->field.name = obconcat (&objfile -> type_obstack,
2198 prefix, name, "");
2199 p = ++(*pp);
2200 if (p[-1] != ':')
2201 complain (&invalid_cpp_abbrev_complaint, *pp);
2202 list->field.type = read_type (pp, objfile);
2203 (*pp)++; /* Skip the comma. */
2204 list->field.bitpos = read_number (pp, ';');
2205 /* This field is unpacked. */
2206 list->field.bitsize = 0;
2207 list->visibility = 0; /* private */
2208 non_public_fields++;
2209 }
2210 /* GNU C++ anonymous type. */
2211 else if (*p == '_')
2212 break;
2213 else
2214 complain (&invalid_cpp_abbrev_complaint, *pp);
2215
2216 nfields++;
2217 continue;
2218 }
2219
2220 while (*p != ':') p++;
2221 list->field.name = obsavestring (*pp, p - *pp,
2222 &objfile -> type_obstack);
2223
2224 /* C++: Check to see if we have hit the methods yet. */
2225 if (p[1] == ':')
2226 break;
2227
2228 *pp = p + 1;
2229
2230 /* This means we have a visibility for a field coming. */
2231 if (**pp == '/')
2232 {
2233 switch (*++*pp)
2234 {
2235 case '0':
2236 list->visibility = 0; /* private */
2237 non_public_fields++;
2238 *pp += 1;
2239 break;
2240
2241 case '1':
2242 list->visibility = 1; /* protected */
2243 non_public_fields++;
2244 *pp += 1;
2245 break;
2246
2247 case '2':
2248 list->visibility = 2; /* public */
2249 *pp += 1;
2250 break;
2251 }
2252 }
2253 else /* normal dbx-style format. */
2254 list->visibility = 2; /* public */
2255
2256 list->field.type = read_type (pp, objfile);
2257 if (**pp == ':')
2258 {
2259 /* Static class member. */
2260 list->field.bitpos = (long)-1;
2261 p = ++(*pp);
2262 while (*p != ';') p++;
2263 list->field.bitsize = (long) savestring (*pp, p - *pp);
2264 *pp = p + 1;
2265 nfields++;
2266 continue;
2267 }
2268 else if (**pp != ',')
2269 /* Bad structure-type format. */
2270 return error_type (pp);
2271
2272 (*pp)++; /* Skip the comma. */
2273 list->field.bitpos = read_number (pp, ',');
2274 list->field.bitsize = read_number (pp, ';');
2275
2276 #if 0
2277 /* FIXME-tiemann: Can't the compiler put out something which
2278 lets us distinguish these? (or maybe just not put out anything
2279 for the field). What is the story here? What does the compiler
2280 really do? Also, patch gdb.texinfo for this case; I document
2281 it as a possible problem there. Search for "DBX-style". */
2282
2283 /* This is wrong because this is identical to the symbols
2284 produced for GCC 0-size arrays. For example:
2285 typedef union {
2286 int num;
2287 char str[0];
2288 } foo;
2289 The code which dumped core in such circumstances should be
2290 fixed not to dump core. */
2291
2292 /* g++ -g0 can put out bitpos & bitsize zero for a static
2293 field. This does not give us any way of getting its
2294 class, so we can't know its name. But we can just
2295 ignore the field so we don't dump core and other nasty
2296 stuff. */
2297 if (list->field.bitpos == 0
2298 && list->field.bitsize == 0)
2299 {
2300 complain (&dbx_class_complaint, 0);
2301 /* Ignore this field. */
2302 list = list->next;
2303 }
2304 else
2305 #endif /* 0 */
2306 {
2307 /* Detect an unpacked field and mark it as such.
2308 dbx gives a bit size for all fields.
2309 Note that forward refs cannot be packed,
2310 and treat enums as if they had the width of ints. */
2311 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
2312 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
2313 list->field.bitsize = 0;
2314 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
2315 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
2316 && (list->field.bitsize
2317 == 8 * TYPE_LENGTH (lookup_fundamental_type (objfile, FT_INTEGER)))
2318 )
2319 )
2320 &&
2321 list->field.bitpos % 8 == 0)
2322 list->field.bitsize = 0;
2323 nfields++;
2324 }
2325 }
2326
2327 if (p[1] == ':')
2328 /* chill the list of fields: the last entry (at the head)
2329 is a partially constructed entry which we now scrub. */
2330 list = list->next;
2331
2332 /* Now create the vector of fields, and record how big it is.
2333 We need this info to record proper virtual function table information
2334 for this class's virtual functions. */
2335
2336 TYPE_NFIELDS (type) = nfields;
2337 TYPE_FIELDS (type) = (struct field *)
2338 obstack_alloc (&objfile -> type_obstack, sizeof (struct field) * nfields);
2339
2340 if (non_public_fields)
2341 {
2342 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2343
2344 TYPE_FIELD_PRIVATE_BITS (type) =
2345 (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2346 B_BYTES (nfields));
2347 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2348
2349 TYPE_FIELD_PROTECTED_BITS (type) =
2350 (B_TYPE *) obstack_alloc (&objfile -> type_obstack,
2351 B_BYTES (nfields));
2352 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2353 }
2354
2355 /* Copy the saved-up fields into the field vector. */
2356
2357 for (n = nfields; list; list = list->next)
2358 {
2359 n -= 1;
2360 TYPE_FIELD (type, n) = list->field;
2361 if (list->visibility == 0)
2362 SET_TYPE_FIELD_PRIVATE (type, n);
2363 else if (list->visibility == 1)
2364 SET_TYPE_FIELD_PROTECTED (type, n);
2365 }
2366
2367 /* Now come the method fields, as NAME::methods
2368 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2369 At the end, we see a semicolon instead of a field.
2370
2371 For the case of overloaded operators, the format is
2372 op$::*.methods, where $ is the CPLUS_MARKER (usually '$'),
2373 `*' holds the place for an operator name (such as `+=')
2374 and `.' marks the end of the operator name. */
2375 if (p[1] == ':')
2376 {
2377 /* Now, read in the methods. To simplify matters, we
2378 "unread" the name that has been read, so that we can
2379 start from the top. */
2380
2381 ALLOCATE_CPLUS_STRUCT_TYPE (type);
2382 /* For each list of method lists... */
2383 do
2384 {
2385 int i;
2386 struct next_fnfield *sublist = 0;
2387 struct type *look_ahead_type = NULL;
2388 int length = 0;
2389 struct next_fnfieldlist *new_mainlist =
2390 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
2391 char *main_fn_name;
2392
2393 p = *pp;
2394
2395 /* read in the name. */
2396 while (*p != ':') p++;
2397 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
2398 {
2399 /* This is a completely wierd case. In order to stuff in the
2400 names that might contain colons (the usual name delimiter),
2401 Mike Tiemann defined a different name format which is
2402 signalled if the identifier is "op$". In that case, the
2403 format is "op$::XXXX." where XXXX is the name. This is
2404 used for names like "+" or "=". YUUUUUUUK! FIXME! */
2405 /* This lets the user type "break operator+".
2406 We could just put in "+" as the name, but that wouldn't
2407 work for "*". */
2408 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2409 char *o = opname + 3;
2410
2411 /* Skip past '::'. */
2412 *pp = p + 2;
2413 if (**pp == '\\') *pp = next_symbol_text ();
2414 p = *pp;
2415 while (*p != '.')
2416 *o++ = *p++;
2417 main_fn_name = savestring (opname, o - opname);
2418 /* Skip past '.' */
2419 *pp = p + 1;
2420 }
2421 else
2422 {
2423 main_fn_name = savestring (*pp, p - *pp);
2424 /* Skip past '::'. */
2425 *pp = p + 2;
2426 }
2427 new_mainlist->fn_fieldlist.name = main_fn_name;
2428
2429 do
2430 {
2431 struct next_fnfield *new_sublist =
2432 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
2433
2434 /* Check for and handle cretinous dbx symbol name continuation! */
2435 if (look_ahead_type == NULL) /* Normal case. */
2436 {
2437 if (**pp == '\\') *pp = next_symbol_text ();
2438
2439 new_sublist->fn_field.type = read_type (pp, objfile);
2440 if (**pp != ':')
2441 /* Invalid symtab info for method. */
2442 return error_type (pp);
2443 }
2444 else
2445 { /* g++ version 1 kludge */
2446 new_sublist->fn_field.type = look_ahead_type;
2447 look_ahead_type = NULL;
2448 }
2449
2450 *pp += 1;
2451 p = *pp;
2452 while (*p != ';') p++;
2453
2454 /* If this is just a stub, then we don't have the
2455 real name here. */
2456 if (TYPE_FLAGS (new_sublist->fn_field.type) & TYPE_FLAG_STUB)
2457 new_sublist->fn_field.is_stub = 1;
2458 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
2459 *pp = p + 1;
2460
2461 /* Set this method's visibility fields. */
2462 switch (*(*pp)++ - '0')
2463 {
2464 case 0:
2465 new_sublist->fn_field.is_private = 1;
2466 break;
2467 case 1:
2468 new_sublist->fn_field.is_protected = 1;
2469 break;
2470 }
2471
2472 if (**pp == '\\') *pp = next_symbol_text ();
2473 switch (**pp)
2474 {
2475 case 'A': /* Normal functions. */
2476 new_sublist->fn_field.is_const = 0;
2477 new_sublist->fn_field.is_volatile = 0;
2478 (*pp)++;
2479 break;
2480 case 'B': /* `const' member functions. */
2481 new_sublist->fn_field.is_const = 1;
2482 new_sublist->fn_field.is_volatile = 0;
2483 (*pp)++;
2484 break;
2485 case 'C': /* `volatile' member function. */
2486 new_sublist->fn_field.is_const = 0;
2487 new_sublist->fn_field.is_volatile = 1;
2488 (*pp)++;
2489 break;
2490 case 'D': /* `const volatile' member function. */
2491 new_sublist->fn_field.is_const = 1;
2492 new_sublist->fn_field.is_volatile = 1;
2493 (*pp)++;
2494 break;
2495 case '*': /* File compiled with g++ version 1 -- no info */
2496 case '?':
2497 case '.':
2498 break;
2499 default:
2500 complain (&const_vol_complaint, (char *) (long) **pp);
2501 break;
2502 }
2503
2504 switch (*(*pp)++)
2505 {
2506 case '*':
2507 /* virtual member function, followed by index. */
2508 /* The sign bit is set to distinguish pointers-to-methods
2509 from virtual function indicies. Since the array is
2510 in words, the quantity must be shifted left by 1
2511 on 16 bit machine, and by 2 on 32 bit machine, forcing
2512 the sign bit out, and usable as a valid index into
2513 the array. Remove the sign bit here. */
2514 new_sublist->fn_field.voffset =
2515 (0x7fffffff & read_number (pp, ';')) + 2;
2516
2517 if (**pp == '\\') *pp = next_symbol_text ();
2518
2519 if (**pp == ';' || **pp == '\0')
2520 /* Must be g++ version 1. */
2521 new_sublist->fn_field.fcontext = 0;
2522 else
2523 {
2524 /* Figure out from whence this virtual function came.
2525 It may belong to virtual function table of
2526 one of its baseclasses. */
2527 look_ahead_type = read_type (pp, objfile);
2528 if (**pp == ':')
2529 { /* g++ version 1 overloaded methods. */ }
2530 else
2531 {
2532 new_sublist->fn_field.fcontext = look_ahead_type;
2533 if (**pp != ';')
2534 return error_type (pp);
2535 else
2536 ++*pp;
2537 look_ahead_type = NULL;
2538 }
2539 }
2540 break;
2541
2542 case '?':
2543 /* static member function. */
2544 new_sublist->fn_field.voffset = VOFFSET_STATIC;
2545 if (strncmp (new_sublist->fn_field.physname,
2546 main_fn_name, strlen (main_fn_name)))
2547 new_sublist->fn_field.is_stub = 1;
2548 break;
2549
2550 default:
2551 /* error */
2552 complain (&member_fn_complaint, (char *) (long) (*pp)[-1]);
2553 /* Fall through into normal member function. */
2554
2555 case '.':
2556 /* normal member function. */
2557 new_sublist->fn_field.voffset = 0;
2558 new_sublist->fn_field.fcontext = 0;
2559 break;
2560 }
2561
2562 new_sublist->next = sublist;
2563 sublist = new_sublist;
2564 length++;
2565 if (**pp == '\\') *pp = next_symbol_text ();
2566 }
2567 while (**pp != ';' && **pp != '\0');
2568
2569 *pp += 1;
2570
2571 new_mainlist->fn_fieldlist.fn_fields =
2572 (struct fn_field *) obstack_alloc (&objfile -> type_obstack,
2573 sizeof (struct fn_field) * length);
2574 for (i = length; (i--, sublist); sublist = sublist->next)
2575 new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
2576
2577 new_mainlist->fn_fieldlist.length = length;
2578 new_mainlist->next = mainlist;
2579 mainlist = new_mainlist;
2580 nfn_fields++;
2581 total_length += length;
2582 if (**pp == '\\') *pp = next_symbol_text ();
2583 }
2584 while (**pp != ';');
2585 }
2586
2587 *pp += 1;
2588
2589
2590 if (nfn_fields)
2591 {
2592 TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *)
2593 obstack_alloc (&objfile -> type_obstack,
2594 sizeof (struct fn_fieldlist) * nfn_fields);
2595 TYPE_NFN_FIELDS (type) = nfn_fields;
2596 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2597 }
2598
2599 {
2600 int i;
2601 for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
2602 TYPE_NFN_FIELDS_TOTAL (type) +=
2603 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
2604 }
2605
2606 for (n = nfn_fields; mainlist; mainlist = mainlist->next) {
2607 --n; /* Circumvent Sun3 compiler bug */
2608 TYPE_FN_FIELDLISTS (type)[n] = mainlist->fn_fieldlist;
2609 }
2610
2611 if (**pp == '~')
2612 {
2613 *pp += 1;
2614
2615 if (**pp == '=' || **pp == '+' || **pp == '-')
2616 {
2617 /* Obsolete flags that used to indicate the presence
2618 of constructors and/or destructors. */
2619 *pp += 1;
2620 }
2621
2622 /* Read either a '%' or the final ';'. */
2623 if (*(*pp)++ == '%')
2624 {
2625 /* We'd like to be able to derive the vtable pointer field
2626 from the type information, but when it's inherited, that's
2627 hard. A reason it's hard is because we may read in the
2628 info about a derived class before we read in info about
2629 the base class that provides the vtable pointer field.
2630 Once the base info has been read, we could fill in the info
2631 for the derived classes, but for the fact that by then,
2632 we don't remember who needs what. */
2633
2634 int predicted_fieldno = -1;
2635
2636 /* Now we must record the virtual function table pointer's
2637 field information. */
2638
2639 struct type *t;
2640 int i;
2641
2642
2643 #if 0
2644 {
2645 /* In version 2, we derive the vfield ourselves. */
2646 for (n = 0; n < nfields; n++)
2647 {
2648 if (! strncmp (TYPE_FIELD_NAME (type, n), vptr_name,
2649 sizeof (vptr_name) -1))
2650 {
2651 predicted_fieldno = n;
2652 break;
2653 }
2654 }
2655 if (predicted_fieldno < 0)
2656 for (n = 0; n < TYPE_N_BASECLASSES (type); n++)
2657 if (! TYPE_FIELD_VIRTUAL (type, n)
2658 && TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n)) >= 0)
2659 {
2660 predicted_fieldno = TYPE_VPTR_FIELDNO (TYPE_BASECLASS (type, n));
2661 break;
2662 }
2663 }
2664 #endif
2665
2666 t = read_type (pp, objfile);
2667 p = (*pp)++;
2668 while (*p != '\0' && *p != ';')
2669 p++;
2670 if (*p == '\0')
2671 /* Premature end of symbol. */
2672 return error_type (pp);
2673
2674 TYPE_VPTR_BASETYPE (type) = t;
2675 if (type == t)
2676 {
2677 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
2678 {
2679 /* FIXME-tiemann: what's this? */
2680 #if 0
2681 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
2682 #else
2683 error_type (pp);
2684 #endif
2685 }
2686 else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
2687 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2688 sizeof (vptr_name) -1))
2689 {
2690 TYPE_VPTR_FIELDNO (type) = i;
2691 break;
2692 }
2693 if (i < 0)
2694 /* Virtual function table field not found. */
2695 return error_type (pp);
2696 }
2697 else
2698 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2699
2700 #if 0
2701 if (TYPE_VPTR_FIELDNO (type) != predicted_fieldno)
2702 error ("TYPE_VPTR_FIELDNO miscalculated");
2703 #endif
2704
2705 *pp = p + 1;
2706 }
2707 }
2708
2709 return type;
2710 }
2711
2712 /* Read a definition of an array type,
2713 and create and return a suitable type object.
2714 Also creates a range type which represents the bounds of that
2715 array. */
2716 static struct type *
2717 read_array_type (pp, type, objfile)
2718 register char **pp;
2719 register struct type *type;
2720 struct objfile *objfile;
2721 {
2722 struct type *index_type, *element_type, *range_type;
2723 int lower, upper;
2724 int adjustable = 0;
2725
2726 /* Format of an array type:
2727 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2728 to handle this.
2729
2730 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2731 for these, produce a type like float[][]. */
2732
2733 index_type = read_type (pp, objfile);
2734 if (**pp != ';')
2735 /* Improper format of array type decl. */
2736 return error_type (pp);
2737 ++*pp;
2738
2739 if (!(**pp >= '0' && **pp <= '9'))
2740 {
2741 *pp += 1;
2742 adjustable = 1;
2743 }
2744 lower = read_number (pp, ';');
2745
2746 if (!(**pp >= '0' && **pp <= '9'))
2747 {
2748 *pp += 1;
2749 adjustable = 1;
2750 }
2751 upper = read_number (pp, ';');
2752
2753 element_type = read_type (pp, objfile);
2754
2755 if (adjustable)
2756 {
2757 lower = 0;
2758 upper = -1;
2759 }
2760
2761 {
2762 /* Create range type. */
2763 range_type = (struct type *)
2764 obstack_alloc (&objfile -> type_obstack, sizeof (struct type));
2765 bzero (range_type, sizeof (struct type));
2766 TYPE_OBJFILE (range_type) = objfile;
2767 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
2768 TYPE_TARGET_TYPE (range_type) = index_type;
2769
2770 /* This should never be needed. */
2771 TYPE_LENGTH (range_type) = sizeof (int);
2772
2773 TYPE_NFIELDS (range_type) = 2;
2774 TYPE_FIELDS (range_type) =
2775 (struct field *) obstack_alloc (&objfile -> type_obstack,
2776 2 * sizeof (struct field));
2777 TYPE_FIELD_BITPOS (range_type, 0) = lower;
2778 TYPE_FIELD_BITPOS (range_type, 1) = upper;
2779 }
2780
2781 TYPE_CODE (type) = TYPE_CODE_ARRAY;
2782 TYPE_TARGET_TYPE (type) = element_type;
2783 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
2784 TYPE_NFIELDS (type) = 1;
2785 TYPE_FIELDS (type) =
2786 (struct field *) obstack_alloc (&objfile -> type_obstack,
2787 sizeof (struct field));
2788 TYPE_FIELD_TYPE (type, 0) = range_type;
2789
2790 /* If we have an array whose element type is not yet known, but whose
2791 bounds *are* known, record it to be adjusted at the end of the file. */
2792 if (TYPE_LENGTH (element_type) == 0 && !adjustable)
2793 add_undefined_type (type);
2794
2795 return type;
2796 }
2797
2798
2799 /* Read a definition of an enumeration type,
2800 and create and return a suitable type object.
2801 Also defines the symbols that represent the values of the type. */
2802
2803 static struct type *
2804 read_enum_type (pp, type, objfile)
2805 register char **pp;
2806 register struct type *type;
2807 struct objfile *objfile;
2808 {
2809 register char *p;
2810 char *name;
2811 register long n;
2812 register struct symbol *sym;
2813 int nsyms = 0;
2814 struct pending **symlist;
2815 struct pending *osyms, *syms;
2816 int o_nsyms;
2817
2818 if (within_function)
2819 symlist = &local_symbols;
2820 else
2821 symlist = &file_symbols;
2822 osyms = *symlist;
2823 o_nsyms = osyms ? osyms->nsyms : 0;
2824
2825 /* Read the value-names and their values.
2826 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2827 A semicolon or comma instead of a NAME means the end. */
2828 while (**pp && **pp != ';' && **pp != ',')
2829 {
2830 /* Check for and handle cretinous dbx symbol name continuation! */
2831 if (**pp == '\\') *pp = next_symbol_text ();
2832
2833 p = *pp;
2834 while (*p != ':') p++;
2835 name = obsavestring (*pp, p - *pp, &objfile -> symbol_obstack);
2836 *pp = p + 1;
2837 n = read_number (pp, ',');
2838
2839 sym = (struct symbol *) obstack_alloc (&objfile -> symbol_obstack, sizeof (struct symbol));
2840 bzero (sym, sizeof (struct symbol));
2841 SYMBOL_NAME (sym) = name;
2842 SYMBOL_CLASS (sym) = LOC_CONST;
2843 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2844 SYMBOL_VALUE (sym) = n;
2845 add_symbol_to_list (sym, symlist);
2846 nsyms++;
2847 }
2848
2849 if (**pp == ';')
2850 (*pp)++; /* Skip the semicolon. */
2851
2852 /* Now fill in the fields of the type-structure. */
2853
2854 TYPE_LENGTH (type) = sizeof (int);
2855 TYPE_CODE (type) = TYPE_CODE_ENUM;
2856 TYPE_NFIELDS (type) = nsyms;
2857 TYPE_FIELDS (type) = (struct field *)
2858 obstack_alloc (&objfile -> type_obstack,
2859 sizeof (struct field) * nsyms);
2860
2861 /* Find the symbols for the values and put them into the type.
2862 The symbols can be found in the symlist that we put them on
2863 to cause them to be defined. osyms contains the old value
2864 of that symlist; everything up to there was defined by us. */
2865 /* Note that we preserve the order of the enum constants, so
2866 that in something like "enum {FOO, LAST_THING=FOO}" we print
2867 FOO, not LAST_THING. */
2868
2869 for (syms = *symlist, n = 0; syms; syms = syms->next)
2870 {
2871 int j = 0;
2872 if (syms == osyms)
2873 j = o_nsyms;
2874 for (; j < syms->nsyms; j++,n++)
2875 {
2876 struct symbol *xsym = syms->symbol[j];
2877 SYMBOL_TYPE (xsym) = type;
2878 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2879 TYPE_FIELD_VALUE (type, n) = 0;
2880 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2881 TYPE_FIELD_BITSIZE (type, n) = 0;
2882 }
2883 if (syms == osyms)
2884 break;
2885 }
2886
2887 #if 0
2888 /* This screws up perfectly good C programs with enums. FIXME. */
2889 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2890 if(TYPE_NFIELDS(type) == 2 &&
2891 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2892 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2893 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2894 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2895 TYPE_CODE(type) = TYPE_CODE_BOOL;
2896 #endif
2897
2898 return type;
2899 }
2900
2901 /* Read a number from the string pointed to by *PP.
2902 The value of *PP is advanced over the number.
2903 If END is nonzero, the character that ends the
2904 number must match END, or an error happens;
2905 and that character is skipped if it does match.
2906 If END is zero, *PP is left pointing to that character.
2907
2908 If the number fits in a long, set *VALUE and set *BITS to 0.
2909 If not, set *BITS to be the number of bits in the number.
2910
2911 If encounter garbage, set *BITS to -1. */
2912
2913 static void
2914 read_huge_number (pp, end, valu, bits)
2915 char **pp;
2916 int end;
2917 long *valu;
2918 int *bits;
2919 {
2920 char *p = *pp;
2921 int sign = 1;
2922 long n = 0;
2923 int radix = 10;
2924 char overflow = 0;
2925 int nbits = 0;
2926 int c;
2927 long upper_limit;
2928
2929 if (*p == '-')
2930 {
2931 sign = -1;
2932 p++;
2933 }
2934
2935 /* Leading zero means octal. GCC uses this to output values larger
2936 than an int (because that would be hard in decimal). */
2937 if (*p == '0')
2938 {
2939 radix = 8;
2940 p++;
2941 }
2942
2943 upper_limit = LONG_MAX / radix;
2944 while ((c = *p++) >= '0' && c <= ('0' + radix))
2945 {
2946 if (n <= upper_limit)
2947 {
2948 n *= radix;
2949 n += c - '0'; /* FIXME this overflows anyway */
2950 }
2951 else
2952 overflow = 1;
2953
2954 /* This depends on large values being output in octal, which is
2955 what GCC does. */
2956 if (radix == 8)
2957 {
2958 if (nbits == 0)
2959 {
2960 if (c == '0')
2961 /* Ignore leading zeroes. */
2962 ;
2963 else if (c == '1')
2964 nbits = 1;
2965 else if (c == '2' || c == '3')
2966 nbits = 2;
2967 else
2968 nbits = 3;
2969 }
2970 else
2971 nbits += 3;
2972 }
2973 }
2974 if (end)
2975 {
2976 if (c && c != end)
2977 {
2978 if (bits != NULL)
2979 *bits = -1;
2980 return;
2981 }
2982 }
2983 else
2984 --p;
2985
2986 *pp = p;
2987 if (overflow)
2988 {
2989 if (nbits == 0)
2990 {
2991 /* Large decimal constants are an error (because it is hard to
2992 count how many bits are in them). */
2993 if (bits != NULL)
2994 *bits = -1;
2995 return;
2996 }
2997
2998 /* -0x7f is the same as 0x80. So deal with it by adding one to
2999 the number of bits. */
3000 if (sign == -1)
3001 ++nbits;
3002 if (bits)
3003 *bits = nbits;
3004 }
3005 else
3006 {
3007 if (valu)
3008 *valu = n * sign;
3009 if (bits)
3010 *bits = 0;
3011 }
3012 }
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 }
This page took 0.113669 seconds and 5 git commands to generate.