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