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