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