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