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