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