1 /* Build symbol tables in GDB's internal format.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This module provides subroutines used for creating and adding to
21 the symbol table. These routines are called from various symbol-
22 file-reading routines.
24 They originated in dbxread.c of gdb-4.2, and were split out to
25 make xcoffread.c more maintainable by sharing code. */
31 #include "breakpoint.h"
32 #include "gdbcore.h" /* for bfd stuff for symfile.h */
33 #include "symfile.h" /* Needed for "struct complaint" */
34 #include "stab.gnu.h" /* We always use GNU stabs, not native */
39 /* Ask buildsym.h to define the vars it normally declares `extern'. */
41 #include "buildsym.h" /* Our own declarations */
45 extern double atof ();
47 /* Things we export from outside, and probably shouldn't. FIXME. */
48 extern void new_object_header_files ();
49 extern void start_subfile ();
50 extern char *next_symbol_text ();
51 extern int hashname ();
53 static struct symbol
*define_symbol ();
54 static void cleanup_undefined_types ();
55 static void fix_common_block ();
57 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
58 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
60 /* Define this as 1 if a pcc declaration of a char or short argument
61 gives the correct address. Otherwise assume pcc gives the
62 address of the corresponding int, which is not the same on a
63 big-endian machine. */
65 #ifndef BELIEVE_PCC_PROMOTION
66 #define BELIEVE_PCC_PROMOTION 0
69 /* Make a list of forward references which haven't been defined. */
70 static struct type
**undef_types
;
71 static int undef_types_allocated
, undef_types_length
;
74 /* Complaints about the symbols we have encountered. */
76 struct complaint innerblock_complaint
=
77 {"inner block not inside outer block in %s", 0, 0};
79 struct complaint blockvector_complaint
=
80 {"block at %x out of order", 0, 0};
83 struct complaint dbx_class_complaint
=
84 {"encountered DBX-style class variable debugging information.\n\
85 You seem to have compiled your program with \
86 \"g++ -g0\" instead of \"g++ -g\".\n\
87 Therefore GDB will not know about your class variables", 0, 0};
90 struct complaint const_vol_complaint
=
91 {"const/volatile indicator missing (ok if using g++ v1.x), got '%c'", 0, 0};
93 struct complaint error_type_complaint
=
94 {"debug info mismatch between compiler and debugger", 0, 0};
96 struct complaint invalid_member_complaint
=
97 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
99 struct complaint range_type_base_complaint
=
100 {"base type %d of range type is not defined", 0, 0};
102 /* Look up a dbx type-number pair. Return the address of the slot
103 where the type for that number-pair is stored.
104 The number-pair is in TYPENUMS.
106 This can be used for finding the type associated with that pair
107 or for associating a new type with the pair. */
110 dbx_lookup_type (typenums
)
113 register int filenum
= typenums
[0], index
= typenums
[1];
115 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
116 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
117 filenum
, index
, symnum
);
121 /* Type is defined outside of header files.
122 Find it in this object file's type vector. */
123 while (index
>= type_vector_length
)
125 type_vector_length
*= 2;
126 type_vector
= (struct type
**)
127 xrealloc (type_vector
,
128 (type_vector_length
* sizeof (struct type
*)));
129 bzero (&type_vector
[type_vector_length
/ 2],
130 type_vector_length
* sizeof (struct type
*) / 2);
132 return &type_vector
[index
];
136 register int real_filenum
= this_object_header_files
[filenum
];
137 register struct header_file
*f
;
140 if (real_filenum
>= n_header_files
)
143 f
= &header_files
[real_filenum
];
145 f_orig_length
= f
->length
;
146 if (index
>= f_orig_length
)
148 while (index
>= f
->length
)
150 f
->vector
= (struct type
**)
151 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
152 bzero (&f
->vector
[f_orig_length
],
153 (f
->length
- f_orig_length
) * sizeof (struct type
*));
155 return &f
->vector
[index
];
159 /* Create a type object. Occaisionally used when you need a type
160 which isn't going to be given a type number. */
165 register struct type
*type
=
166 (struct type
*) obstack_alloc (symbol_obstack
, sizeof (struct type
));
168 bzero (type
, sizeof (struct type
));
169 TYPE_VPTR_FIELDNO (type
) = -1;
170 TYPE_VPTR_BASETYPE (type
) = 0;
174 /* Make sure there is a type allocated for type numbers TYPENUMS
175 and return the type object.
176 This can create an empty (zeroed) type object.
177 TYPENUMS may be (-1, -1) to return a new type object that is not
178 put into the type vector, and so may not be referred to by number. */
181 dbx_alloc_type (typenums
)
184 register struct type
**type_addr
;
185 register struct type
*type
;
187 if (typenums
[1] != -1)
189 type_addr
= dbx_lookup_type (typenums
);
198 /* If we are referring to a type not known at all yet,
199 allocate an empty type for it.
200 We will fill it in later if we find out how. */
203 type
= dbx_create_type ();
211 /* maintain the lists of symbols and blocks */
213 /* Add a symbol to one of the lists of symbols. */
215 add_symbol_to_list (symbol
, listhead
)
216 struct symbol
*symbol
;
217 struct pending
**listhead
;
219 /* We keep PENDINGSIZE symbols in each link of the list.
220 If we don't have a link with room in it, add a new link. */
221 if (*listhead
== 0 || (*listhead
)->nsyms
== PENDINGSIZE
)
223 register struct pending
*link
;
226 link
= free_pendings
;
227 free_pendings
= link
->next
;
230 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
232 link
->next
= *listhead
;
237 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
240 /* At end of reading syms, or in case of quit,
241 really free as many `struct pending's as we can easily find. */
245 really_free_pendings (foo
)
248 struct pending
*next
, *next1
;
250 struct pending_block
*bnext
, *bnext1
;
253 for (next
= free_pendings
; next
; next
= next1
)
260 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
261 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
263 bnext1
= bnext
->next
;
269 for (next
= file_symbols
; next
; next
= next1
)
276 for (next
= global_symbols
; next
; next
= next1
)
284 /* Take one of the lists of symbols and make a block from it.
285 Keep the order the symbols have in the list (reversed from the input file).
286 Put the block on the list of pending blocks. */
289 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
290 struct symbol
*symbol
;
291 struct pending
**listhead
;
292 struct pending_block
*old_blocks
;
293 CORE_ADDR start
, end
;
295 register struct pending
*next
, *next1
;
296 register struct block
*block
;
297 register struct pending_block
*pblock
;
298 struct pending_block
*opblock
;
301 /* Count the length of the list of symbols. */
303 for (next
= *listhead
, i
= 0; next
; i
+= next
->nsyms
, next
= next
->next
)
306 block
= (struct block
*) obstack_alloc (symbol_obstack
,
307 (sizeof (struct block
)
309 * sizeof (struct symbol
*))));
311 /* Copy the symbols into the block. */
313 BLOCK_NSYMS (block
) = i
;
314 for (next
= *listhead
; next
; next
= next
->next
)
317 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
318 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
321 BLOCK_START (block
) = start
;
322 BLOCK_END (block
) = end
;
323 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
324 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
326 /* Put the block in as the value of the symbol that names it. */
330 SYMBOL_BLOCK_VALUE (symbol
) = block
;
331 BLOCK_FUNCTION (block
) = symbol
;
334 BLOCK_FUNCTION (block
) = 0;
336 /* Now "free" the links of the list, and empty the list. */
338 for (next
= *listhead
; next
; next
= next1
)
341 next
->next
= free_pendings
;
342 free_pendings
= next
;
346 /* Install this block as the superblock
347 of all blocks made since the start of this scope
348 that don't have superblocks yet. */
351 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
353 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0) {
355 /* Check to be sure the blocks are nested as we receive them.
356 If the compiler/assembler/linker work, this just burns a small
358 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
359 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)) {
360 complain(&innerblock_complaint
, symbol
? SYMBOL_NAME (symbol
):
362 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
363 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
366 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
371 /* Record this block on the list of all blocks in the file.
372 Put it after opblock, or at the beginning if opblock is 0.
373 This puts the block in the list after all its subblocks. */
375 /* Allocate in the symbol_obstack to save time.
376 It wastes a little space. */
377 pblock
= (struct pending_block
*)
378 obstack_alloc (symbol_obstack
,
379 sizeof (struct pending_block
));
380 pblock
->block
= block
;
383 pblock
->next
= opblock
->next
;
384 opblock
->next
= pblock
;
388 pblock
->next
= pending_blocks
;
389 pending_blocks
= pblock
;
396 register struct pending_block
*next
;
397 register struct blockvector
*blockvector
;
400 /* Count the length of the list of blocks. */
402 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
404 blockvector
= (struct blockvector
*)
405 obstack_alloc (symbol_obstack
,
406 (sizeof (struct blockvector
)
407 + (i
- 1) * sizeof (struct block
*)));
409 /* Copy the blocks into the blockvector.
410 This is done in reverse order, which happens to put
411 the blocks into the proper order (ascending starting address).
412 finish_block has hair to insert each block into the list
413 after its subblocks in order to make sure this is true. */
415 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
416 for (next
= pending_blocks
; next
; next
= next
->next
) {
417 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
420 #if 0 /* Now we make the links in the obstack, so don't free them. */
421 /* Now free the links of the list, and empty the list. */
423 for (next
= pending_blocks
; next
; next
= next1
)
431 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
432 /* Some compilers output blocks in the wrong order, but we depend
433 on their being in the right order so we can binary search.
434 Check the order and moan about it. FIXME. */
435 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
436 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
437 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
438 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
439 complain (&blockvector_complaint
,
440 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
448 /* Manage the vector of line numbers. */
451 record_line (line
, pc
)
455 struct linetable_entry
*e
;
456 /* Ignore the dummy line number in libg.o */
461 /* Make sure line vector is big enough. */
463 if (line_vector_index
+ 1 >= line_vector_length
)
465 line_vector_length
*= 2;
466 line_vector
= (struct linetable
*)
467 xrealloc (line_vector
,
468 (sizeof (struct linetable
)
469 + line_vector_length
* sizeof (struct linetable_entry
)));
470 current_subfile
->line_vector
= line_vector
;
473 e
= line_vector
->item
+ line_vector_index
++;
474 e
->line
= line
; e
->pc
= pc
;
477 /* Start a new symtab for a new source file.
478 This is called when a dbx symbol of type N_SO is seen;
479 it indicates the start of data for one original source file. */
482 start_symtab (name
, dirname
, start_addr
)
485 CORE_ADDR start_addr
;
488 last_source_file
= name
;
489 last_source_start_addr
= start_addr
;
494 /* Context stack is initially empty, with room for 10 levels. */
496 = (struct context_stack
*) xmalloc (10 * sizeof (struct context_stack
));
497 context_stack_size
= 10;
498 context_stack_depth
= 0;
500 new_object_header_files ();
502 type_vector_length
= 160;
503 type_vector
= (struct type
**)
504 xmalloc (type_vector_length
* sizeof (struct type
*));
505 bzero (type_vector
, type_vector_length
* sizeof (struct type
*));
507 /* Initialize the list of sub source files with one entry
508 for this file (the top-level source file). */
512 start_subfile (name
, dirname
);
515 /* Finish the symbol definitions for one main source file,
516 close off all the lexical contexts for that file
517 (creating struct block's for them), then make the struct symtab
518 for that file and put it in the list of all such.
520 END_ADDR is the address of the end of the file's text. */
523 end_symtab (end_addr
)
526 register struct symtab
*symtab
;
527 register struct blockvector
*blockvector
;
528 register struct subfile
*subfile
;
529 register struct linetable
*lv
;
530 struct subfile
*nextsub
;
532 /* Finish the lexical context of the last function in the file;
533 pop the context stack. */
535 if (context_stack_depth
> 0)
537 register struct context_stack
*cstk
;
538 context_stack_depth
--;
539 cstk
= &context_stack
[context_stack_depth
];
540 /* Make a block for the local symbols within. */
541 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
542 cstk
->start_addr
, end_addr
);
545 /* Cleanup any undefined types that have been left hanging around
546 (this needs to be done before the finish_blocks so that
547 file_symbols is still good). */
548 cleanup_undefined_types ();
550 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
551 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
);
552 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
);
553 blockvector
= make_blockvector ();
555 current_subfile
->line_vector_index
= line_vector_index
;
557 /* Now create the symtab objects proper, one for each subfile. */
558 /* (The main file is the last one on the chain.) */
560 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
562 symtab
= allocate_symtab (subfile
->name
);
564 /* Fill in its components. */
565 symtab
->blockvector
= blockvector
;
566 lv
= subfile
->line_vector
;
567 lv
->nitems
= subfile
->line_vector_index
;
568 symtab
->linetable
= (struct linetable
*)
569 xrealloc (lv
, (sizeof (struct linetable
)
570 + lv
->nitems
* sizeof (struct linetable_entry
)));
572 symtab
->dirname
= subfile
->dirname
;
574 symtab
->free_code
= free_linetable
;
575 symtab
->free_ptr
= 0;
577 /* There should never already be a symtab for this name, since
578 any prev dups have been removed when the psymtab was read in.
579 FIXME, there ought to be a way to check this here. */
580 /* FIXME blewit |= free_named_symtabs (symtab->filename); */
582 /* Link the new symtab into the list of such. */
583 symtab
->next
= symtab_list
;
584 symtab_list
= symtab
;
586 nextsub
= subfile
->next
;
590 free ((char *) type_vector
);
592 type_vector_length
= -1;
594 line_vector_length
= -1;
595 last_source_file
= 0;
600 /* Initialize anything that needs initializing when starting to read
601 a fresh piece of a symbol file, e.g. reading in the stuff corresponding
613 /* Initialize anything that needs initializing when a completely new
614 symbol file is specified (not just adding some symbols from another
615 file, e.g. a shared library). */
620 /* Empty the hash table of global syms looking for values. */
621 bzero (global_sym_chain
, sizeof global_sym_chain
);
626 /* Scan through all of the global symbols defined in the object file,
627 assigning values to the debugging symbols that need to be assigned
628 to. Get these symbols from the misc function list. */
636 for (mf
= 0; mf
< misc_function_count
; mf
++)
638 char *namestring
= misc_function_vector
[mf
].name
;
639 struct symbol
*sym
, *prev
;
643 prev
= (struct symbol
*) 0;
645 /* Get the hash index and check all the symbols
646 under that hash index. */
648 hash
= hashname (namestring
);
650 for (sym
= global_sym_chain
[hash
]; sym
;)
652 if (*namestring
== SYMBOL_NAME (sym
)[0]
653 && !strcmp(namestring
+ 1, SYMBOL_NAME (sym
) + 1))
655 /* Splice this symbol out of the hash chain and
656 assign the value we have to it. */
658 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
660 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
662 /* Check to see whether we need to fix up a common block. */
663 /* Note: this code might be executed several times for
664 the same symbol if there are multiple references. */
665 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
666 fix_common_block (sym
, misc_function_vector
[mf
].address
);
668 SYMBOL_VALUE_ADDRESS (sym
) = misc_function_vector
[mf
].address
;
671 sym
= SYMBOL_VALUE_CHAIN (prev
);
673 sym
= global_sym_chain
[hash
];
678 sym
= SYMBOL_VALUE_CHAIN (sym
);
685 /* Read a number by which a type is referred to in dbx data,
686 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
687 Just a single number N is equivalent to (0,N).
688 Return the two numbers by storing them in the vector TYPENUMS.
689 TYPENUMS will then be used as an argument to dbx_lookup_type. */
692 read_type_number (pp
, typenums
)
694 register int *typenums
;
699 typenums
[0] = read_number (pp
, ',');
700 typenums
[1] = read_number (pp
, ')');
705 typenums
[1] = read_number (pp
, 0);
709 /* To handle GNU C++ typename abbreviation, we need to be able to
710 fill in a type's name as soon as space for that type is allocated.
711 `type_synonym_name' is the name of the type being allocated.
712 It is cleared as soon as it is used (lest all allocated types
714 static char *type_synonym_name
;
717 static struct symbol
*
718 define_symbol (valu
, string
, desc
, type
)
724 register struct symbol
*sym
;
725 char *p
= (char *) strchr (string
, ':');
730 /* Ignore syms with empty names. */
734 /* Ignore old-style symbols from cc -go */
738 sym
= (struct symbol
*)obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
740 if (processing_gcc_compilation
) {
741 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
742 number of bytes occupied by a type or object, which we ignore. */
743 SYMBOL_LINE(sym
) = desc
;
745 SYMBOL_LINE(sym
) = 0; /* unknown */
748 if (string
[0] == CPLUS_MARKER
)
750 /* Special GNU C++ names. */
754 SYMBOL_NAME (sym
) = "this";
756 case 'v': /* $vtbl_ptr_type */
757 /* Was: SYMBOL_NAME (sym) = "vptr"; */
760 SYMBOL_NAME (sym
) = "eh_throw";
764 /* This was an anonymous type that was never fixed up. */
775 = (char *) obstack_alloc (symbol_obstack
, ((p
- string
) + 1));
776 /* Open-coded bcopy--saves function call time. */
778 register char *p1
= string
;
779 register char *p2
= SYMBOL_NAME (sym
);
786 /* Determine the type of name being defined. */
787 /* The Acorn RISC machine's compiler can put out locals that don't
788 start with "234=" or "(3,4)=", so assume anything other than the
789 deftypes we know how to handle is a local. */
790 /* (Peter Watkins @ Computervision)
791 Handle Sun-style local fortran array types 'ar...' .
792 (gnu@cygnus.com) -- this strchr() handles them properly?
793 (tiemann@cygnus.com) -- 'C' is for catch. */
794 if (!strchr ("cfFGpPrStTvVXC", *p
))
799 /* c is a special case, not followed by a type-number.
800 SYMBOL:c=iVALUE for an integer constant symbol.
801 SYMBOL:c=rVALUE for a floating constant symbol.
802 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
803 e.g. "b:c=e6,0" for "const b = blob1"
804 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
808 error ("Invalid symbol data at symtab pos %d.", symnum
);
816 SYMBOL_TYPE (sym
) = builtin_type_double
;
818 (char *) obstack_alloc (symbol_obstack
, sizeof (double));
819 bcopy (&d
, dbl_valu
, sizeof (double));
820 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
821 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
822 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
827 SYMBOL_TYPE (sym
) = builtin_type_int
;
828 SYMBOL_VALUE (sym
) = atoi (p
);
829 SYMBOL_CLASS (sym
) = LOC_CONST
;
833 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
834 e.g. "b:c=e6,0" for "const b = blob1"
835 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
839 read_type_number (&p
, typenums
);
841 error ("Invalid symbol data: no comma in enum const symbol");
843 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
844 SYMBOL_VALUE (sym
) = atoi (p
);
845 SYMBOL_CLASS (sym
) = LOC_CONST
;
849 error ("Invalid symbol data at symtab pos %d.", symnum
);
851 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
852 add_symbol_to_list (sym
, &file_symbols
);
856 /* Now usually comes a number that says which data type,
857 and possibly more stuff to define the type
858 (all of which is handled by read_type) */
860 if (deftype
== 'p' && *p
== 'F')
861 /* pF is a two-letter code that means a function parameter in Fortran.
862 The type-number specifies the type of the return value.
863 Translate it into a pointer-to-function type. */
867 = lookup_pointer_type (lookup_function_type (read_type (&p
)));
871 struct type
*type_read
;
877 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
878 strlen (SYMBOL_NAME (sym
)));
881 type_read
= read_type (&p
);
883 if ((deftype
== 'F' || deftype
== 'f')
884 && TYPE_CODE (type_read
) != TYPE_CODE_FUNC
)
887 /* This code doesn't work -- it needs to realloc and can't. */
888 struct type
*new = (struct type
*)
889 obstack_alloc (symbol_obstack
, sizeof (struct type
));
891 /* Generate a template for the type of this function. The
892 types of the arguments will be added as we read the symbol
894 *new = *lookup_function_type (type_read
);
895 SYMBOL_TYPE(sym
) = new;
896 in_function_type
= new;
898 SYMBOL_TYPE (sym
) = lookup_function_type (type_read
);
902 SYMBOL_TYPE (sym
) = type_read
;
908 /* The name of a caught exception. */
909 SYMBOL_CLASS (sym
) = LOC_LABEL
;
910 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
911 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
912 add_symbol_to_list (sym
, &local_symbols
);
916 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
917 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
918 add_symbol_to_list (sym
, &file_symbols
);
922 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
923 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
924 add_symbol_to_list (sym
, &global_symbols
);
928 /* For a class G (global) symbol, it appears that the
929 value is not correct. It is necessary to search for the
930 corresponding linker definition to find the value.
931 These definitions appear at the end of the namelist. */
932 i
= hashname (SYMBOL_NAME (sym
));
933 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
934 global_sym_chain
[i
] = sym
;
935 SYMBOL_CLASS (sym
) = LOC_STATIC
;
936 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
937 add_symbol_to_list (sym
, &global_symbols
);
940 /* This case is faked by a conditional above,
941 when there is no code letter in the dbx data.
942 Dbx data never actually contains 'l'. */
944 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
945 SYMBOL_VALUE (sym
) = valu
;
946 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
947 add_symbol_to_list (sym
, &local_symbols
);
951 /* Normally this is a parameter, a LOC_ARG. On the i960, it
952 can also be a LOC_LOCAL_ARG depending on symbol type. */
953 #ifndef DBX_PARM_SYMBOL_CLASS
954 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
956 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
957 SYMBOL_VALUE (sym
) = valu
;
958 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
960 /* This doesn't work yet. */
961 add_param_to_type (&in_function_type
, sym
);
963 add_symbol_to_list (sym
, &local_symbols
);
965 /* If it's gcc-compiled, if it says `short', believe it. */
966 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
969 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
970 /* This macro is defined on machines (e.g. sparc) where
971 we should believe the type of a PCC 'short' argument,
972 but shouldn't believe the address (the address is
973 the address of the corresponding int). Note that
974 this is only different from the BELIEVE_PCC_PROMOTION
975 case on big-endian machines.
977 My guess is that this correction, as opposed to changing
978 the parameter to an 'int' (as done below, for PCC
979 on most machines), is the right thing to do
980 on all machines, but I don't want to risk breaking
981 something that already works. On most PCC machines,
982 the sparc problem doesn't come up because the calling
983 function has to zero the top bytes (not knowing whether
984 the called function wants an int or a short), so there
985 is no practical difference between an int and a short
986 (except perhaps what happens when the GDB user types
987 "print short_arg = 0x10000;").
989 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
990 actually produces the correct address (we don't need to fix it
991 up). I made this code adapt so that it will offset the symbol
992 if it was pointing at an int-aligned location and not
993 otherwise. This way you can use the same gdb for 4.0.x and
996 if (0 == SYMBOL_VALUE (sym
) % sizeof (int))
998 if (SYMBOL_TYPE (sym
) == builtin_type_char
999 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
)
1000 SYMBOL_VALUE (sym
) += 3;
1001 else if (SYMBOL_TYPE (sym
) == builtin_type_short
1002 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1003 SYMBOL_VALUE (sym
) += 2;
1007 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
1009 /* If PCC says a parameter is a short or a char,
1010 it is really an int. */
1011 if (SYMBOL_TYPE (sym
) == builtin_type_char
1012 || SYMBOL_TYPE (sym
) == builtin_type_short
)
1013 SYMBOL_TYPE (sym
) = builtin_type_int
;
1014 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
1015 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
1016 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
1019 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
1022 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
1023 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1024 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1025 add_symbol_to_list (sym
, &local_symbols
);
1029 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
1030 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
1031 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1032 add_symbol_to_list (sym
, &local_symbols
);
1036 /* Static symbol at top level of file */
1037 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1038 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1039 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1040 add_symbol_to_list (sym
, &file_symbols
);
1044 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1045 SYMBOL_VALUE (sym
) = valu
;
1046 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1047 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1048 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1049 TYPE_NAME (SYMBOL_TYPE (sym
)) =
1050 obsavestring (SYMBOL_NAME (sym
),
1051 strlen (SYMBOL_NAME (sym
)));
1052 /* C++ vagaries: we may have a type which is derived from
1053 a base type which did not have its name defined when the
1054 derived class was output. We fill in the derived class's
1055 base part member's name here in that case. */
1056 else if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1057 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
1058 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
1061 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
1062 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
1063 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
1064 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
1067 add_symbol_to_list (sym
, &file_symbols
);
1071 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
1072 SYMBOL_VALUE (sym
) = valu
;
1073 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
1074 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
1075 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
1076 TYPE_NAME (SYMBOL_TYPE (sym
))
1078 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
1080 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
1081 ? "struct " : "union ")),
1083 add_symbol_to_list (sym
, &file_symbols
);
1087 register struct symbol
*typedef_sym
1088 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
1089 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
1090 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
1092 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
1093 SYMBOL_VALUE (typedef_sym
) = valu
;
1094 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
1095 add_symbol_to_list (typedef_sym
, &file_symbols
);
1100 /* Static symbol of local scope */
1101 SYMBOL_CLASS (sym
) = LOC_STATIC
;
1102 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
1103 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1104 add_symbol_to_list (sym
, &local_symbols
);
1108 /* Reference parameter */
1109 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
1110 SYMBOL_VALUE (sym
) = valu
;
1111 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1112 add_symbol_to_list (sym
, &local_symbols
);
1116 /* This is used by Sun FORTRAN for "function result value".
1117 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
1118 that Pascal uses it too, but when I tried it Pascal used
1119 "x:3" (local symbol) instead. */
1120 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
1121 SYMBOL_VALUE (sym
) = valu
;
1122 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
1123 add_symbol_to_list (sym
, &local_symbols
);
1127 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
1132 /* What about types defined as forward references inside of a small lexical
1134 /* Add a type to the list of undefined types to be checked through
1135 once this file has been read in. */
1137 add_undefined_type (type
)
1140 if (undef_types_length
== undef_types_allocated
)
1142 undef_types_allocated
*= 2;
1143 undef_types
= (struct type
**)
1144 xrealloc (undef_types
,
1145 undef_types_allocated
* sizeof (struct type
*));
1147 undef_types
[undef_types_length
++] = type
;
1150 /* Add here something to go through each undefined type, see if it's
1151 still undefined, and do a full lookup if so. */
1153 cleanup_undefined_types ()
1157 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
1159 /* Reasonable test to see if it's been defined since. */
1160 if (TYPE_NFIELDS (*type
) == 0)
1162 struct pending
*ppt
;
1164 /* Name of the type, without "struct" or "union" */
1165 char *typename
= TYPE_NAME (*type
);
1167 if (!strncmp (typename
, "struct ", 7))
1169 if (!strncmp (typename
, "union ", 6))
1172 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1173 for (i
= 0; i
< ppt
->nsyms
; i
++)
1175 struct symbol
*sym
= ppt
->symbol
[i
];
1177 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1178 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1179 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
1181 && !strcmp (SYMBOL_NAME (sym
), typename
))
1182 bcopy (SYMBOL_TYPE (sym
), *type
, sizeof (struct type
));
1186 /* It has been defined; don't mark it as a stub. */
1187 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
1189 undef_types_length
= 0;
1192 /* Skip rest of this symbol and return an error type.
1194 General notes on error recovery: error_type always skips to the
1195 end of the symbol (modulo cretinous dbx symbol name continuation).
1196 Thus code like this:
1198 if (*(*pp)++ != ';')
1199 return error_type (pp);
1201 is wrong because if *pp starts out pointing at '\0' (typically as the
1202 result of an earlier error), it will be incremented to point to the
1203 start of the next symbol, which might produce strange results, at least
1204 if you run off the end of the string table. Instead use
1207 return error_type (pp);
1213 foo = error_type (pp);
1217 And in case it isn't obvious, the point of all this hair is so the compiler
1218 can define new types and new syntaxes, and old versions of the
1219 debugger will be able to read the new symbol tables. */
1225 complain (&error_type_complaint
, 0);
1228 /* Skip to end of symbol. */
1229 while (**pp
!= '\0')
1232 /* Check for and handle cretinous dbx symbol name continuation! */
1233 if ((*pp
)[-1] == '\\')
1234 *pp
= next_symbol_text ();
1238 return builtin_type_error
;
1241 /* Read a dbx type reference or definition;
1242 return the type that is meant.
1243 This can be just a number, in which case it references
1244 a type already defined and placed in type_vector.
1245 Or the number can be followed by an =, in which case
1246 it means to define a new type according to the text that
1253 register struct type
*type
= 0;
1258 /* Read type number if present. The type number may be omitted.
1259 for instance in a two-dimensional array declared with type
1260 "ar1;1;10;ar1;1;10;4". */
1261 if ((**pp
>= '0' && **pp
<= '9')
1264 read_type_number (pp
, typenums
);
1266 /* Detect random reference to type not yet defined.
1267 Allocate a type object but leave it zeroed. */
1269 return dbx_alloc_type (typenums
);
1275 /* 'typenums=' not present, type is anonymous. Read and return
1276 the definition, but don't put it in the type vector. */
1277 typenums
[0] = typenums
[1] = -1;
1285 enum type_code code
;
1287 /* Used to index through file_symbols. */
1288 struct pending
*ppt
;
1291 /* Name including "struct", etc. */
1294 /* Name without "struct", etc. */
1295 char *type_name_only
;
1301 /* Set the type code according to the following letter. */
1305 code
= TYPE_CODE_STRUCT
;
1309 code
= TYPE_CODE_UNION
;
1313 code
= TYPE_CODE_ENUM
;
1317 return error_type (pp
);
1320 to
= type_name
= (char *)
1321 obstack_alloc (symbol_obstack
,
1323 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
1325 /* Copy the prefix. */
1327 while (*to
++ = *from
++)
1331 type_name_only
= to
;
1333 /* Copy the name. */
1335 while ((*to
++ = *from
++) != ':')
1339 /* Set the pointer ahead of the name which we just read. */
1343 /* The following hack is clearly wrong, because it doesn't
1344 check whether we are in a baseclass. I tried to reproduce
1345 the case that it is trying to fix, but I couldn't get
1346 g++ to put out a cross reference to a basetype. Perhaps
1347 it doesn't do it anymore. */
1348 /* Note: for C++, the cross reference may be to a base type which
1349 has not yet been seen. In this case, we skip to the comma,
1350 which will mark the end of the base class name. (The ':'
1351 at the end of the base class name will be skipped as well.)
1352 But sometimes (ie. when the cross ref is the last thing on
1353 the line) there will be no ','. */
1354 from
= (char *) strchr (*pp
, ',');
1360 /* Now check to see whether the type has already been declared. */
1361 /* This is necessary at least in the case where the
1362 program says something like
1364 The compiler puts out a cross-reference; we better find
1365 set the length of the structure correctly so we can
1366 set the length of the array. */
1367 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
1368 for (i
= 0; i
< ppt
->nsyms
; i
++)
1370 struct symbol
*sym
= ppt
->symbol
[i
];
1372 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
1373 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
1374 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
1375 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
1377 obstack_free (symbol_obstack
, type_name
);
1378 type
= SYMBOL_TYPE (sym
);
1383 /* Didn't find the type to which this refers, so we must
1384 be dealing with a forward reference. Allocate a type
1385 structure for it, and keep track of it so we can
1386 fill in the rest of the fields when we get the full
1388 type
= dbx_alloc_type (typenums
);
1389 TYPE_CODE (type
) = code
;
1390 TYPE_NAME (type
) = type_name
;
1392 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
1394 add_undefined_type (type
);
1410 read_type_number (pp
, xtypenums
);
1411 type
= *dbx_lookup_type (xtypenums
);
1413 type
= builtin_type_void
;
1414 if (typenums
[0] != -1)
1415 *dbx_lookup_type (typenums
) = type
;
1419 type1
= read_type (pp
);
1420 type
= lookup_pointer_type (type1
);
1421 if (typenums
[0] != -1)
1422 *dbx_lookup_type (typenums
) = type
;
1427 struct type
*domain
= read_type (pp
);
1428 struct type
*memtype
;
1431 /* Invalid member type data format. */
1432 return error_type (pp
);
1435 memtype
= read_type (pp
);
1436 type
= dbx_alloc_type (typenums
);
1437 smash_to_member_type (type
, domain
, memtype
);
1442 if ((*pp
)[0] == '#')
1444 /* We'll get the parameter types from the name. */
1445 struct type
*return_type
;
1448 return_type
= read_type (pp
);
1449 if (*(*pp
)++ != ';')
1450 complain (&invalid_member_complaint
, symnum
);
1451 type
= allocate_stub_method (return_type
);
1452 if (typenums
[0] != -1)
1453 *dbx_lookup_type (typenums
) = type
;
1457 struct type
*domain
= read_type (pp
);
1458 struct type
*return_type
;
1461 if (*(*pp
)++ != ',')
1462 error ("invalid member type data format, at symtab pos %d.",
1465 return_type
= read_type (pp
);
1466 args
= read_args (pp
, ';');
1467 type
= dbx_alloc_type (typenums
);
1468 smash_to_method_type (type
, domain
, return_type
, args
);
1473 type1
= read_type (pp
);
1474 type
= lookup_reference_type (type1
);
1475 if (typenums
[0] != -1)
1476 *dbx_lookup_type (typenums
) = type
;
1480 type1
= read_type (pp
);
1481 type
= lookup_function_type (type1
);
1482 if (typenums
[0] != -1)
1483 *dbx_lookup_type (typenums
) = type
;
1487 type
= read_range_type (pp
, typenums
);
1488 if (typenums
[0] != -1)
1489 *dbx_lookup_type (typenums
) = type
;
1493 type
= dbx_alloc_type (typenums
);
1494 type
= read_enum_type (pp
, type
);
1495 *dbx_lookup_type (typenums
) = type
;
1499 type
= dbx_alloc_type (typenums
);
1500 TYPE_NAME (type
) = type_synonym_name
;
1501 type_synonym_name
= 0;
1502 type
= read_struct_type (pp
, type
);
1506 type
= dbx_alloc_type (typenums
);
1507 TYPE_NAME (type
) = type_synonym_name
;
1508 type_synonym_name
= 0;
1509 type
= read_struct_type (pp
, type
);
1510 TYPE_CODE (type
) = TYPE_CODE_UNION
;
1515 return error_type (pp
);
1518 type
= dbx_alloc_type (typenums
);
1519 type
= read_array_type (pp
, type
);
1523 --*pp
; /* Go back to the symbol in error */
1524 /* Particularly important if it was \0! */
1525 return error_type (pp
);
1532 /* If this is an overriding temporary alteration for a header file's
1533 contents, and this type number is unknown in the global definition,
1534 put this type into the global definition at this type number. */
1535 if (header_file_prev_index
>= 0)
1537 register struct type
**tp
1538 = explicit_lookup_type (header_file_prev_index
, typenums
[1]);
1546 /* This page contains subroutines of read_type. */
1548 /* Read the description of a structure (or union type)
1549 and return an object describing the type. */
1552 read_struct_type (pp
, type
)
1554 register struct type
*type
;
1556 /* Total number of methods defined in this class.
1557 If the class defines two `f' methods, and one `g' method,
1558 then this will have the value 3. */
1559 int total_length
= 0;
1563 struct nextfield
*next
;
1564 int visibility
; /* 0=public, 1=protected, 2=public */
1570 struct next_fnfield
*next
;
1571 int visibility
; /* 0=public, 1=protected, 2=public */
1572 struct fn_field fn_field
;
1575 struct next_fnfieldlist
1577 struct next_fnfieldlist
*next
;
1578 struct fn_fieldlist fn_fieldlist
;
1581 register struct nextfield
*list
= 0;
1582 struct nextfield
*new;
1587 register struct next_fnfieldlist
*mainlist
= 0;
1590 if (TYPE_MAIN_VARIANT (type
) == 0)
1592 TYPE_MAIN_VARIANT (type
) = type
;
1595 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
1597 /* First comes the total size in bytes. */
1599 TYPE_LENGTH (type
) = read_number (pp
, 0);
1601 /* C++: Now, if the class is a derived class, then the next character
1602 will be a '!', followed by the number of base classes derived from.
1603 Each element in the list contains visibility information,
1604 the offset of this base class in the derived structure,
1605 and then the base type. */
1608 int i
, n_baseclasses
, offset
;
1609 struct type
*baseclass
;
1612 /* Nonzero if it is a virtual baseclass, i.e.,
1616 struct C : public B, public virtual A {};
1618 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
1619 2.0 language feature. */
1624 n_baseclasses
= read_number (pp
, ',');
1625 TYPE_FIELD_VIRTUAL_BITS (type
) =
1626 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (n_baseclasses
));
1627 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
1629 for (i
= 0; i
< n_baseclasses
; i
++)
1632 *pp
= next_symbol_text ();
1643 /* Bad visibility format. */
1644 return error_type (pp
);
1657 /* Bad visibility format. */
1658 return error_type (pp
);
1661 SET_TYPE_FIELD_VIRTUAL (type
, i
);
1664 /* Offset of the portion of the object corresponding to
1665 this baseclass. Always zero in the absence of
1666 multiple inheritance. */
1667 offset
= read_number (pp
, ',');
1668 baseclass
= read_type (pp
);
1669 *pp
+= 1; /* skip trailing ';' */
1671 /* Make this baseclass visible for structure-printing purposes. */
1672 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1675 list
->visibility
= via_public
;
1676 list
->field
.type
= baseclass
;
1677 list
->field
.name
= type_name_no_tag (baseclass
);
1678 list
->field
.bitpos
= offset
;
1679 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
1682 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
1685 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
1686 At the end, we see a semicolon instead of a field.
1688 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
1691 The `?' is a placeholder for one of '/2' (public visibility),
1692 '/1' (protected visibility), '/0' (private visibility), or nothing
1693 (C style symbol table, public visibility). */
1695 /* We better set p right now, in case there are no fields at all... */
1700 /* Check for and handle cretinous dbx symbol name continuation! */
1701 if (**pp
== '\\') *pp
= next_symbol_text ();
1703 /* Get space to record the next field's data. */
1704 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
1708 /* Get the field name. */
1710 if (*p
== CPLUS_MARKER
)
1712 /* Special GNU C++ name. */
1717 struct type
*context
;
1728 error ("invalid abbreviation at symtab pos %d.", symnum
);
1731 context
= read_type (pp
);
1732 if (type_name_no_tag (context
) == 0)
1735 error ("type name unknown at symtab pos %d.", symnum
);
1736 /* FIXME-tiemann: when is `name' ever non-0? */
1737 TYPE_NAME (context
) = obsavestring (name
, p
- name
- 1);
1739 list
->field
.name
= obconcat (prefix
, type_name_no_tag (context
), "");
1742 error ("invalid abbreviation at symtab pos %d.", symnum
);
1743 list
->field
.type
= read_type (pp
);
1744 (*pp
)++; /* Skip the comma. */
1745 list
->field
.bitpos
= read_number (pp
, ';');
1746 /* This field is unpacked. */
1747 list
->field
.bitsize
= 0;
1749 /* GNU C++ anonymous type. */
1753 error ("invalid abbreviation at symtab pos %d.", symnum
);
1759 while (*p
!= ':') p
++;
1760 list
->field
.name
= obsavestring (*pp
, p
- *pp
);
1762 /* C++: Check to see if we have hit the methods yet. */
1768 /* This means we have a visibility for a field coming. */
1774 list
->visibility
= 0; /* private */
1779 list
->visibility
= 1; /* protected */
1784 list
->visibility
= 2; /* public */
1789 else /* normal dbx-style format. */
1790 list
->visibility
= 2; /* public */
1792 list
->field
.type
= read_type (pp
);
1795 /* Static class member. */
1796 list
->field
.bitpos
= (long)-1;
1798 while (*p
!= ';') p
++;
1799 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
1804 else if (**pp
!= ',')
1805 /* Bad structure-type format. */
1806 return error_type (pp
);
1808 (*pp
)++; /* Skip the comma. */
1809 list
->field
.bitpos
= read_number (pp
, ',');
1810 list
->field
.bitsize
= read_number (pp
, ';');
1813 /* FIXME-tiemann: Can't the compiler put out something which
1814 lets us distinguish these? (or maybe just not put out anything
1815 for the field). What is the story here? What does the compiler
1816 really do? Also, patch gdb.texinfo for this case; I document
1817 it as a possible problem there. Search for "DBX-style". */
1819 /* This is wrong because this is identical to the symbols
1820 produced for GCC 0-size arrays. For example:
1825 The code which dumped core in such circumstances should be
1826 fixed not to dump core. */
1828 /* g++ -g0 can put out bitpos & bitsize zero for a static
1829 field. This does not give us any way of getting its
1830 class, so we can't know its name. But we can just
1831 ignore the field so we don't dump core and other nasty
1833 if (list
->field
.bitpos
== 0
1834 && list
->field
.bitsize
== 0)
1836 complain (&dbx_class_complaint
, 0);
1837 /* Ignore this field. */
1843 /* Detect an unpacked field and mark it as such.
1844 dbx gives a bit size for all fields.
1845 Note that forward refs cannot be packed,
1846 and treat enums as if they had the width of ints. */
1847 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
1848 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
1849 list
->field
.bitsize
= 0;
1850 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
1851 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
1852 && (list
->field
.bitsize
1853 == 8 * TYPE_LENGTH (builtin_type_int
))
1857 list
->field
.bitpos
% 8 == 0)
1858 list
->field
.bitsize
= 0;
1864 /* chill the list of fields: the last entry (at the head)
1865 is a partially constructed entry which we now scrub. */
1868 /* Now create the vector of fields, and record how big it is.
1869 We need this info to record proper virtual function table information
1870 for this class's virtual functions. */
1872 TYPE_NFIELDS (type
) = nfields
;
1873 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
,
1874 sizeof (struct field
) * nfields
);
1876 TYPE_FIELD_PRIVATE_BITS (type
) =
1877 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
1878 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
1880 TYPE_FIELD_PROTECTED_BITS (type
) =
1881 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
1882 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
1884 /* Copy the saved-up fields into the field vector. */
1886 for (n
= nfields
; list
; list
= list
->next
)
1889 TYPE_FIELD (type
, n
) = list
->field
;
1890 if (list
->visibility
== 0)
1891 SET_TYPE_FIELD_PRIVATE (type
, n
);
1892 else if (list
->visibility
== 1)
1893 SET_TYPE_FIELD_PROTECTED (type
, n
);
1896 /* Now come the method fields, as NAME::methods
1897 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
1898 At the end, we see a semicolon instead of a field.
1900 For the case of overloaded operators, the format is
1901 OPERATOR::*.methods, where OPERATOR is the string "operator",
1902 `*' holds the place for an operator name (such as `+=')
1903 and `.' marks the end of the operator name. */
1906 /* Now, read in the methods. To simplify matters, we
1907 "unread" the name that has been read, so that we can
1908 start from the top. */
1910 /* For each list of method lists... */
1914 struct next_fnfield
*sublist
= 0;
1915 struct type
*look_ahead_type
= NULL
;
1917 struct next_fnfieldlist
*new_mainlist
=
1918 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
1923 /* read in the name. */
1924 while (*p
!= ':') p
++;
1925 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
1927 /* This lets the user type "break operator+".
1928 We could just put in "+" as the name, but that wouldn't
1930 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
1931 char *o
= opname
+ 3;
1933 /* Skip past '::'. */
1937 main_fn_name
= savestring (opname
, o
- opname
);
1944 main_fn_name
= savestring (*pp
, p
- *pp
);
1945 /* Skip past '::'. */
1948 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
1952 struct next_fnfield
*new_sublist
=
1953 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
1955 /* Check for and handle cretinous dbx symbol name continuation! */
1956 if (look_ahead_type
== NULL
) /* Normal case. */
1958 if (**pp
== '\\') *pp
= next_symbol_text ();
1960 new_sublist
->fn_field
.type
= read_type (pp
);
1962 /* Invalid symtab info for method. */
1963 return error_type (pp
);
1966 { /* g++ version 1 kludge */
1967 new_sublist
->fn_field
.type
= look_ahead_type
;
1968 look_ahead_type
= NULL
;
1973 while (*p
!= ';') p
++;
1974 /* If this is just a stub, then we don't have the
1976 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
1978 new_sublist
->visibility
= *(*pp
)++ - '0';
1979 if (**pp
== '\\') *pp
= next_symbol_text ();
1982 case 'A': /* Normal functions. */
1983 new_sublist
->fn_field
.is_const
= 0;
1984 new_sublist
->fn_field
.is_volatile
= 0;
1987 case 'B': /* `const' member functions. */
1988 new_sublist
->fn_field
.is_const
= 1;
1989 new_sublist
->fn_field
.is_volatile
= 0;
1992 case 'C': /* `volatile' member function. */
1993 new_sublist
->fn_field
.is_const
= 0;
1994 new_sublist
->fn_field
.is_volatile
= 1;
1997 case 'D': /* `const volatile' member function. */
1998 new_sublist
->fn_field
.is_const
= 1;
1999 new_sublist
->fn_field
.is_volatile
= 1;
2003 /* This probably just means we're processing a file compiled
2004 with g++ version 1. */
2005 complain(&const_vol_complaint
, **pp
);
2011 /* virtual member function, followed by index. */
2012 /* The sign bit is set to distinguish pointers-to-methods
2013 from virtual function indicies. Since the array is
2014 in words, the quantity must be shifted left by 1
2015 on 16 bit machine, and by 2 on 32 bit machine, forcing
2016 the sign bit out, and usable as a valid index into
2017 the array. Remove the sign bit here. */
2018 new_sublist
->fn_field
.voffset
=
2019 (0x7fffffff & read_number (pp
, ';')) + 2;
2021 if (**pp
== '\\') *pp
= next_symbol_text ();
2023 if (**pp
== ';' || **pp
== '\0')
2024 /* Must be g++ version 1. */
2025 new_sublist
->fn_field
.fcontext
= 0;
2028 /* Figure out from whence this virtual function came.
2029 It may belong to virtual function table of
2030 one of its baseclasses. */
2031 look_ahead_type
= read_type (pp
);
2033 { /* g++ version 1 overloaded methods. */ }
2036 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
2038 return error_type (pp
);
2041 look_ahead_type
= NULL
;
2047 /* static member function. */
2048 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
2052 /* normal member function. */
2053 new_sublist
->fn_field
.voffset
= 0;
2054 new_sublist
->fn_field
.fcontext
= 0;
2058 new_sublist
->next
= sublist
;
2059 sublist
= new_sublist
;
2061 if (**pp
== '\\') *pp
= next_symbol_text ();
2063 while (**pp
!= ';' && **pp
!= '\0');
2067 new_mainlist
->fn_fieldlist
.fn_fields
=
2068 (struct fn_field
*) obstack_alloc (symbol_obstack
,
2069 sizeof (struct fn_field
) * length
);
2070 TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
) =
2071 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
2072 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
), length
);
2074 TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
) =
2075 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
2076 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
), length
);
2078 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
2080 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
2081 if (sublist
->visibility
== 0)
2082 B_SET (new_mainlist
->fn_fieldlist
.private_fn_field_bits
, i
);
2083 else if (sublist
->visibility
== 1)
2084 B_SET (new_mainlist
->fn_fieldlist
.protected_fn_field_bits
, i
);
2087 new_mainlist
->fn_fieldlist
.length
= length
;
2088 new_mainlist
->next
= mainlist
;
2089 mainlist
= new_mainlist
;
2091 total_length
+= length
;
2093 while (**pp
!= ';');
2098 TYPE_FN_FIELDLISTS (type
) =
2099 (struct fn_fieldlist
*) obstack_alloc (symbol_obstack
,
2100 sizeof (struct fn_fieldlist
) * nfn_fields
);
2102 TYPE_NFN_FIELDS (type
) = nfn_fields
;
2103 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
2107 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
2108 TYPE_NFN_FIELDS_TOTAL (type
) +=
2109 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
2112 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
)
2113 TYPE_FN_FIELDLISTS (type
)[--n
] = mainlist
->fn_fieldlist
;
2122 |= TYPE_FLAG_HAS_CONSTRUCTOR
| TYPE_FLAG_HAS_DESTRUCTOR
;
2125 else if (**pp
== '+')
2127 TYPE_FLAGS (type
) |= TYPE_FLAG_HAS_CONSTRUCTOR
;
2130 else if (**pp
== '-')
2132 TYPE_FLAGS (type
) |= TYPE_FLAG_HAS_DESTRUCTOR
;
2136 /* Read either a '%' or the final ';'. */
2137 if (*(*pp
)++ == '%')
2139 /* Now we must record the virtual function table pointer's
2140 field information. */
2147 while (*p
!= '\0' && *p
!= ';')
2150 /* Premature end of symbol. */
2151 return error_type (pp
);
2153 TYPE_VPTR_BASETYPE (type
) = t
;
2156 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
2158 /* FIXME-tiemann: what's this? */
2160 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
2165 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
2166 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
2167 sizeof (vptr_name
) -1))
2169 TYPE_VPTR_FIELDNO (type
) = i
;
2173 /* Virtual function table field not found. */
2174 return error_type (pp
);
2177 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
2185 /* Read a definition of an array type,
2186 and create and return a suitable type object.
2187 Also creates a range type which represents the bounds of that
2190 read_array_type (pp
, type
)
2192 register struct type
*type
;
2194 struct type
*index_type
, *element_type
, *range_type
;
2198 /* Format of an array type:
2199 "ar<index type>;lower;upper;<array_contents_type>". Put code in
2202 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
2203 for these, produce a type like float[][]. */
2205 index_type
= read_type (pp
);
2207 /* Improper format of array type decl. */
2208 return error_type (pp
);
2211 if (!(**pp
>= '0' && **pp
<= '9'))
2216 lower
= read_number (pp
, ';');
2218 if (!(**pp
>= '0' && **pp
<= '9'))
2223 upper
= read_number (pp
, ';');
2225 element_type
= read_type (pp
);
2234 /* Create range type. */
2235 range_type
= (struct type
*) obstack_alloc (symbol_obstack
,
2236 sizeof (struct type
));
2237 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
2238 TYPE_TARGET_TYPE (range_type
) = index_type
;
2240 /* This should never be needed. */
2241 TYPE_LENGTH (range_type
) = sizeof (int);
2243 TYPE_NFIELDS (range_type
) = 2;
2244 TYPE_FIELDS (range_type
) =
2245 (struct field
*) obstack_alloc (symbol_obstack
,
2246 2 * sizeof (struct field
));
2247 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
2248 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
2251 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
2252 TYPE_TARGET_TYPE (type
) = element_type
;
2253 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
2254 TYPE_NFIELDS (type
) = 1;
2255 TYPE_FIELDS (type
) =
2256 (struct field
*) obstack_alloc (symbol_obstack
,
2257 sizeof (struct field
));
2258 TYPE_FIELD_TYPE (type
, 0) = range_type
;
2264 /* Read a definition of an enumeration type,
2265 and create and return a suitable type object.
2266 Also defines the symbols that represent the values of the type. */
2269 read_enum_type (pp
, type
)
2271 register struct type
*type
;
2276 register struct symbol
*sym
;
2278 struct pending
**symlist
;
2279 struct pending
*osyms
, *syms
;
2282 if (within_function
)
2283 symlist
= &local_symbols
;
2285 symlist
= &file_symbols
;
2287 o_nsyms
= osyms
? osyms
->nsyms
: 0;
2289 /* Read the value-names and their values.
2290 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
2291 A semicolon or comman instead of a NAME means the end. */
2292 while (**pp
&& **pp
!= ';' && **pp
!= ',')
2294 /* Check for and handle cretinous dbx symbol name continuation! */
2295 if (**pp
== '\\') *pp
= next_symbol_text ();
2298 while (*p
!= ':') p
++;
2299 name
= obsavestring (*pp
, p
- *pp
);
2301 n
= read_number (pp
, ',');
2303 sym
= (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
2304 bzero (sym
, sizeof (struct symbol
));
2305 SYMBOL_NAME (sym
) = name
;
2306 SYMBOL_CLASS (sym
) = LOC_CONST
;
2307 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
2308 SYMBOL_VALUE (sym
) = n
;
2309 add_symbol_to_list (sym
, symlist
);
2314 (*pp
)++; /* Skip the semicolon. */
2316 /* Now fill in the fields of the type-structure. */
2318 TYPE_LENGTH (type
) = sizeof (int);
2319 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
2320 TYPE_NFIELDS (type
) = nsyms
;
2321 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
2323 /* Find the symbols for the values and put them into the type.
2324 The symbols can be found in the symlist that we put them on
2325 to cause them to be defined. osyms contains the old value
2326 of that symlist; everything up to there was defined by us. */
2327 /* Note that we preserve the order of the enum constants, so
2328 that in something like "enum {FOO, LAST_THING=FOO}" we print
2329 FOO, not LAST_THING. */
2331 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
2336 for (; j
< syms
->nsyms
; j
++,n
++)
2338 struct symbol
*xsym
= syms
->symbol
[j
];
2339 SYMBOL_TYPE (xsym
) = type
;
2340 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
2341 TYPE_FIELD_VALUE (type
, n
) = 0;
2342 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
2343 TYPE_FIELD_BITSIZE (type
, n
) = 0;
2350 /* This screws up perfectly good C programs with enums. FIXME. */
2351 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
2352 if(TYPE_NFIELDS(type
) == 2 &&
2353 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
2354 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
2355 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
2356 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
2357 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
2363 /* Read a number from the string pointed to by *PP.
2364 The value of *PP is advanced over the number.
2365 If END is nonzero, the character that ends the
2366 number must match END, or an error happens;
2367 and that character is skipped if it does match.
2368 If END is zero, *PP is left pointing to that character.
2370 If the number fits in a long, set *VALUE and set *BITS to 0.
2371 If not, set *BITS to be the number of bits in the number.
2373 If encounter garbage, set *BITS to -1. */
2376 read_huge_number (pp
, end
, valu
, bits
)
2397 /* Leading zero means octal. GCC uses this to output values larger
2398 than an int (because that would be hard in decimal). */
2405 upper_limit
= LONG_MAX
/ radix
;
2406 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
2408 if (n
<= upper_limit
)
2411 n
+= c
- '0'; /* FIXME this overflows anyway */
2416 /* This depends on large values being output in octal, which is
2423 /* Ignore leading zeroes. */
2427 else if (c
== '2' || c
== '3')
2453 /* Large decimal constants are an error (because it is hard to
2454 count how many bits are in them). */
2460 /* -0x7f is the same as 0x80. So deal with it by adding one to
2461 the number of bits. */
2476 #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
2477 #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
2480 read_range_type (pp
, typenums
)
2488 struct type
*result_type
;
2490 /* First comes a type we are a subrange of.
2491 In C it is usually 0, 1 or the type being defined. */
2492 read_type_number (pp
, rangenums
);
2493 self_subrange
= (rangenums
[0] == typenums
[0] &&
2494 rangenums
[1] == typenums
[1]);
2496 /* A semicolon should now follow; skip it. */
2500 /* The remaining two operands are usually lower and upper bounds
2501 of the range. But in some special cases they mean something else. */
2502 read_huge_number (pp
, ';', &n2
, &n2bits
);
2503 read_huge_number (pp
, ';', &n3
, &n3bits
);
2505 if (n2bits
== -1 || n3bits
== -1)
2506 return error_type (pp
);
2508 /* If limits are huge, must be large integral type. */
2509 if (n2bits
!= 0 || n3bits
!= 0)
2511 char got_signed
= 0;
2512 char got_unsigned
= 0;
2513 /* Number of bits in the type. */
2516 /* Range from 0 to <large number> is an unsigned large integral type. */
2517 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
2522 /* Range from <large number> to <large number>-1 is a large signed
2524 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
2530 /* Check for "long long". */
2531 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
2532 return builtin_type_long_long
;
2533 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
2534 return builtin_type_unsigned_long_long
;
2536 if (got_signed
|| got_unsigned
)
2538 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
2539 sizeof (struct type
));
2540 bzero (result_type
, sizeof (struct type
));
2541 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
2542 TYPE_MAIN_VARIANT (result_type
) = result_type
;
2543 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
2545 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
2549 return error_type (pp
);
2552 /* A type defined as a subrange of itself, with bounds both 0, is void. */
2553 if (self_subrange
&& n2
== 0 && n3
== 0)
2554 return builtin_type_void
;
2556 /* If n3 is zero and n2 is not, we want a floating type,
2557 and n2 is the width in bytes.
2559 Fortran programs appear to use this for complex types also,
2560 and they give no way to distinguish between double and single-complex!
2561 We don't have complex types, so we would lose on all fortran files!
2562 So return type `double' for all of those. It won't work right
2563 for the complex values, but at least it makes the file loadable. */
2565 if (n3
== 0 && n2
> 0)
2567 if (n2
== sizeof (float))
2568 return builtin_type_float
;
2569 return builtin_type_double
;
2572 /* If the upper bound is -1, it must really be an unsigned int. */
2574 else if (n2
== 0 && n3
== -1)
2576 if (sizeof (int) == sizeof (long))
2577 return builtin_type_unsigned_int
;
2579 return builtin_type_unsigned_long
;
2582 /* Special case: char is defined (Who knows why) as a subrange of
2583 itself with range 0-127. */
2584 else if (self_subrange
&& n2
== 0 && n3
== 127)
2585 return builtin_type_char
;
2587 /* Assumptions made here: Subrange of self is equivalent to subrange
2590 && (self_subrange
||
2591 *dbx_lookup_type (rangenums
) == builtin_type_int
))
2593 /* an unsigned type */
2595 if (n3
== - sizeof (long long))
2596 return builtin_type_unsigned_long_long
;
2598 if (n3
== (unsigned int)~0L)
2599 return builtin_type_unsigned_int
;
2600 if (n3
== (unsigned long)~0L)
2601 return builtin_type_unsigned_long
;
2602 if (n3
== (unsigned short)~0L)
2603 return builtin_type_unsigned_short
;
2604 if (n3
== (unsigned char)~0L)
2605 return builtin_type_unsigned_char
;
2608 else if (n3
== 0 && n2
== -sizeof (long long))
2609 return builtin_type_long_long
;
2611 else if (n2
== -n3
-1)
2614 if (n3
== (1 << (8 * sizeof (int) - 1)) - 1)
2615 return builtin_type_int
;
2616 if (n3
== (1 << (8 * sizeof (long) - 1)) - 1)
2617 return builtin_type_long
;
2618 if (n3
== (1 << (8 * sizeof (short) - 1)) - 1)
2619 return builtin_type_short
;
2620 if (n3
== (1 << (8 * sizeof (char) - 1)) - 1)
2621 return builtin_type_char
;
2624 /* We have a real range type on our hands. Allocate space and
2625 return a real pointer. */
2627 /* At this point I don't have the faintest idea how to deal with
2628 a self_subrange type; I'm going to assume that this is used
2629 as an idiom, and that all of them are special cases. So . . . */
2631 return error_type (pp
);
2633 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
2634 sizeof (struct type
));
2635 bzero (result_type
, sizeof (struct type
));
2637 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
2639 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
2640 if (TYPE_TARGET_TYPE (result_type
) == 0) {
2641 complain (&range_type_base_complaint
, rangenums
[1]);
2642 TYPE_TARGET_TYPE (result_type
) = builtin_type_int
;
2645 TYPE_NFIELDS (result_type
) = 2;
2646 TYPE_FIELDS (result_type
) =
2647 (struct field
*) obstack_alloc (symbol_obstack
,
2648 2 * sizeof (struct field
));
2649 bzero (TYPE_FIELDS (result_type
), 2 * sizeof (struct field
));
2650 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
2651 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
2654 /* Note that TYPE_LENGTH (result_type) is just overridden a few
2655 statements down. What do we really need here? */
2656 /* We have to figure out how many bytes it takes to hold this
2657 range type. I'm going to assume that anything that is pushing
2658 the bounds of a long was taken care of above. */
2659 if (n2
>= MIN_OF_C_TYPE(char) && n3
<= MAX_OF_C_TYPE(char))
2660 TYPE_LENGTH (result_type
) = 1;
2661 else if (n2
>= MIN_OF_C_TYPE(short) && n3
<= MAX_OF_C_TYPE(short))
2662 TYPE_LENGTH (result_type
) = sizeof (short);
2663 else if (n2
>= MIN_OF_C_TYPE(int) && n3
<= MAX_OF_C_TYPE(int))
2664 TYPE_LENGTH (result_type
) = sizeof (int);
2665 else if (n2
>= MIN_OF_C_TYPE(long) && n3
<= MAX_OF_C_TYPE(long))
2666 TYPE_LENGTH (result_type
) = sizeof (long);
2668 /* Ranged type doesn't fit within known sizes. */
2669 /* FIXME -- use "long long" here. */
2670 return error_type (pp
);
2673 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
2678 /* Read a number from the string pointed to by *PP.
2679 The value of *PP is advanced over the number.
2680 If END is nonzero, the character that ends the
2681 number must match END, or an error happens;
2682 and that character is skipped if it does match.
2683 If END is zero, *PP is left pointing to that character. */
2686 read_number (pp
, end
)
2690 register char *p
= *pp
;
2691 register long n
= 0;
2695 /* Handle an optional leading minus sign. */
2703 /* Read the digits, as far as they go. */
2705 while ((c
= *p
++) >= '0' && c
<= '9')
2713 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
2722 /* Read in an argument list. This is a list of types, separated by commas
2723 and terminated with END. Return the list of types read in, or (struct type
2724 **)-1 if there is an error. */
2730 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
2736 /* Invalid argument list: no ','. */
2737 return (struct type
**)-1;
2740 /* Check for and handle cretinous dbx symbol name continuation! */
2742 *pp
= next_symbol_text ();
2744 types
[n
++] = read_type (pp
);
2746 *pp
+= 1; /* get past `end' (the ':' character) */
2750 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
2752 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
2754 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
2755 bzero (rval
+ n
, sizeof (struct type
*));
2759 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
2761 bcopy (types
, rval
, n
* sizeof (struct type
*));
2765 /* Add a common block's start address to the offset of each symbol
2766 declared to be in it (by being between a BCOMM/ECOMM pair that uses
2767 the common block name). */
2770 fix_common_block (sym
, valu
)
2774 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
2775 for ( ; next
; next
= next
->next
)
2778 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
2779 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
2783 /* Initializer for this module */
2785 _initialize_buildsym ()
2787 undef_types_allocated
= 20;
2788 undef_types_length
= 0;
2789 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
2790 sizeof (struct type
*));