* Makefile.in: Add xcoffread.c, xcoffexec.c.
[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
1640 TYPE_FLAGS (type) |= TYPE_FLAG_STUB;
1641
1642 add_undefined_type (type);
1643 return type;
1644 }
1645
1646 case '-': /* RS/6000 built-in type */
1647 (*pp)--;
1648 type = builtin_type (pp); /* (in xcoffread.c) */
1649 goto after_digits;
1650
1651 case '0':
1652 case '1':
1653 case '2':
1654 case '3':
1655 case '4':
1656 case '5':
1657 case '6':
1658 case '7':
1659 case '8':
1660 case '9':
1661 case '(':
1662 (*pp)--;
1663 read_type_number (pp, xtypenums);
1664 type = *dbx_lookup_type (xtypenums);
1665 /* fall through */
1666
1667 after_digits:
1668 if (type == 0)
1669 type = builtin_type_void;
1670 if (typenums[0] != -1)
1671 *dbx_lookup_type (typenums) = type;
1672 break;
1673
1674 case '*':
1675 type1 = read_type (pp);
1676 /* FIXME -- we should be doing smash_to_XXX types here. */
1677 #if 0
1678 /* postponed type decoration should be allowed. */
1679 if (typenums[1] > 0 && typenums[1] < type_vector_length &&
1680 (type = type_vector[typenums[1]])) {
1681 smash_to_pointer_type (type, type1);
1682 break;
1683 }
1684 #endif
1685 type = lookup_pointer_type (type1);
1686 if (typenums[0] != -1)
1687 *dbx_lookup_type (typenums) = type;
1688 break;
1689
1690 case '@':
1691 {
1692 struct type *domain = read_type (pp);
1693 struct type *memtype;
1694
1695 if (**pp != ',')
1696 /* Invalid member type data format. */
1697 return error_type (pp);
1698 ++*pp;
1699
1700 memtype = read_type (pp);
1701 type = dbx_alloc_type (typenums);
1702 smash_to_member_type (type, domain, memtype);
1703 }
1704 break;
1705
1706 case '#':
1707 if ((*pp)[0] == '#')
1708 {
1709 /* We'll get the parameter types from the name. */
1710 struct type *return_type;
1711
1712 *pp += 1;
1713 return_type = read_type (pp);
1714 if (*(*pp)++ != ';')
1715 complain (&invalid_member_complaint, symnum);
1716 type = allocate_stub_method (return_type);
1717 if (typenums[0] != -1)
1718 *dbx_lookup_type (typenums) = type;
1719 }
1720 else
1721 {
1722 struct type *domain = read_type (pp);
1723 struct type *return_type;
1724 struct type **args;
1725
1726 if (*(*pp)++ != ',')
1727 error ("invalid member type data format, at symtab pos %d.",
1728 symnum);
1729
1730 return_type = read_type (pp);
1731 args = read_args (pp, ';');
1732 type = dbx_alloc_type (typenums);
1733 smash_to_method_type (type, domain, return_type, args);
1734 }
1735 break;
1736
1737 case '&':
1738 type1 = read_type (pp);
1739 type = lookup_reference_type (type1);
1740 if (typenums[0] != -1)
1741 *dbx_lookup_type (typenums) = type;
1742 break;
1743
1744 case 'f':
1745 type1 = read_type (pp);
1746 type = lookup_function_type (type1);
1747 if (typenums[0] != -1)
1748 *dbx_lookup_type (typenums) = type;
1749 break;
1750
1751 case 'r':
1752 type = read_range_type (pp, typenums);
1753 if (typenums[0] != -1)
1754 *dbx_lookup_type (typenums) = type;
1755 break;
1756
1757 case 'e':
1758 type = dbx_alloc_type (typenums);
1759 type = read_enum_type (pp, type);
1760 *dbx_lookup_type (typenums) = type;
1761 break;
1762
1763 case 's':
1764 type = dbx_alloc_type (typenums);
1765 TYPE_NAME (type) = type_synonym_name;
1766 type_synonym_name = 0;
1767 type = read_struct_type (pp, type);
1768 break;
1769
1770 case 'u':
1771 type = dbx_alloc_type (typenums);
1772 TYPE_NAME (type) = type_synonym_name;
1773 type_synonym_name = 0;
1774 type = read_struct_type (pp, type);
1775 TYPE_CODE (type) = TYPE_CODE_UNION;
1776 break;
1777
1778 case 'a':
1779 if (**pp != 'r')
1780 return error_type (pp);
1781 ++*pp;
1782
1783 type = dbx_alloc_type (typenums);
1784 type = read_array_type (pp, type);
1785 break;
1786
1787 default:
1788 --*pp; /* Go back to the symbol in error */
1789 /* Particularly important if it was \0! */
1790 return error_type (pp);
1791 }
1792
1793 if (type == 0)
1794 abort ();
1795
1796 #if 0
1797 /* If this is an overriding temporary alteration for a header file's
1798 contents, and this type number is unknown in the global definition,
1799 put this type into the global definition at this type number. */
1800 if (header_file_prev_index >= 0)
1801 {
1802 register struct type **tp
1803 = explicit_lookup_type (header_file_prev_index, typenums[1]);
1804 if (*tp == 0)
1805 *tp = type;
1806 }
1807 #endif
1808 return type;
1809 }
1810 \f
1811 /* This page contains subroutines of read_type. */
1812
1813 /* Read the description of a structure (or union type)
1814 and return an object describing the type. */
1815
1816 struct type *
1817 read_struct_type (pp, type)
1818 char **pp;
1819 register struct type *type;
1820 {
1821 /* Total number of methods defined in this class.
1822 If the class defines two `f' methods, and one `g' method,
1823 then this will have the value 3. */
1824 int total_length = 0;
1825
1826 struct nextfield
1827 {
1828 struct nextfield *next;
1829 int visibility; /* 0=public, 1=protected, 2=public */
1830 struct field field;
1831 };
1832
1833 struct next_fnfield
1834 {
1835 struct next_fnfield *next;
1836 int visibility; /* 0=public, 1=protected, 2=public */
1837 struct fn_field fn_field;
1838 };
1839
1840 struct next_fnfieldlist
1841 {
1842 struct next_fnfieldlist *next;
1843 struct fn_fieldlist fn_fieldlist;
1844 };
1845
1846 register struct nextfield *list = 0;
1847 struct nextfield *new;
1848 register char *p;
1849 int nfields = 0;
1850 register int n;
1851
1852 register struct next_fnfieldlist *mainlist = 0;
1853 int nfn_fields = 0;
1854
1855 if (TYPE_MAIN_VARIANT (type) == 0)
1856 {
1857 TYPE_MAIN_VARIANT (type) = type;
1858 }
1859
1860 TYPE_CODE (type) = TYPE_CODE_STRUCT;
1861
1862 /* First comes the total size in bytes. */
1863
1864 TYPE_LENGTH (type) = read_number (pp, 0);
1865
1866 /* C++: Now, if the class is a derived class, then the next character
1867 will be a '!', followed by the number of base classes derived from.
1868 Each element in the list contains visibility information,
1869 the offset of this base class in the derived structure,
1870 and then the base type. */
1871 if (**pp == '!')
1872 {
1873 int i, n_baseclasses, offset;
1874 struct type *baseclass;
1875 int via_public;
1876
1877 /* Nonzero if it is a virtual baseclass, i.e.,
1878
1879 struct A{};
1880 struct B{};
1881 struct C : public B, public virtual A {};
1882
1883 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1884 2.0 language feature. */
1885 int via_virtual;
1886
1887 *pp += 1;
1888
1889 n_baseclasses = read_number (pp, ',');
1890 TYPE_FIELD_VIRTUAL_BITS (type) =
1891 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (n_baseclasses));
1892 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), n_baseclasses);
1893
1894 for (i = 0; i < n_baseclasses; i++)
1895 {
1896 if (**pp == '\\')
1897 *pp = next_symbol_text ();
1898
1899 switch (**pp)
1900 {
1901 case '0':
1902 via_virtual = 0;
1903 break;
1904 case '1':
1905 via_virtual = 1;
1906 break;
1907 default:
1908 /* Bad visibility format. */
1909 return error_type (pp);
1910 }
1911 ++*pp;
1912
1913 switch (**pp)
1914 {
1915 case '0':
1916 via_public = 0;
1917 break;
1918 case '2':
1919 via_public = 2;
1920 break;
1921 default:
1922 /* Bad visibility format. */
1923 return error_type (pp);
1924 }
1925 if (via_virtual)
1926 SET_TYPE_FIELD_VIRTUAL (type, i);
1927 ++*pp;
1928
1929 /* Offset of the portion of the object corresponding to
1930 this baseclass. Always zero in the absence of
1931 multiple inheritance. */
1932 offset = read_number (pp, ',');
1933 baseclass = read_type (pp);
1934 *pp += 1; /* skip trailing ';' */
1935
1936 /* Make this baseclass visible for structure-printing purposes. */
1937 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1938 new->next = list;
1939 list = new;
1940 list->visibility = via_public;
1941 list->field.type = baseclass;
1942 list->field.name = type_name_no_tag (baseclass);
1943 list->field.bitpos = offset;
1944 list->field.bitsize = 0; /* this should be an unpacked field! */
1945 nfields++;
1946 }
1947 TYPE_N_BASECLASSES (type) = n_baseclasses;
1948 }
1949
1950 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
1951 At the end, we see a semicolon instead of a field.
1952
1953 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1954 a static field.
1955
1956 The `?' is a placeholder for one of '/2' (public visibility),
1957 '/1' (protected visibility), '/0' (private visibility), or nothing
1958 (C style symbol table, public visibility). */
1959
1960 /* We better set p right now, in case there are no fields at all... */
1961 p = *pp;
1962
1963 while (**pp != ';')
1964 {
1965 /* Check for and handle cretinous dbx symbol name continuation! */
1966 if (**pp == '\\') *pp = next_symbol_text ();
1967
1968 /* Get space to record the next field's data. */
1969 new = (struct nextfield *) alloca (sizeof (struct nextfield));
1970 new->next = list;
1971 list = new;
1972
1973 /* Get the field name. */
1974 p = *pp;
1975 if (*p == CPLUS_MARKER)
1976 {
1977 /* Special GNU C++ name. */
1978 if (*++p == 'v')
1979 {
1980 const char *prefix;
1981 char *name = 0;
1982 struct type *context;
1983
1984 switch (*++p)
1985 {
1986 case 'f':
1987 prefix = vptr_name;
1988 break;
1989 case 'b':
1990 prefix = vb_name;
1991 break;
1992 default:
1993 error ("invalid abbreviation at symtab pos %d.", symnum);
1994 }
1995 *pp = p + 1;
1996 context = read_type (pp);
1997 name = type_name_no_tag (context);
1998 if (name == 0)
1999 {
2000 error ("type name unknown at symtab pos %d.", symnum);
2001 TYPE_NAME (context) = name;
2002 }
2003 list->field.name = obconcat (prefix, name, "");
2004 p = ++(*pp);
2005 if (p[-1] != ':')
2006 error ("invalid abbreviation at symtab pos %d.", symnum);
2007 list->field.type = read_type (pp);
2008 (*pp)++; /* Skip the comma. */
2009 list->field.bitpos = read_number (pp, ';');
2010 /* This field is unpacked. */
2011 list->field.bitsize = 0;
2012 }
2013 /* GNU C++ anonymous type. */
2014 else if (*p == '_')
2015 break;
2016 else
2017 error ("invalid abbreviation at symtab pos %d.", symnum);
2018
2019 nfields++;
2020 continue;
2021 }
2022
2023 while (*p != ':') p++;
2024 list->field.name = obsavestring (*pp, p - *pp);
2025
2026 /* C++: Check to see if we have hit the methods yet. */
2027 if (p[1] == ':')
2028 break;
2029
2030 *pp = p + 1;
2031
2032 /* This means we have a visibility for a field coming. */
2033 if (**pp == '/')
2034 {
2035 switch (*++*pp)
2036 {
2037 case '0':
2038 list->visibility = 0; /* private */
2039 *pp += 1;
2040 break;
2041
2042 case '1':
2043 list->visibility = 1; /* protected */
2044 *pp += 1;
2045 break;
2046
2047 case '2':
2048 list->visibility = 2; /* public */
2049 *pp += 1;
2050 break;
2051 }
2052 }
2053 else /* normal dbx-style format. */
2054 list->visibility = 2; /* public */
2055
2056 list->field.type = read_type (pp);
2057 if (**pp == ':')
2058 {
2059 /* Static class member. */
2060 list->field.bitpos = (long)-1;
2061 p = ++(*pp);
2062 while (*p != ';') p++;
2063 list->field.bitsize = (long) savestring (*pp, p - *pp);
2064 *pp = p + 1;
2065 nfields++;
2066 continue;
2067 }
2068 else if (**pp != ',')
2069 /* Bad structure-type format. */
2070 return error_type (pp);
2071
2072 (*pp)++; /* Skip the comma. */
2073 list->field.bitpos = read_number (pp, ',');
2074 list->field.bitsize = read_number (pp, ';');
2075
2076 #if 0
2077 /* FIXME-tiemann: Can't the compiler put out something which
2078 lets us distinguish these? (or maybe just not put out anything
2079 for the field). What is the story here? What does the compiler
2080 really do? Also, patch gdb.texinfo for this case; I document
2081 it as a possible problem there. Search for "DBX-style". */
2082
2083 /* This is wrong because this is identical to the symbols
2084 produced for GCC 0-size arrays. For example:
2085 typedef union {
2086 int num;
2087 char str[0];
2088 } foo;
2089 The code which dumped core in such circumstances should be
2090 fixed not to dump core. */
2091
2092 /* g++ -g0 can put out bitpos & bitsize zero for a static
2093 field. This does not give us any way of getting its
2094 class, so we can't know its name. But we can just
2095 ignore the field so we don't dump core and other nasty
2096 stuff. */
2097 if (list->field.bitpos == 0
2098 && list->field.bitsize == 0)
2099 {
2100 complain (&dbx_class_complaint, 0);
2101 /* Ignore this field. */
2102 list = list->next;
2103 }
2104 else
2105 #endif /* 0 */
2106 {
2107 /* Detect an unpacked field and mark it as such.
2108 dbx gives a bit size for all fields.
2109 Note that forward refs cannot be packed,
2110 and treat enums as if they had the width of ints. */
2111 if (TYPE_CODE (list->field.type) != TYPE_CODE_INT
2112 && TYPE_CODE (list->field.type) != TYPE_CODE_ENUM)
2113 list->field.bitsize = 0;
2114 if ((list->field.bitsize == 8 * TYPE_LENGTH (list->field.type)
2115 || (TYPE_CODE (list->field.type) == TYPE_CODE_ENUM
2116 && (list->field.bitsize
2117 == 8 * TYPE_LENGTH (builtin_type_int))
2118 )
2119 )
2120 &&
2121 list->field.bitpos % 8 == 0)
2122 list->field.bitsize = 0;
2123 nfields++;
2124 }
2125 }
2126
2127 if (p[1] == ':')
2128 /* chill the list of fields: the last entry (at the head)
2129 is a partially constructed entry which we now scrub. */
2130 list = list->next;
2131
2132 /* Now create the vector of fields, and record how big it is.
2133 We need this info to record proper virtual function table information
2134 for this class's virtual functions. */
2135
2136 TYPE_NFIELDS (type) = nfields;
2137 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack,
2138 sizeof (struct field) * nfields);
2139
2140 TYPE_FIELD_PRIVATE_BITS (type) =
2141 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
2142 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields);
2143
2144 TYPE_FIELD_PROTECTED_BITS (type) =
2145 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (nfields));
2146 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields);
2147
2148 /* Copy the saved-up fields into the field vector. */
2149
2150 for (n = nfields; list; list = list->next)
2151 {
2152 n -= 1;
2153 TYPE_FIELD (type, n) = list->field;
2154 if (list->visibility == 0)
2155 SET_TYPE_FIELD_PRIVATE (type, n);
2156 else if (list->visibility == 1)
2157 SET_TYPE_FIELD_PROTECTED (type, n);
2158 }
2159
2160 /* Now come the method fields, as NAME::methods
2161 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
2162 At the end, we see a semicolon instead of a field.
2163
2164 For the case of overloaded operators, the format is
2165 OPERATOR::*.methods, where OPERATOR is the string "operator",
2166 `*' holds the place for an operator name (such as `+=')
2167 and `.' marks the end of the operator name. */
2168 if (p[1] == ':')
2169 {
2170 /* Now, read in the methods. To simplify matters, we
2171 "unread" the name that has been read, so that we can
2172 start from the top. */
2173
2174 /* For each list of method lists... */
2175 do
2176 {
2177 int i;
2178 struct next_fnfield *sublist = 0;
2179 struct type *look_ahead_type = NULL;
2180 int length = 0;
2181 struct next_fnfieldlist *new_mainlist =
2182 (struct next_fnfieldlist *)alloca (sizeof (struct next_fnfieldlist));
2183 char *main_fn_name;
2184
2185 p = *pp;
2186
2187 /* read in the name. */
2188 while (*p != ':') p++;
2189 #if 0
2190 if ((*pp)[0] == 'o' && (*pp)[1] == 'p' && (*pp)[2] == CPLUS_MARKER)
2191 {
2192 /* This lets the user type "break operator+".
2193 We could just put in "+" as the name, but that wouldn't
2194 work for "*". */
2195 /* I don't understand what this is trying to do.
2196 It seems completely bogus. -Per Bothner. */
2197 static char opname[32] = {'o', 'p', CPLUS_MARKER};
2198 char *o = opname + 3;
2199
2200 /* Skip past '::'. */
2201 *pp = p + 2;
2202 if (**pp == '\\') *pp = next_symbol_text ();
2203 p = *pp;
2204 while (*p != '.')
2205 *o++ = *p++;
2206 main_fn_name = savestring (opname, o - opname);
2207 /* Skip past '.' */
2208 *pp = p + 1;
2209 }
2210 else
2211 #endif
2212 main_fn_name = savestring (*pp, p - *pp);
2213 /* Skip past '::'. */
2214 *pp = p + 2;
2215 new_mainlist->fn_fieldlist.name = main_fn_name;
2216
2217 do
2218 {
2219 struct next_fnfield *new_sublist =
2220 (struct next_fnfield *)alloca (sizeof (struct next_fnfield));
2221
2222 /* Check for and handle cretinous dbx symbol name continuation! */
2223 if (look_ahead_type == NULL) /* Normal case. */
2224 {
2225 if (**pp == '\\') *pp = next_symbol_text ();
2226
2227 new_sublist->fn_field.type = read_type (pp);
2228 if (**pp != ':')
2229 /* Invalid symtab info for method. */
2230 return error_type (pp);
2231 }
2232 else
2233 { /* g++ version 1 kludge */
2234 new_sublist->fn_field.type = look_ahead_type;
2235 look_ahead_type = NULL;
2236 }
2237
2238 *pp += 1;
2239 p = *pp;
2240 while (*p != ';') p++;
2241 /* If this is just a stub, then we don't have the
2242 real name here. */
2243 new_sublist->fn_field.physname = savestring (*pp, p - *pp);
2244 *pp = p + 1;
2245 new_sublist->visibility = *(*pp)++ - '0';
2246 if (**pp == '\\') *pp = next_symbol_text ();
2247 switch (**pp)
2248 {
2249 case 'A': /* Normal functions. */
2250 new_sublist->fn_field.is_const = 0;
2251 new_sublist->fn_field.is_volatile = 0;
2252 (*pp)++;
2253 break;
2254 case 'B': /* `const' member functions. */
2255 new_sublist->fn_field.is_const = 1;
2256 new_sublist->fn_field.is_volatile = 0;
2257 (*pp)++;
2258 break;
2259 case 'C': /* `volatile' member function. */
2260 new_sublist->fn_field.is_const = 0;
2261 new_sublist->fn_field.is_volatile = 1;
2262 (*pp)++;
2263 break;
2264 case 'D': /* `const volatile' member function. */
2265 new_sublist->fn_field.is_const = 1;
2266 new_sublist->fn_field.is_volatile = 1;
2267 (*pp)++;
2268 break;
2269 default:
2270 /* This probably just means we're processing a file compiled
2271 with g++ version 1. */
2272 complain(&const_vol_complaint, **pp);
2273 }
2274
2275 switch (*(*pp)++)
2276 {
2277 case '*':
2278 /* virtual member function, followed by index. */
2279 /* The sign bit is set to distinguish pointers-to-methods
2280 from virtual function indicies. Since the array is
2281 in words, the quantity must be shifted left by 1
2282 on 16 bit machine, and by 2 on 32 bit machine, forcing
2283 the sign bit out, and usable as a valid index into
2284 the array. Remove the sign bit here. */
2285 new_sublist->fn_field.voffset =
2286 (0x7fffffff & read_number (pp, ';')) + 2;
2287
2288 if (**pp == '\\') *pp = next_symbol_text ();
2289
2290 if (**pp == ';' || **pp == '\0')
2291 /* Must be g++ version 1. */
2292 new_sublist->fn_field.fcontext = 0;
2293 else
2294 {
2295 /* Figure out from whence this virtual function came.
2296 It may belong to virtual function table of
2297 one of its baseclasses. */
2298 look_ahead_type = read_type (pp);
2299 if (**pp == ':')
2300 { /* g++ version 1 overloaded methods. */ }
2301 else
2302 {
2303 new_sublist->fn_field.fcontext = look_ahead_type;
2304 if (**pp != ';')
2305 return error_type (pp);
2306 else
2307 ++*pp;
2308 look_ahead_type = NULL;
2309 }
2310 }
2311 break;
2312
2313 case '?':
2314 /* static member function. */
2315 new_sublist->fn_field.voffset = VOFFSET_STATIC;
2316 break;
2317 default:
2318 /* **pp == '.'. */
2319 /* normal member function. */
2320 new_sublist->fn_field.voffset = 0;
2321 new_sublist->fn_field.fcontext = 0;
2322 break;
2323 }
2324
2325 new_sublist->next = sublist;
2326 sublist = new_sublist;
2327 length++;
2328 if (**pp == '\\') *pp = next_symbol_text ();
2329 }
2330 while (**pp != ';' && **pp != '\0');
2331
2332 *pp += 1;
2333
2334 new_mainlist->fn_fieldlist.fn_fields =
2335 (struct fn_field *) obstack_alloc (symbol_obstack,
2336 sizeof (struct fn_field) * length);
2337 TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist) =
2338 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
2339 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist->fn_fieldlist), length);
2340
2341 TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist) =
2342 (B_TYPE *) obstack_alloc (symbol_obstack, B_BYTES (length));
2343 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist->fn_fieldlist), length);
2344
2345 for (i = length; (i--, sublist); sublist = sublist->next)
2346 {
2347 new_mainlist->fn_fieldlist.fn_fields[i] = sublist->fn_field;
2348 if (sublist->visibility == 0)
2349 B_SET (new_mainlist->fn_fieldlist.private_fn_field_bits, i);
2350 else if (sublist->visibility == 1)
2351 B_SET (new_mainlist->fn_fieldlist.protected_fn_field_bits, i);
2352 }
2353
2354 new_mainlist->fn_fieldlist.length = length;
2355 new_mainlist->next = mainlist;
2356 mainlist = new_mainlist;
2357 nfn_fields++;
2358 total_length += length;
2359 }
2360 while (**pp != ';');
2361 }
2362
2363 *pp += 1;
2364
2365 TYPE_FN_FIELDLISTS (type) =
2366 (struct fn_fieldlist *) obstack_alloc (symbol_obstack,
2367 sizeof (struct fn_fieldlist) * nfn_fields);
2368
2369 TYPE_NFN_FIELDS (type) = nfn_fields;
2370 TYPE_NFN_FIELDS_TOTAL (type) = total_length;
2371
2372 {
2373 int i;
2374 for (i = 0; i < TYPE_N_BASECLASSES (type); ++i)
2375 TYPE_NFN_FIELDS_TOTAL (type) +=
2376 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type, i));
2377 }
2378
2379 for (n = nfn_fields; mainlist; mainlist = mainlist->next)
2380 TYPE_FN_FIELDLISTS (type)[--n] = mainlist->fn_fieldlist;
2381
2382 if (**pp == '~')
2383 {
2384 *pp += 1;
2385
2386 if (**pp == '=')
2387 {
2388 TYPE_FLAGS (type)
2389 |= TYPE_FLAG_HAS_CONSTRUCTOR | TYPE_FLAG_HAS_DESTRUCTOR;
2390 *pp += 1;
2391 }
2392 else if (**pp == '+')
2393 {
2394 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_CONSTRUCTOR;
2395 *pp += 1;
2396 }
2397 else if (**pp == '-')
2398 {
2399 TYPE_FLAGS (type) |= TYPE_FLAG_HAS_DESTRUCTOR;
2400 *pp += 1;
2401 }
2402
2403 /* Read either a '%' or the final ';'. */
2404 if (*(*pp)++ == '%')
2405 {
2406 /* Now we must record the virtual function table pointer's
2407 field information. */
2408
2409 struct type *t;
2410 int i;
2411
2412 t = read_type (pp);
2413 p = (*pp)++;
2414 while (*p != '\0' && *p != ';')
2415 p++;
2416 if (*p == '\0')
2417 /* Premature end of symbol. */
2418 return error_type (pp);
2419
2420 TYPE_VPTR_BASETYPE (type) = t;
2421 if (type == t)
2422 {
2423 if (TYPE_FIELD_NAME (t, TYPE_N_BASECLASSES (t)) == 0)
2424 {
2425 /* FIXME-tiemann: what's this? */
2426 #if 0
2427 TYPE_VPTR_FIELDNO (type) = i = TYPE_N_BASECLASSES (t);
2428 #else
2429 error_type (pp);
2430 #endif
2431 }
2432 else for (i = TYPE_NFIELDS (t) - 1; i >= TYPE_N_BASECLASSES (t); --i)
2433 if (! strncmp (TYPE_FIELD_NAME (t, i), vptr_name,
2434 sizeof (vptr_name) -1))
2435 {
2436 TYPE_VPTR_FIELDNO (type) = i;
2437 break;
2438 }
2439 if (i < 0)
2440 /* Virtual function table field not found. */
2441 return error_type (pp);
2442 }
2443 else
2444 TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t);
2445 *pp = p + 1;
2446 }
2447 }
2448
2449 return type;
2450 }
2451
2452 /* Read a definition of an array type,
2453 and create and return a suitable type object.
2454 Also creates a range type which represents the bounds of that
2455 array. */
2456 struct type *
2457 read_array_type (pp, type)
2458 register char **pp;
2459 register struct type *type;
2460 {
2461 struct type *index_type, *element_type, *range_type;
2462 int lower, upper;
2463 int adjustable = 0;
2464
2465 /* Format of an array type:
2466 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2467 to handle this.
2468
2469 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2470 for these, produce a type like float[][]. */
2471
2472 index_type = read_type (pp);
2473 if (**pp != ';')
2474 /* Improper format of array type decl. */
2475 return error_type (pp);
2476 ++*pp;
2477
2478 if (!(**pp >= '0' && **pp <= '9'))
2479 {
2480 *pp += 1;
2481 adjustable = 1;
2482 }
2483 lower = read_number (pp, ';');
2484
2485 if (!(**pp >= '0' && **pp <= '9'))
2486 {
2487 *pp += 1;
2488 adjustable = 1;
2489 }
2490 upper = read_number (pp, ';');
2491
2492 element_type = read_type (pp);
2493
2494 if (adjustable)
2495 {
2496 lower = 0;
2497 upper = -1;
2498 }
2499
2500 {
2501 /* Create range type. */
2502 range_type = (struct type *) obstack_alloc (symbol_obstack,
2503 sizeof (struct type));
2504 TYPE_CODE (range_type) = TYPE_CODE_RANGE;
2505 TYPE_TARGET_TYPE (range_type) = index_type;
2506
2507 /* This should never be needed. */
2508 TYPE_LENGTH (range_type) = sizeof (int);
2509
2510 TYPE_NFIELDS (range_type) = 2;
2511 TYPE_FIELDS (range_type) =
2512 (struct field *) obstack_alloc (symbol_obstack,
2513 2 * sizeof (struct field));
2514 TYPE_FIELD_BITPOS (range_type, 0) = lower;
2515 TYPE_FIELD_BITPOS (range_type, 1) = upper;
2516 }
2517
2518 TYPE_CODE (type) = TYPE_CODE_ARRAY;
2519 TYPE_TARGET_TYPE (type) = element_type;
2520 TYPE_LENGTH (type) = (upper - lower + 1) * TYPE_LENGTH (element_type);
2521 TYPE_NFIELDS (type) = 1;
2522 TYPE_FIELDS (type) =
2523 (struct field *) obstack_alloc (symbol_obstack,
2524 sizeof (struct field));
2525 TYPE_FIELD_TYPE (type, 0) = range_type;
2526
2527 return type;
2528 }
2529
2530
2531 /* Read a definition of an enumeration type,
2532 and create and return a suitable type object.
2533 Also defines the symbols that represent the values of the type. */
2534
2535 struct type *
2536 read_enum_type (pp, type)
2537 register char **pp;
2538 register struct type *type;
2539 {
2540 register char *p;
2541 char *name;
2542 register long n;
2543 register struct symbol *sym;
2544 int nsyms = 0;
2545 struct pending **symlist;
2546 struct pending *osyms, *syms;
2547 int o_nsyms;
2548
2549 if (within_function)
2550 symlist = &local_symbols;
2551 else
2552 symlist = &file_symbols;
2553 osyms = *symlist;
2554 o_nsyms = osyms ? osyms->nsyms : 0;
2555
2556 /* Read the value-names and their values.
2557 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2558 A semicolon or comman instead of a NAME means the end. */
2559 while (**pp && **pp != ';' && **pp != ',')
2560 {
2561 /* Check for and handle cretinous dbx symbol name continuation! */
2562 if (**pp == '\\') *pp = next_symbol_text ();
2563
2564 p = *pp;
2565 while (*p != ':') p++;
2566 name = obsavestring (*pp, p - *pp);
2567 *pp = p + 1;
2568 n = read_number (pp, ',');
2569
2570 sym = (struct symbol *) obstack_alloc (symbol_obstack, sizeof (struct symbol));
2571 bzero (sym, sizeof (struct symbol));
2572 SYMBOL_NAME (sym) = name;
2573 SYMBOL_CLASS (sym) = LOC_CONST;
2574 SYMBOL_NAMESPACE (sym) = VAR_NAMESPACE;
2575 SYMBOL_VALUE (sym) = n;
2576 add_symbol_to_list (sym, symlist);
2577 nsyms++;
2578 }
2579
2580 if (**pp == ';')
2581 (*pp)++; /* Skip the semicolon. */
2582
2583 /* Now fill in the fields of the type-structure. */
2584
2585 TYPE_LENGTH (type) = sizeof (int);
2586 TYPE_CODE (type) = TYPE_CODE_ENUM;
2587 TYPE_NFIELDS (type) = nsyms;
2588 TYPE_FIELDS (type) = (struct field *) obstack_alloc (symbol_obstack, sizeof (struct field) * nsyms);
2589
2590 /* Find the symbols for the values and put them into the type.
2591 The symbols can be found in the symlist that we put them on
2592 to cause them to be defined. osyms contains the old value
2593 of that symlist; everything up to there was defined by us. */
2594 /* Note that we preserve the order of the enum constants, so
2595 that in something like "enum {FOO, LAST_THING=FOO}" we print
2596 FOO, not LAST_THING. */
2597
2598 for (syms = *symlist, n = 0; syms; syms = syms->next)
2599 {
2600 int j = 0;
2601 if (syms == osyms)
2602 j = o_nsyms;
2603 for (; j < syms->nsyms; j++,n++)
2604 {
2605 struct symbol *xsym = syms->symbol[j];
2606 SYMBOL_TYPE (xsym) = type;
2607 TYPE_FIELD_NAME (type, n) = SYMBOL_NAME (xsym);
2608 TYPE_FIELD_VALUE (type, n) = 0;
2609 TYPE_FIELD_BITPOS (type, n) = SYMBOL_VALUE (xsym);
2610 TYPE_FIELD_BITSIZE (type, n) = 0;
2611 }
2612 if (syms == osyms)
2613 break;
2614 }
2615
2616 #if 0
2617 /* This screws up perfectly good C programs with enums. FIXME. */
2618 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2619 if(TYPE_NFIELDS(type) == 2 &&
2620 ((!strcmp(TYPE_FIELD_NAME(type,0),"TRUE") &&
2621 !strcmp(TYPE_FIELD_NAME(type,1),"FALSE")) ||
2622 (!strcmp(TYPE_FIELD_NAME(type,1),"TRUE") &&
2623 !strcmp(TYPE_FIELD_NAME(type,0),"FALSE"))))
2624 TYPE_CODE(type) = TYPE_CODE_BOOL;
2625 #endif
2626
2627 return type;
2628 }
2629
2630 /* Read a number from the string pointed to by *PP.
2631 The value of *PP is advanced over the number.
2632 If END is nonzero, the character that ends the
2633 number must match END, or an error happens;
2634 and that character is skipped if it does match.
2635 If END is zero, *PP is left pointing to that character.
2636
2637 If the number fits in a long, set *VALUE and set *BITS to 0.
2638 If not, set *BITS to be the number of bits in the number.
2639
2640 If encounter garbage, set *BITS to -1. */
2641
2642 void
2643 read_huge_number (pp, end, valu, bits)
2644 char **pp;
2645 int end;
2646 long *valu;
2647 int *bits;
2648 {
2649 char *p = *pp;
2650 int sign = 1;
2651 long n = 0;
2652 int radix = 10;
2653 char overflow = 0;
2654 int nbits = 0;
2655 int c;
2656 long upper_limit;
2657
2658 if (*p == '-')
2659 {
2660 sign = -1;
2661 p++;
2662 }
2663
2664 /* Leading zero means octal. GCC uses this to output values larger
2665 than an int (because that would be hard in decimal). */
2666 if (*p == '0')
2667 {
2668 radix = 8;
2669 p++;
2670 }
2671
2672 upper_limit = LONG_MAX / radix;
2673 while ((c = *p++) >= '0' && c <= ('0' + radix))
2674 {
2675 if (n <= upper_limit)
2676 {
2677 n *= radix;
2678 n += c - '0'; /* FIXME this overflows anyway */
2679 }
2680 else
2681 overflow = 1;
2682
2683 /* This depends on large values being output in octal, which is
2684 what GCC does. */
2685 if (radix == 8)
2686 {
2687 if (nbits == 0)
2688 {
2689 if (c == '0')
2690 /* Ignore leading zeroes. */
2691 ;
2692 else if (c == '1')
2693 nbits = 1;
2694 else if (c == '2' || c == '3')
2695 nbits = 2;
2696 else
2697 nbits = 3;
2698 }
2699 else
2700 nbits += 3;
2701 }
2702 }
2703 if (end)
2704 {
2705 if (c && c != end)
2706 {
2707 if (bits != NULL)
2708 *bits = -1;
2709 return;
2710 }
2711 }
2712 else
2713 --p;
2714
2715 *pp = p;
2716 if (overflow)
2717 {
2718 if (nbits == 0)
2719 {
2720 /* Large decimal constants are an error (because it is hard to
2721 count how many bits are in them). */
2722 if (bits != NULL)
2723 *bits = -1;
2724 return;
2725 }
2726
2727 /* -0x7f is the same as 0x80. So deal with it by adding one to
2728 the number of bits. */
2729 if (sign == -1)
2730 ++nbits;
2731 if (bits)
2732 *bits = nbits;
2733 }
2734 else
2735 {
2736 if (valu)
2737 *valu = n * sign;
2738 if (bits)
2739 *bits = 0;
2740 }
2741 }
2742
2743 #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
2744 #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
2745
2746 struct type *
2747 read_range_type (pp, typenums)
2748 char **pp;
2749 int typenums[2];
2750 {
2751 int rangenums[2];
2752 long n2, n3;
2753 int n2bits, n3bits;
2754 int self_subrange;
2755 struct type *result_type;
2756
2757 /* First comes a type we are a subrange of.
2758 In C it is usually 0, 1 or the type being defined. */
2759 read_type_number (pp, rangenums);
2760 self_subrange = (rangenums[0] == typenums[0] &&
2761 rangenums[1] == typenums[1]);
2762
2763 /* A semicolon should now follow; skip it. */
2764 if (**pp == ';')
2765 (*pp)++;
2766
2767 /* The remaining two operands are usually lower and upper bounds
2768 of the range. But in some special cases they mean something else. */
2769 read_huge_number (pp, ';', &n2, &n2bits);
2770 read_huge_number (pp, ';', &n3, &n3bits);
2771
2772 if (n2bits == -1 || n3bits == -1)
2773 return error_type (pp);
2774
2775 /* If limits are huge, must be large integral type. */
2776 if (n2bits != 0 || n3bits != 0)
2777 {
2778 char got_signed = 0;
2779 char got_unsigned = 0;
2780 /* Number of bits in the type. */
2781 int nbits;
2782
2783 /* Range from 0 to <large number> is an unsigned large integral type. */
2784 if ((n2bits == 0 && n2 == 0) && n3bits != 0)
2785 {
2786 got_unsigned = 1;
2787 nbits = n3bits;
2788 }
2789 /* Range from <large number> to <large number>-1 is a large signed
2790 integral type. */
2791 else if (n2bits != 0 && n3bits != 0 && n2bits == n3bits + 1)
2792 {
2793 got_signed = 1;
2794 nbits = n2bits;
2795 }
2796
2797 /* Check for "long long". */
2798 if (got_signed && nbits == TARGET_LONG_LONG_BIT)
2799 return builtin_type_long_long;
2800 if (got_unsigned && nbits == TARGET_LONG_LONG_BIT)
2801 return builtin_type_unsigned_long_long;
2802
2803 if (got_signed || got_unsigned)
2804 {
2805 result_type = (struct type *) obstack_alloc (symbol_obstack,
2806 sizeof (struct type));
2807 bzero (result_type, sizeof (struct type));
2808 TYPE_LENGTH (result_type) = nbits / TARGET_CHAR_BIT;
2809 TYPE_MAIN_VARIANT (result_type) = result_type;
2810 TYPE_CODE (result_type) = TYPE_CODE_INT;
2811 if (got_unsigned)
2812 TYPE_FLAGS (result_type) |= TYPE_FLAG_UNSIGNED;
2813 return result_type;
2814 }
2815 else
2816 return error_type (pp);
2817 }
2818
2819 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2820 if (self_subrange && n2 == 0 && n3 == 0)
2821 return builtin_type_void;
2822
2823 /* If n3 is zero and n2 is not, we want a floating type,
2824 and n2 is the width in bytes.
2825
2826 Fortran programs appear to use this for complex types also,
2827 and they give no way to distinguish between double and single-complex!
2828 We don't have complex types, so we would lose on all fortran files!
2829 So return type `double' for all of those. It won't work right
2830 for the complex values, but at least it makes the file loadable. */
2831
2832 if (n3 == 0 && n2 > 0)
2833 {
2834 if (n2 == sizeof (float))
2835 return builtin_type_float;
2836 return builtin_type_double;
2837 }
2838
2839 /* If the upper bound is -1, it must really be an unsigned int. */
2840
2841 else if (n2 == 0 && n3 == -1)
2842 {
2843 /* FIXME -- this confuses host and target type sizes. */
2844 if (sizeof (int) == sizeof (long))
2845 return builtin_type_unsigned_int;
2846 else
2847 return builtin_type_unsigned_long;
2848 }
2849
2850 /* Special case: char is defined (Who knows why) as a subrange of
2851 itself with range 0-127. */
2852 else if (self_subrange && n2 == 0 && n3 == 127)
2853 return builtin_type_char;
2854
2855 /* Assumptions made here: Subrange of self is equivalent to subrange
2856 of int. FIXME: Host and target type-sizes assumed the same. */
2857 else if (n2 == 0
2858 && (self_subrange ||
2859 *dbx_lookup_type (rangenums) == builtin_type_int))
2860 {
2861 /* an unsigned type */
2862 #ifdef LONG_LONG
2863 if (n3 == - sizeof (long long))
2864 return builtin_type_unsigned_long_long;
2865 #endif
2866 if (n3 == (unsigned int)~0L)
2867 return builtin_type_unsigned_int;
2868 if (n3 == (unsigned long)~0L)
2869 return builtin_type_unsigned_long;
2870 if (n3 == (unsigned short)~0L)
2871 return builtin_type_unsigned_short;
2872 if (n3 == (unsigned char)~0L)
2873 return builtin_type_unsigned_char;
2874 }
2875 #ifdef LONG_LONG
2876 else if (n3 == 0 && n2 == -sizeof (long long))
2877 return builtin_type_long_long;
2878 #endif
2879 else if (n2 == -n3 -1)
2880 {
2881 /* a signed type */
2882 if (n3 == (1 << (8 * sizeof (int) - 1)) - 1)
2883 return builtin_type_int;
2884 if (n3 == (1 << (8 * sizeof (long) - 1)) - 1)
2885 return builtin_type_long;
2886 if (n3 == (1 << (8 * sizeof (short) - 1)) - 1)
2887 return builtin_type_short;
2888 if (n3 == (1 << (8 * sizeof (char) - 1)) - 1)
2889 return builtin_type_char;
2890 }
2891
2892 /* We have a real range type on our hands. Allocate space and
2893 return a real pointer. */
2894
2895 /* At this point I don't have the faintest idea how to deal with
2896 a self_subrange type; I'm going to assume that this is used
2897 as an idiom, and that all of them are special cases. So . . . */
2898 if (self_subrange)
2899 return error_type (pp);
2900
2901 result_type = (struct type *) obstack_alloc (symbol_obstack,
2902 sizeof (struct type));
2903 bzero (result_type, sizeof (struct type));
2904
2905 TYPE_CODE (result_type) = TYPE_CODE_RANGE;
2906
2907 TYPE_TARGET_TYPE (result_type) = *dbx_lookup_type(rangenums);
2908 if (TYPE_TARGET_TYPE (result_type) == 0) {
2909 complain (&range_type_base_complaint, rangenums[1]);
2910 TYPE_TARGET_TYPE (result_type) = builtin_type_int;
2911 }
2912
2913 TYPE_NFIELDS (result_type) = 2;
2914 TYPE_FIELDS (result_type) =
2915 (struct field *) obstack_alloc (symbol_obstack,
2916 2 * sizeof (struct field));
2917 bzero (TYPE_FIELDS (result_type), 2 * sizeof (struct field));
2918 TYPE_FIELD_BITPOS (result_type, 0) = n2;
2919 TYPE_FIELD_BITPOS (result_type, 1) = n3;
2920
2921 #if 0
2922 /* Note that TYPE_LENGTH (result_type) is just overridden a few
2923 statements down. What do we really need here? */
2924 /* We have to figure out how many bytes it takes to hold this
2925 range type. I'm going to assume that anything that is pushing
2926 the bounds of a long was taken care of above. */
2927 if (n2 >= MIN_OF_C_TYPE(char) && n3 <= MAX_OF_C_TYPE(char))
2928 TYPE_LENGTH (result_type) = 1;
2929 else if (n2 >= MIN_OF_C_TYPE(short) && n3 <= MAX_OF_C_TYPE(short))
2930 TYPE_LENGTH (result_type) = sizeof (short);
2931 else if (n2 >= MIN_OF_C_TYPE(int) && n3 <= MAX_OF_C_TYPE(int))
2932 TYPE_LENGTH (result_type) = sizeof (int);
2933 else if (n2 >= MIN_OF_C_TYPE(long) && n3 <= MAX_OF_C_TYPE(long))
2934 TYPE_LENGTH (result_type) = sizeof (long);
2935 else
2936 /* Ranged type doesn't fit within known sizes. */
2937 /* FIXME -- use "long long" here. */
2938 return error_type (pp);
2939 #endif
2940
2941 TYPE_LENGTH (result_type) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type));
2942
2943 return result_type;
2944 }
2945
2946 /* Read a number from the string pointed to by *PP.
2947 The value of *PP is advanced over the number.
2948 If END is nonzero, the character that ends the
2949 number must match END, or an error happens;
2950 and that character is skipped if it does match.
2951 If END is zero, *PP is left pointing to that character. */
2952
2953 long
2954 read_number (pp, end)
2955 char **pp;
2956 int end;
2957 {
2958 register char *p = *pp;
2959 register long n = 0;
2960 register int c;
2961 int sign = 1;
2962
2963 /* Handle an optional leading minus sign. */
2964
2965 if (*p == '-')
2966 {
2967 sign = -1;
2968 p++;
2969 }
2970
2971 /* Read the digits, as far as they go. */
2972
2973 while ((c = *p++) >= '0' && c <= '9')
2974 {
2975 n *= 10;
2976 n += c - '0';
2977 }
2978 if (end)
2979 {
2980 if (c && c != end)
2981 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c, symnum);
2982 }
2983 else
2984 --p;
2985
2986 *pp = p;
2987 return n * sign;
2988 }
2989
2990 /* Read in an argument list. This is a list of types, separated by commas
2991 and terminated with END. Return the list of types read in, or (struct type
2992 **)-1 if there is an error. */
2993 struct type **
2994 read_args (pp, end)
2995 char **pp;
2996 int end;
2997 {
2998 /* FIXME! Remove this arbitrary limit! */
2999 struct type *types[1024], **rval; /* allow for fns of 1023 parameters */
3000 int n = 0;
3001
3002 while (**pp != end)
3003 {
3004 if (**pp != ',')
3005 /* Invalid argument list: no ','. */
3006 return (struct type **)-1;
3007 *pp += 1;
3008
3009 /* Check for and handle cretinous dbx symbol name continuation! */
3010 if (**pp == '\\')
3011 *pp = next_symbol_text ();
3012
3013 types[n++] = read_type (pp);
3014 }
3015 *pp += 1; /* get past `end' (the ':' character) */
3016
3017 if (n == 1)
3018 {
3019 rval = (struct type **) xmalloc (2 * sizeof (struct type *));
3020 }
3021 else if (TYPE_CODE (types[n-1]) != TYPE_CODE_VOID)
3022 {
3023 rval = (struct type **) xmalloc ((n + 1) * sizeof (struct type *));
3024 bzero (rval + n, sizeof (struct type *));
3025 }
3026 else
3027 {
3028 rval = (struct type **) xmalloc (n * sizeof (struct type *));
3029 }
3030 bcopy (types, rval, n * sizeof (struct type *));
3031 return rval;
3032 }
3033
3034 /* Add a common block's start address to the offset of each symbol
3035 declared to be in it (by being between a BCOMM/ECOMM pair that uses
3036 the common block name). */
3037
3038 static void
3039 fix_common_block (sym, valu)
3040 struct symbol *sym;
3041 int valu;
3042 {
3043 struct pending *next = (struct pending *) SYMBOL_NAMESPACE (sym);
3044 for ( ; next; next = next->next)
3045 {
3046 register int j;
3047 for (j = next->nsyms - 1; j >= 0; j--)
3048 SYMBOL_VALUE_ADDRESS (next->symbol[j]) += valu;
3049 }
3050 }
3051
3052 /* Initializer for this module */
3053 void
3054 _initialize_buildsym ()
3055 {
3056 undef_types_allocated = 20;
3057 undef_types_length = 0;
3058 undef_types = (struct type **) xmalloc (undef_types_allocated *
3059 sizeof (struct type *));
3060 }
This page took 0.092064 seconds and 5 git commands to generate.