1 /* Read dbx symbol tables and convert to internal format, for GDB.
2 Copyright (C) 1986-1991 Free Software Foundation, Inc.
4 This file is part of GDB.
6 GDB 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 1, or (at your option)
11 GDB 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 GDB; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* Symbol read-in occurs in two phases:
21 1. A scan (read_dbx_symtab()) of the entire executable, whose sole
22 purpose is to make a list of symbols (partial symbol table)
23 which will cause symbols
24 to be read in if referenced. This scan happens when the
25 "symbol-file" command is given (symbol_file_command()).
26 1a. The "add-file" command. Similar to #1.
27 2. Full read-in of symbols. (dbx_psymtab_to_symtab()). This happens
28 when a symbol in a file for which symbols have not yet been
29 read in is referenced. */
31 /* There used to be some PROFILE_TYPES code in this file which counted
32 the number of occurances of various symbols. I'd suggest instead:
33 nm -ap foo | awk 'print $5' | sort | uniq -c
34 to print how many of each n_type, or something like
35 nm -ap foo | awk '$5 == "LSYM" {print $6 $7 $8 $9 $10 $11}' | \
37 {print substr($2,1,1)}' | sort | uniq -c
38 to print the number of each kind of symbol descriptor (i.e. the letter
47 #include <sys/types.h>
53 #include "a.out.gnu.h"
54 #include "stab.gnu.h" /* We always use GNU stabs, not native, now */
59 * Define specifically gnu symbols here.
62 /* The following type indicates the definition of a symbol as being
63 an indirect reference to another symbol. The other symbol
64 appears as an undefined reference, immediately following this symbol.
66 Indirection is asymmetrical. The other symbol's value will be used
67 to satisfy requests for the indirect symbol, but not vice versa.
68 If the other symbol does not have a definition, libraries will
69 be searched to find a definition. */
74 /* The following symbols refer to set elements.
75 All the N_SET[ATDB] symbols with the same name form one set.
76 Space is allocated for the set in the text section, and each set
77 element's value is stored into one word of the space.
78 The first word of the space is the length of the set (number of elements).
80 The address of the set is made into an N_SETV symbol
81 whose name is the same as the name of the set.
82 This symbol acts like a N_DATA global symbol
83 in that it can satisfy undefined external references. */
86 #define N_SETA 0x14 /* Absolute set element symbol */
87 #endif /* This is input to LD, in a .o file. */
90 #define N_SETT 0x16 /* Text set element symbol */
91 #endif /* This is input to LD, in a .o file. */
94 #define N_SETD 0x18 /* Data set element symbol */
95 #endif /* This is input to LD, in a .o file. */
98 #define N_SETB 0x1A /* Bss set element symbol */
99 #endif /* This is input to LD, in a .o file. */
101 /* Macros dealing with the set element symbols defined in a.out.h */
102 #define SET_ELEMENT_P(x) ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT))
103 #define TYPE_OF_SET_ELEMENT(x) ((x)-N_SETA+N_ABS)
106 #define N_SETV 0x1C /* Pointer to set vector in data area. */
107 #endif /* This is output from LD. */
110 #define N_WARNING 0x1E /* Warning message to print if file included */
111 #endif /* This is input to ld */
113 #endif /* NO_GNU_STABS */
116 #include <sys/param.h>
117 #include <sys/file.h>
118 #include <sys/stat.h>
120 #include "breakpoint.h"
123 #include "gdbcore.h" /* for bfd stuff */
124 #include "liba.out.h" /* FIXME Secret internal BFD stuff for a.out */
127 struct dbx_symfile_info
{
128 asection
*text_sect
; /* Text section accessor */
129 int symcount
; /* How many symbols are there in the file */
130 char *stringtab
; /* The actual string table */
131 int stringtab_size
; /* Its size */
132 off_t symtab_offset
; /* Offset in file to symbol table */
133 int desc
; /* File descriptor of symbol file */
136 extern void qsort ();
137 extern double atof ();
138 extern struct cmd_list_element
*cmdlist
;
140 extern void symbol_file_command ();
142 /* Forward declarations */
144 static void add_symbol_to_list ();
145 static void read_dbx_symtab ();
146 static void init_psymbol_list ();
147 static void process_one_symbol ();
148 static struct type
*read_type ();
149 static struct type
*read_range_type ();
150 static struct type
*read_enum_type ();
151 static struct type
*read_struct_type ();
152 static struct type
*read_array_type ();
153 static long read_number ();
154 static void finish_block ();
155 static struct blockvector
*make_blockvector ();
156 static struct symbol
*define_symbol ();
157 static void start_subfile ();
158 static int hashname ();
159 static struct pending
*copy_pending ();
160 static void fix_common_block ();
161 static void add_undefined_type ();
162 static void cleanup_undefined_types ();
163 static void scan_file_globals ();
164 static void read_ofile_symtab ();
165 static void dbx_psymtab_to_symtab ();
168 static struct type
**read_args ();
170 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
};
171 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
};
173 /* Macro to determine which symbols to ignore when reading the first symbol
174 of a file. Some machines override this definition. */
175 #ifndef IGNORE_SYMBOL
176 /* This code is used on Ultrix systems. Ignore it */
177 #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
180 /* Macro for name of symbol to indicate a file compiled with gcc. */
181 #ifndef GCC_COMPILED_FLAG_SYMBOL
182 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
185 /* Convert stab register number (from `r' declaration) to a gdb REGNUM. */
187 #ifndef STAB_REG_TO_REGNUM
188 #define STAB_REG_TO_REGNUM(VALUE) (VALUE)
191 /* Define this as 1 if a pcc declaration of a char or short argument
192 gives the correct address. Otherwise assume pcc gives the
193 address of the corresponding int, which is not the same on a
194 big-endian machine. */
196 #ifndef BELIEVE_PCC_PROMOTION
197 #define BELIEVE_PCC_PROMOTION 0
200 /* Nonzero means give verbose info on gdb action. From main.c. */
201 extern int info_verbose
;
203 /* Name of source file whose symbol data we are now processing.
204 This comes from a symbol of type N_SO. */
206 static char *last_source_file
;
208 /* Core address of start of text of current source file.
209 This too comes from the N_SO symbol. */
211 static CORE_ADDR last_source_start_addr
;
213 /* The entry point of a file we are reading. */
214 CORE_ADDR entry_point
;
216 /* The list of sub-source-files within the current individual compilation.
217 Each file gets its own symtab with its own linetable and associated info,
218 but they all share one blockvector. */
222 struct subfile
*next
;
225 struct linetable
*line_vector
;
226 int line_vector_length
;
227 int line_vector_index
;
228 int prev_line_number
;
231 static struct subfile
*subfiles
;
233 static struct subfile
*current_subfile
;
235 /* Count symbols as they are processed, for error messages. */
237 static unsigned int symnum
;
239 /* Vector of types defined so far, indexed by their dbx type numbers.
240 (In newer sun systems, dbx uses a pair of numbers in parens,
241 as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be
242 translated through the type_translations hash table to get
243 the index into the type vector.) */
245 static struct typevector
*type_vector
;
247 /* Number of elements allocated for type_vector currently. */
249 static int type_vector_length
;
251 /* Vector of line number information. */
253 static struct linetable
*line_vector
;
255 /* Index of next entry to go in line_vector_index. */
257 static int line_vector_index
;
259 /* Last line number recorded in the line vector. */
261 static int prev_line_number
;
263 /* Number of elements allocated for line_vector currently. */
265 static int line_vector_length
;
267 /* Hash table of global symbols whose values are not known yet.
268 They are chained thru the SYMBOL_VALUE_CHAIN, since we don't
269 have the correct data for that slot yet. */
270 /* The use of the LOC_BLOCK code in this chain is nonstandard--
271 it refers to a FORTRAN common block rather than the usual meaning. */
274 static struct symbol
*global_sym_chain
[HASHSIZE
];
276 /* Record the symbols defined for each context in a list.
277 We don't create a struct block for the context until we
278 know how long to make it. */
280 #define PENDINGSIZE 100
284 struct pending
*next
;
286 struct symbol
*symbol
[PENDINGSIZE
];
289 /* List of free `struct pending' structures for reuse. */
290 struct pending
*free_pendings
;
292 /* Here are the three lists that symbols are put on. */
294 struct pending
*file_symbols
; /* static at top level, and types */
296 struct pending
*global_symbols
; /* global functions and variables */
298 struct pending
*local_symbols
; /* everything local to lexical context */
300 /* List of symbols declared since the last BCOMM. This list is a tail
301 of local_symbols. When ECOMM is seen, the symbols on the list
302 are noted so their proper addresses can be filled in later,
303 using the common block base address gotten from the assembler
306 struct pending
*common_block
;
309 /* Stack representing unclosed lexical contexts
310 (that will become blocks, eventually). */
314 struct pending
*locals
;
315 struct pending_block
*old_blocks
;
317 CORE_ADDR start_addr
;
318 CORE_ADDR end_addr
; /* Temp slot for exception handling. */
322 struct context_stack
*context_stack
;
324 /* Index of first unused entry in context stack. */
325 int context_stack_depth
;
327 /* Currently allocated size of context stack. */
329 int context_stack_size
;
331 /* Nonzero if within a function (so symbols should be local,
332 if nothing says specifically). */
336 /* List of blocks already made (lexical contexts already closed).
337 This is used at the end to make the blockvector. */
341 struct pending_block
*next
;
345 struct pending_block
*pending_blocks
;
347 extern CORE_ADDR startup_file_start
; /* From blockframe.c */
348 extern CORE_ADDR startup_file_end
; /* From blockframe.c */
350 /* Global variable which, when set, indicates that we are processing a
351 .o file compiled with gcc */
353 static unsigned char processing_gcc_compilation
;
355 /* Make a list of forward references which haven't been defined. */
356 static struct type
**undef_types
;
357 static int undef_types_allocated
, undef_types_length
;
359 /* String table for the main symbol file. It is kept in memory
360 permanently, to speed up symbol reading. Other files' symbol tables
361 are read in on demand. FIXME, this should be cleaner. */
363 static char *symfile_string_table
;
364 static int symfile_string_table_size
;
366 /* Setup a define to deal cleanly with the underscore problem */
368 #ifdef NAMES_HAVE_UNDERSCORE
369 #define HASH_OFFSET 1
371 #define HASH_OFFSET 0
374 /* Complaints about the symbols we have encountered. */
376 struct complaint innerblock_complaint
=
377 {"inner block not inside outer block in %s", 0, 0};
379 struct complaint blockvector_complaint
=
380 {"block at %x out of order", 0, 0};
382 struct complaint lbrac_complaint
=
383 {"bad block start address patched", 0, 0};
386 struct complaint dbx_class_complaint
=
387 {"encountered DBX-style class variable debugging information.\n\
388 You seem to have compiled your program with \
389 \"g++ -g0\" instead of \"g++ -g\".\n\
390 Therefore GDB will not know about your class variables", 0, 0};
393 struct complaint string_table_offset_complaint
=
394 {"bad string table offset in symbol %d", 0, 0};
396 struct complaint unknown_symtype_complaint
=
397 {"unknown symbol type 0x%x", 0, 0};
399 struct complaint lbrac_rbrac_complaint
=
400 {"block start larger than block end", 0, 0};
402 struct complaint const_vol_complaint
=
403 {"const/volatile indicator missing, got '%c'", 0, 0};
405 struct complaint error_type_complaint
=
406 {"C++ type mismatch between compiler and debugger", 0, 0};
408 struct complaint invalid_member_complaint
=
409 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
411 /* Support for Sun changes to dbx symbol format */
413 /* For each identified header file, we have a table of types defined
416 header_files maps header file names to their type tables.
417 It is a vector of n_header_files elements.
418 Each element describes one header file.
419 It contains a vector of types.
421 Sometimes it can happen that the same header file produces
422 different results when included in different places.
423 This can result from conditionals or from different
424 things done before including the file.
425 When this happens, there are multiple entries for the file in this table,
426 one entry for each distinct set of results.
427 The entries are distinguished by the INSTANCE field.
428 The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
429 used to match header-file references to their corresponding data. */
433 char *name
; /* Name of header file */
434 int instance
; /* Numeric code distinguishing instances
435 of one header file that produced
436 different results when included.
437 It comes from the N_BINCL or N_EXCL. */
438 struct type
**vector
; /* Pointer to vector of types */
439 int length
; /* Allocated length (# elts) of that vector */
442 static struct header_file
*header_files
= 0;
444 static int n_header_files
;
446 static int n_allocated_header_files
;
448 /* During initial symbol readin, we need to have a structure to keep
449 track of which psymtabs have which bincls in them. This structure
450 is used during readin to setup the list of dependencies within each
451 partial symbol table. */
453 struct header_file_location
455 char *name
; /* Name of header file */
456 int instance
; /* See above */
457 struct partial_symtab
*pst
; /* Partial symtab that has the
458 BINCL/EINCL defs for this file */
461 /* The actual list and controling variables */
462 static struct header_file_location
*bincl_list
, *next_bincl
;
463 static int bincls_allocated
;
465 /* Within each object file, various header files are assigned numbers.
466 A type is defined or referred to with a pair of numbers
467 (FILENUM,TYPENUM) where FILENUM is the number of the header file
468 and TYPENUM is the number within that header file.
469 TYPENUM is the index within the vector of types for that header file.
471 FILENUM == 1 is special; it refers to the main source of the object file,
472 and not to any header file. FILENUM != 1 is interpreted by looking it up
473 in the following table, which contains indices in header_files. */
475 static int *this_object_header_files
= 0;
477 static int n_this_object_header_files
;
479 static int n_allocated_this_object_header_files
;
481 /* When a header file is getting special overriding definitions
482 for one source file, record here the header_files index
483 of its normal definition vector.
484 At other times, this is -1. */
486 static int header_file_prev_index
;
488 /* Free up old header file tables, and allocate new ones.
489 We're reading a new symbol file now. */
492 free_and_init_header_files ()
495 for (i
= 0; i
< n_header_files
; i
++)
496 free (header_files
[i
].name
);
497 if (header_files
) /* First time null */
499 if (this_object_header_files
) /* First time null */
500 free (this_object_header_files
);
502 n_allocated_header_files
= 10;
503 header_files
= (struct header_file
*) xmalloc (10 * sizeof (struct header_file
));
506 n_allocated_this_object_header_files
= 10;
507 this_object_header_files
= (int *) xmalloc (10 * sizeof (int));
510 /* Called at the start of each object file's symbols.
511 Clear out the mapping of header file numbers to header files. */
514 new_object_header_files ()
516 /* Leave FILENUM of 0 free for builtin types and this file's types. */
517 n_this_object_header_files
= 1;
518 header_file_prev_index
= -1;
521 /* Add header file number I for this object file
522 at the next successive FILENUM. */
525 add_this_object_header_file (i
)
528 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
530 n_allocated_this_object_header_files
*= 2;
531 this_object_header_files
532 = (int *) xrealloc (this_object_header_files
,
533 n_allocated_this_object_header_files
* sizeof (int));
536 this_object_header_files
[n_this_object_header_files
++] = i
;
539 /* Add to this file an "old" header file, one already seen in
540 a previous object file. NAME is the header file's name.
541 INSTANCE is its instance code, to select among multiple
542 symbol tables for the same header file. */
545 add_old_header_file (name
, instance
)
549 register struct header_file
*p
= header_files
;
552 for (i
= 0; i
< n_header_files
; i
++)
553 if (!strcmp (p
[i
].name
, name
) && instance
== p
[i
].instance
)
555 add_this_object_header_file (i
);
558 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
562 /* Add to this file a "new" header file: definitions for its types follow.
563 NAME is the header file's name.
564 Most often this happens only once for each distinct header file,
565 but not necessarily. If it happens more than once, INSTANCE has
566 a different value each time, and references to the header file
567 use INSTANCE values to select among them.
569 dbx output contains "begin" and "end" markers for each new header file,
570 but at this level we just need to know which files there have been;
571 so we record the file when its "begin" is seen and ignore the "end". */
574 add_new_header_file (name
, instance
)
579 header_file_prev_index
= -1;
581 /* Make sure there is room for one more header file. */
583 if (n_header_files
== n_allocated_header_files
)
585 n_allocated_header_files
*= 2;
586 header_files
= (struct header_file
*)
587 xrealloc (header_files
,
588 (n_allocated_header_files
589 * sizeof (struct header_file
)));
592 /* Create an entry for this header file. */
594 i
= n_header_files
++;
595 header_files
[i
].name
= savestring (name
, strlen(name
));
596 header_files
[i
].instance
= instance
;
597 header_files
[i
].length
= 10;
598 header_files
[i
].vector
599 = (struct type
**) xmalloc (10 * sizeof (struct type
*));
600 bzero (header_files
[i
].vector
, 10 * sizeof (struct type
*));
602 add_this_object_header_file (i
);
605 /* Look up a dbx type-number pair. Return the address of the slot
606 where the type for that number-pair is stored.
607 The number-pair is in TYPENUMS.
609 This can be used for finding the type associated with that pair
610 or for associating a new type with the pair. */
612 static struct type
**
613 dbx_lookup_type (typenums
)
616 register int filenum
= typenums
[0], index
= typenums
[1];
618 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
619 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
620 filenum
, index
, symnum
);
624 /* Type is defined outside of header files.
625 Find it in this object file's type vector. */
626 if (index
>= type_vector_length
)
628 type_vector_length
*= 2;
629 type_vector
= (struct typevector
*)
630 xrealloc (type_vector
,
631 (sizeof (struct typevector
)
632 + type_vector_length
* sizeof (struct type
*)));
633 bzero (&type_vector
->type
[type_vector_length
/ 2],
634 type_vector_length
* sizeof (struct type
*) / 2);
636 return &type_vector
->type
[index
];
640 register int real_filenum
= this_object_header_files
[filenum
];
641 register struct header_file
*f
;
644 if (real_filenum
>= n_header_files
)
647 f
= &header_files
[real_filenum
];
649 f_orig_length
= f
->length
;
650 if (index
>= f_orig_length
)
652 while (index
>= f
->length
)
654 f
->vector
= (struct type
**)
655 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
656 bzero (&f
->vector
[f_orig_length
],
657 (f
->length
- f_orig_length
) * sizeof (struct type
*));
659 return &f
->vector
[index
];
663 /* Create a type object. Occaisionally used when you need a type
664 which isn't going to be given a type number. */
669 register struct type
*type
=
670 (struct type
*) obstack_alloc (symbol_obstack
, sizeof (struct type
));
672 bzero (type
, sizeof (struct type
));
673 TYPE_VPTR_FIELDNO (type
) = -1;
677 /* Make sure there is a type allocated for type numbers TYPENUMS
678 and return the type object.
679 This can create an empty (zeroed) type object.
680 TYPENUMS may be (-1, -1) to return a new type object that is not
681 put into the type vector, and so may not be referred to by number. */
684 dbx_alloc_type (typenums
)
687 register struct type
**type_addr
;
688 register struct type
*type
;
690 if (typenums
[1] != -1)
692 type_addr
= dbx_lookup_type (typenums
);
701 /* If we are referring to a type not known at all yet,
702 allocate an empty type for it.
703 We will fill it in later if we find out how. */
706 type
= dbx_create_type ();
715 static struct type
**
716 explicit_lookup_type (real_filenum
, index
)
717 int real_filenum
, index
;
719 register struct header_file
*f
= &header_files
[real_filenum
];
721 if (index
>= f
->length
)
724 f
->vector
= (struct type
**)
725 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
726 bzero (&f
->vector
[f
->length
/ 2],
727 f
->length
* sizeof (struct type
*) / 2);
729 return &f
->vector
[index
];
733 /* maintain the lists of symbols and blocks */
735 /* Add a symbol to one of the lists of symbols. */
737 add_symbol_to_list (symbol
, listhead
)
738 struct symbol
*symbol
;
739 struct pending
**listhead
;
741 /* We keep PENDINGSIZE symbols in each link of the list.
742 If we don't have a link with room in it, add a new link. */
743 if (*listhead
== 0 || (*listhead
)->nsyms
== PENDINGSIZE
)
745 register struct pending
*link
;
748 link
= free_pendings
;
749 free_pendings
= link
->next
;
752 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
754 link
->next
= *listhead
;
759 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
762 /* At end of reading syms, or in case of quit,
763 really free as many `struct pending's as we can easily find. */
767 really_free_pendings (foo
)
770 struct pending
*next
, *next1
;
771 struct pending_block
*bnext
, *bnext1
;
773 for (next
= free_pendings
; next
; next
= next1
)
780 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
781 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
783 bnext1
= bnext
->next
;
789 for (next
= file_symbols
; next
; next
= next1
)
796 for (next
= global_symbols
; next
; next
= next1
)
804 /* Take one of the lists of symbols and make a block from it.
805 Keep the order the symbols have in the list (reversed from the input file).
806 Put the block on the list of pending blocks. */
809 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
810 struct symbol
*symbol
;
811 struct pending
**listhead
;
812 struct pending_block
*old_blocks
;
813 CORE_ADDR start
, end
;
815 register struct pending
*next
, *next1
;
816 register struct block
*block
;
817 register struct pending_block
*pblock
;
818 struct pending_block
*opblock
;
821 /* Count the length of the list of symbols. */
823 for (next
= *listhead
, i
= 0; next
; i
+= next
->nsyms
, next
= next
->next
)
826 block
= (struct block
*) obstack_alloc (symbol_obstack
,
827 (sizeof (struct block
)
829 * sizeof (struct symbol
*))));
831 /* Copy the symbols into the block. */
833 BLOCK_NSYMS (block
) = i
;
834 for (next
= *listhead
; next
; next
= next
->next
)
837 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
838 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
841 BLOCK_START (block
) = start
;
842 BLOCK_END (block
) = end
;
843 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
844 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
846 /* Put the block in as the value of the symbol that names it. */
850 SYMBOL_BLOCK_VALUE (symbol
) = block
;
851 BLOCK_FUNCTION (block
) = symbol
;
854 BLOCK_FUNCTION (block
) = 0;
856 /* Now "free" the links of the list, and empty the list. */
858 for (next
= *listhead
; next
; next
= next1
)
861 next
->next
= free_pendings
;
862 free_pendings
= next
;
866 /* Install this block as the superblock
867 of all blocks made since the start of this scope
868 that don't have superblocks yet. */
871 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
873 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0) {
875 /* Check to be sure the blocks are nested as we receive them.
876 If the compiler/assembler/linker work, this just burns a small
878 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
879 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)) {
880 complain(&innerblock_complaint
, symbol
? SYMBOL_NAME (symbol
):
882 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
883 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
886 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
891 /* Record this block on the list of all blocks in the file.
892 Put it after opblock, or at the beginning if opblock is 0.
893 This puts the block in the list after all its subblocks. */
895 /* Allocate in the symbol_obstack to save time.
896 It wastes a little space. */
897 pblock
= (struct pending_block
*)
898 obstack_alloc (symbol_obstack
,
899 sizeof (struct pending_block
));
900 pblock
->block
= block
;
903 pblock
->next
= opblock
->next
;
904 opblock
->next
= pblock
;
908 pblock
->next
= pending_blocks
;
909 pending_blocks
= pblock
;
913 static struct blockvector
*
916 register struct pending_block
*next
;
917 register struct blockvector
*blockvector
;
920 /* Count the length of the list of blocks. */
922 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
924 blockvector
= (struct blockvector
*)
925 obstack_alloc (symbol_obstack
,
926 (sizeof (struct blockvector
)
927 + (i
- 1) * sizeof (struct block
*)));
929 /* Copy the blocks into the blockvector.
930 This is done in reverse order, which happens to put
931 the blocks into the proper order (ascending starting address).
932 finish_block has hair to insert each block into the list
933 after its subblocks in order to make sure this is true. */
935 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
936 for (next
= pending_blocks
; next
; next
= next
->next
) {
937 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
940 #if 0 /* Now we make the links in the obstack, so don't free them. */
941 /* Now free the links of the list, and empty the list. */
943 for (next
= pending_blocks
; next
; next
= next1
)
951 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
952 /* Some compilers output blocks in the wrong order, but we depend
953 on their being in the right order so we can binary search.
954 Check the order and moan about it. FIXME. */
955 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
956 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
957 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
958 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
959 complain (&blockvector_complaint
,
960 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
968 /* Manage the vector of line numbers. */
971 record_line (line
, pc
)
975 struct linetable_entry
*e
;
976 /* Ignore the dummy line number in libg.o */
981 /* Make sure line vector is big enough. */
983 if (line_vector_index
+ 1 >= line_vector_length
)
985 line_vector_length
*= 2;
986 line_vector
= (struct linetable
*)
987 xrealloc (line_vector
,
988 (sizeof (struct linetable
)
989 + line_vector_length
* sizeof (struct linetable_entry
)));
990 current_subfile
->line_vector
= line_vector
;
993 e
= line_vector
->item
+ line_vector_index
++;
994 e
->line
= line
; e
->pc
= pc
;
997 /* Start a new symtab for a new source file.
998 This is called when a dbx symbol of type N_SO is seen;
999 it indicates the start of data for one original source file. */
1002 start_symtab (name
, dirname
, start_addr
)
1005 CORE_ADDR start_addr
;
1008 last_source_file
= name
;
1009 last_source_start_addr
= start_addr
;
1012 within_function
= 0;
1014 /* Context stack is initially empty, with room for 10 levels. */
1016 = (struct context_stack
*) xmalloc (10 * sizeof (struct context_stack
));
1017 context_stack_size
= 10;
1018 context_stack_depth
= 0;
1020 new_object_header_files ();
1022 type_vector_length
= 160;
1023 type_vector
= (struct typevector
*)
1024 xmalloc (sizeof (struct typevector
)
1025 + type_vector_length
* sizeof (struct type
*));
1026 bzero (type_vector
->type
, type_vector_length
* sizeof (struct type
*));
1028 /* Initialize the list of sub source files with one entry
1029 for this file (the top-level source file). */
1032 current_subfile
= 0;
1033 start_subfile (name
, dirname
);
1036 /* Handle an N_SOL symbol, which indicates the start of
1037 code that came from an included (or otherwise merged-in)
1038 source file with a different name. */
1041 start_subfile (name
, dirname
)
1045 register struct subfile
*subfile
;
1047 /* Save the current subfile's line vector data. */
1049 if (current_subfile
)
1051 current_subfile
->line_vector_index
= line_vector_index
;
1052 current_subfile
->line_vector_length
= line_vector_length
;
1053 current_subfile
->prev_line_number
= prev_line_number
;
1056 /* See if this subfile is already known as a subfile of the
1057 current main source file. */
1059 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
1061 if (!strcmp (subfile
->name
, name
))
1063 line_vector
= subfile
->line_vector
;
1064 line_vector_index
= subfile
->line_vector_index
;
1065 line_vector_length
= subfile
->line_vector_length
;
1066 prev_line_number
= subfile
->prev_line_number
;
1067 current_subfile
= subfile
;
1072 /* This subfile is not known. Add an entry for it. */
1074 line_vector_index
= 0;
1075 line_vector_length
= 1000;
1076 prev_line_number
= -2; /* Force first line number to be explicit */
1077 line_vector
= (struct linetable
*)
1078 xmalloc (sizeof (struct linetable
)
1079 + line_vector_length
* sizeof (struct linetable_entry
));
1081 /* Make an entry for this subfile in the list of all subfiles
1082 of the current main source file. */
1084 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
1085 subfile
->next
= subfiles
;
1086 subfile
->name
= obsavestring (name
, strlen (name
));
1087 if (dirname
== NULL
)
1088 subfile
->dirname
= NULL
;
1090 subfile
->dirname
= obsavestring (dirname
, strlen (dirname
));
1092 subfile
->line_vector
= line_vector
;
1094 current_subfile
= subfile
;
1097 /* Finish the symbol definitions for one main source file,
1098 close off all the lexical contexts for that file
1099 (creating struct block's for them), then make the struct symtab
1100 for that file and put it in the list of all such.
1102 END_ADDR is the address of the end of the file's text. */
1105 end_symtab (end_addr
)
1108 register struct symtab
*symtab
;
1109 register struct blockvector
*blockvector
;
1110 register struct subfile
*subfile
;
1111 register struct linetable
*lv
;
1112 struct subfile
*nextsub
;
1114 /* Finish the lexical context of the last function in the file;
1115 pop the context stack. */
1117 if (context_stack_depth
> 0)
1119 register struct context_stack
*cstk
;
1120 context_stack_depth
--;
1121 cstk
= &context_stack
[context_stack_depth
];
1122 /* Make a block for the local symbols within. */
1123 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
1124 cstk
->start_addr
, end_addr
);
1127 /* Cleanup any undefined types that have been left hanging around
1128 (this needs to be done before the finish_blocks so that
1129 file_symbols is still good). */
1130 cleanup_undefined_types ();
1132 /* Finish defining all the blocks of this symtab. */
1133 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
);
1134 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
);
1135 blockvector
= make_blockvector ();
1137 current_subfile
->line_vector_index
= line_vector_index
;
1139 /* Now create the symtab objects proper, one for each subfile. */
1140 /* (The main file is one of them.) */
1142 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
1144 symtab
= (struct symtab
*) xmalloc (sizeof (struct symtab
));
1146 /* Fill in its components. */
1147 symtab
->blockvector
= blockvector
;
1148 lv
= subfile
->line_vector
;
1149 lv
->nitems
= subfile
->line_vector_index
;
1150 symtab
->linetable
= (struct linetable
*)
1151 xrealloc (lv
, (sizeof (struct linetable
)
1152 + lv
->nitems
* sizeof (struct linetable_entry
)));
1153 type_vector
->length
= type_vector_length
;
1154 symtab
->typevector
= type_vector
;
1156 symtab
->filename
= subfile
->name
;
1157 symtab
->dirname
= subfile
->dirname
;
1159 symtab
->free_code
= free_linetable
;
1160 symtab
->free_ptr
= 0;
1161 if (subfile
->next
== 0)
1162 symtab
->free_ptr
= (char *) type_vector
;
1165 symtab
->line_charpos
= 0;
1167 symtab
->language
= language_unknown
;
1168 symtab
->fullname
= NULL
;
1170 /* If there is already a symtab for a file of this name, remove it,
1171 and clear out other dependent data structures such as
1172 breakpoints. This happens in VxWorks maybe? -gnu@cygnus */
1173 free_named_symtab (symtab
->filename
);
1175 /* Link the new symtab into the list of such. */
1176 symtab
->next
= symtab_list
;
1177 symtab_list
= symtab
;
1179 nextsub
= subfile
->next
;
1184 type_vector_length
= -1;
1186 line_vector_length
= -1;
1187 last_source_file
= 0;
1190 /* Handle the N_BINCL and N_EINCL symbol types
1191 that act like N_SOL for switching source files
1192 (different subfiles, as we call them) within one object file,
1193 but using a stack rather than in an arbitrary order. */
1195 struct subfile_stack
1197 struct subfile_stack
*next
;
1202 struct subfile_stack
*subfile_stack
;
1207 register struct subfile_stack
*tem
1208 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
1210 tem
->next
= subfile_stack
;
1211 subfile_stack
= tem
;
1212 if (current_subfile
== 0 || current_subfile
->name
== 0)
1214 tem
->name
= current_subfile
->name
;
1215 tem
->prev_index
= header_file_prev_index
;
1221 register char *name
;
1222 register struct subfile_stack
*link
= subfile_stack
;
1228 subfile_stack
= link
->next
;
1229 header_file_prev_index
= link
->prev_index
;
1236 record_misc_function (name
, address
, type
)
1241 enum misc_function_type misc_type
=
1242 (type
== (N_TEXT
| N_EXT
) ? mf_text
:
1243 (type
== (N_DATA
| N_EXT
)
1245 || type
== (N_SETV
| N_EXT
)
1247 type
== (N_BSS
| N_EXT
) ? mf_bss
:
1248 type
== (N_ABS
| N_EXT
) ? mf_abs
: mf_unknown
);
1250 prim_record_misc_function (obsavestring (name
, strlen (name
)),
1251 address
, misc_type
);
1254 /* Scan and build partial symbols for a symbol file.
1255 We have been initialized by a call to dbx_symfile_init, which
1256 put all the relevant info into a "struct dbx_symfile_info"
1257 hung off the struct sym_fns SF.
1259 ADDR is the address relative to which the symbols in it are (e.g.
1260 the base address of the text segment).
1261 MAINLINE is true if we are reading the main symbol
1262 table (as opposed to a shared lib or dynamically loaded file). */
1265 dbx_symfile_read (sf
, addr
, mainline
)
1268 int mainline
; /* FIXME comments above */
1270 struct dbx_symfile_info
*info
= (struct dbx_symfile_info
*) (sf
->sym_private
);
1271 bfd
*sym_bfd
= sf
->sym_bfd
;
1273 char *filename
= bfd_get_filename (sym_bfd
);
1275 val
= lseek (info
->desc
, info
->symtab_offset
, L_SET
);
1277 perror_with_name (filename
);
1279 /* If mainline, set global string table pointers, and reinitialize global
1280 partial symbol list. */
1282 symfile_string_table
= info
->stringtab
;
1283 symfile_string_table_size
= info
->stringtab_size
;
1284 init_psymbol_list (info
->symcount
);
1287 symfile_bfd
= sym_bfd
; /* Kludge for SWAP_SYMBOL */
1290 make_cleanup (really_free_pendings
, 0);
1292 init_misc_bunches ();
1293 make_cleanup (discard_misc_bunches
, 0);
1295 /* Now that the symbol table data of the executable file are all in core,
1296 process them and define symbols accordingly. */
1298 read_dbx_symtab (filename
,
1299 addr
- bfd_section_vma (sym_bfd
, info
->text_sect
), /*offset*/
1300 info
->desc
, info
->stringtab
, info
->stringtab_size
,
1302 bfd_section_vma (sym_bfd
, info
->text_sect
),
1303 bfd_section_size (sym_bfd
, info
->text_sect
));
1305 /* Go over the misc symbol bunches and install them in vector. */
1307 condense_misc_bunches (!mainline
);
1309 /* Free up any memory we allocated for ourselves. */
1312 free (info
->stringtab
); /* Stringtab is only saved for mainline */
1315 sf
->sym_private
= 0; /* Zap pointer to our (now gone) info struct */
1317 /* Call to select_source_symtab used to be here; it was using too
1318 much time. I'll make sure that list_sources can handle the lack
1319 of current_source_symtab */
1321 if (!partial_symtab_list
)
1322 printf_filtered ("\n(no debugging symbols found)...");
1325 /* Discard any information we have cached during the reading of a
1326 single symbol file. This should not toss global information
1327 from previous symbol files that have been read. E.g. we might
1328 be discarding info from reading a shared library, and should not
1329 throw away the info from the main file. */
1332 dbx_symfile_discard ()
1335 /* Empty the hash table of global syms looking for values. */
1336 bzero (global_sym_chain
, sizeof global_sym_chain
);
1343 /* Initialize anything that needs initializing when a completely new
1344 symbol file is specified (not just adding some symbols from another
1345 file, e.g. a shared library). */
1350 dbx_symfile_discard ();
1351 /* Don't put these on the cleanup chain; they need to stick around
1352 until the next call to symbol_file_command. *Then* we'll free
1354 if (symfile_string_table
)
1356 free (symfile_string_table
);
1357 symfile_string_table
= 0;
1358 symfile_string_table_size
= 0;
1360 free_and_init_header_files ();
1364 /* dbx_symfile_init ()
1365 is the dbx-specific initialization routine for reading symbols.
1366 It is passed a struct sym_fns which contains, among other things,
1367 the BFD for the file whose symbols are being read, and a slot for a pointer
1368 to "private data" which we fill with goodies.
1370 We read the string table into malloc'd space and stash a pointer to it.
1372 Since BFD doesn't know how to read debug symbols in a format-independent
1373 way (and may never do so...), we have to do it ourselves. We will never
1374 be called unless this is an a.out (or very similar) file.
1375 FIXME, there should be a cleaner peephole into the BFD environment here. */
1378 dbx_symfile_init (sf
)
1383 struct stat statbuf
;
1384 bfd
*sym_bfd
= sf
->sym_bfd
;
1385 char *name
= bfd_get_filename (sym_bfd
);
1386 struct dbx_symfile_info
*info
;
1387 unsigned char size_temp
[4];
1389 /* Allocate struct to keep track of the symfile */
1390 sf
->sym_private
= xmalloc (sizeof (*info
)); /* FIXME storage leak */
1391 info
= (struct dbx_symfile_info
*)sf
->sym_private
;
1393 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1394 desc
= fileno ((FILE *)(sym_bfd
->iostream
)); /* Raw file descriptor */
1395 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
1396 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
1397 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1400 info
->text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
1401 if (!info
->text_sect
)
1403 info
->symcount
= bfd_get_symcount_upper_bound(sym_bfd
); /* It's exact for a.out */
1405 /* Read the string table size and check it for bogosity. */
1406 val
= lseek (desc
, STRING_TABLE_OFFSET
, L_SET
);
1408 perror_with_name (name
);
1409 if (fstat (desc
, &statbuf
) == -1)
1410 perror_with_name (name
);
1412 val
= myread (desc
, size_temp
, sizeof (long));
1414 perror_with_name (name
);
1415 info
->stringtab_size
= bfd_h_getlong (sym_bfd
, size_temp
);
1417 if (info
->stringtab_size
>= 0 && info
->stringtab_size
< statbuf
.st_size
)
1419 info
->stringtab
= (char *) xmalloc (info
->stringtab_size
);
1420 /* Caller is responsible for freeing the string table. No cleanup. */
1423 info
->stringtab
= NULL
;
1424 if (info
->stringtab
== NULL
&& info
->stringtab_size
!= 0)
1425 error ("ridiculous string table size: %d bytes", info
->stringtab_size
);
1427 /* Now read in the string table in one big gulp. */
1429 val
= lseek (desc
, STRING_TABLE_OFFSET
, L_SET
);
1431 perror_with_name (name
);
1432 val
= myread (desc
, info
->stringtab
, info
->stringtab_size
);
1434 perror_with_name (name
);
1436 /* Record the position of the symbol table for later use. */
1438 info
->symtab_offset
= SYMBOL_TABLE_OFFSET
;
1441 /* Buffer for reading the symbol table entries. */
1442 static struct nlist symbuf
[4096];
1443 static int symbuf_idx
;
1444 static int symbuf_end
;
1446 /* I/O descriptor for reading the symbol table. */
1447 static int symtab_input_desc
;
1449 /* The address in memory of the string table of the object file we are
1450 reading (which might not be the "main" object file, but might be a
1451 shared library or some other dynamically loaded thing). This is set
1452 by read_dbx_symtab when building psymtabs, and by read_ofile_symtab
1453 when building symtabs, and is used only by next_symbol_text. */
1454 static char *stringtab_global
;
1456 /* Refill the symbol table input buffer
1457 and set the variables that control fetching entries from it.
1458 Reports an error if no data available.
1459 This function can read past the end of the symbol table
1460 (into the string table) but this does no harm. */
1465 int nbytes
= myread (symtab_input_desc
, symbuf
, sizeof (symbuf
));
1467 perror_with_name ("<symbol file>");
1468 else if (nbytes
== 0)
1469 error ("Premature end of file reading symbol table");
1470 symbuf_end
= nbytes
/ sizeof (struct nlist
);
1475 #define SWAP_SYMBOL(symp) \
1477 (symp)->n_un.n_strx = bfd_h_getlong(symfile_bfd, \
1478 (unsigned char *)&(symp)->n_un.n_strx); \
1479 (symp)->n_desc = bfd_h_getshort (symfile_bfd, \
1480 (unsigned char *)&(symp)->n_desc); \
1481 (symp)->n_value = bfd_h_getlong (symfile_bfd, \
1482 (unsigned char *)&(symp)->n_value); \
1485 /* Invariant: The symbol pointed to by symbuf_idx is the first one
1486 that hasn't been swapped. Swap the symbol at the same time
1487 that symbuf_idx is incremented. */
1489 /* dbx allows the text of a symbol name to be continued into the
1490 next symbol name! When such a continuation is encountered
1491 (a \ at the end of the text of a name)
1492 call this function to get the continuation. */
1497 if (symbuf_idx
== symbuf_end
)
1500 SWAP_SYMBOL(&symbuf
[symbuf_idx
]);
1501 return symbuf
[symbuf_idx
++].n_un
.n_strx
+ stringtab_global
;
1504 /* Initializes storage for all of the partial symbols that will be
1505 created by read_dbx_symtab and subsidiaries. */
1508 init_psymbol_list (total_symbols
)
1511 /* Free any previously allocated psymbol lists. */
1512 if (global_psymbols
.list
)
1513 free (global_psymbols
.list
);
1514 if (static_psymbols
.list
)
1515 free (static_psymbols
.list
);
1517 /* Current best guess is that there are approximately a twentieth
1518 of the total symbols (in a debugging file) are global or static
1520 global_psymbols
.size
= total_symbols
/ 10;
1521 static_psymbols
.size
= total_symbols
/ 10;
1522 global_psymbols
.next
= global_psymbols
.list
= (struct partial_symbol
*)
1523 xmalloc (global_psymbols
.size
* sizeof (struct partial_symbol
));
1524 static_psymbols
.next
= static_psymbols
.list
= (struct partial_symbol
*)
1525 xmalloc (static_psymbols
.size
* sizeof (struct partial_symbol
));
1528 /* Initialize the list of bincls to contain none and have some
1532 init_bincl_list (number
)
1535 bincls_allocated
= number
;
1536 next_bincl
= bincl_list
= (struct header_file_location
*)
1537 xmalloc (bincls_allocated
* sizeof(struct header_file_location
));
1540 /* Add a bincl to the list. */
1543 add_bincl_to_list (pst
, name
, instance
)
1544 struct partial_symtab
*pst
;
1548 if (next_bincl
>= bincl_list
+ bincls_allocated
)
1550 int offset
= next_bincl
- bincl_list
;
1551 bincls_allocated
*= 2;
1552 bincl_list
= (struct header_file_location
*)
1553 xrealloc ((char *)bincl_list
,
1554 bincls_allocated
* sizeof (struct header_file_location
));
1555 next_bincl
= bincl_list
+ offset
;
1557 next_bincl
->pst
= pst
;
1558 next_bincl
->instance
= instance
;
1559 next_bincl
++->name
= name
;
1562 /* Given a name, value pair, find the corresponding
1563 bincl in the list. Return the partial symtab associated
1564 with that header_file_location. */
1566 struct partial_symtab
*
1567 find_corresponding_bincl_psymtab (name
, instance
)
1571 struct header_file_location
*bincl
;
1573 for (bincl
= bincl_list
; bincl
< next_bincl
; bincl
++)
1574 if (bincl
->instance
== instance
1575 && !strcmp (name
, bincl
->name
))
1578 return (struct partial_symtab
*) 0;
1581 /* Free the storage allocated for the bincl list. */
1587 bincls_allocated
= 0;
1590 static struct partial_symtab
*start_psymtab ();
1591 static void end_psymtab();
1594 /* This is normally a macro defined in read_dbx_symtab, but this
1595 is a lot easier to debug. */
1597 ADD_PSYMBOL_TO_PLIST(NAME
, NAMELENGTH
, NAMESPACE
, CLASS
, PLIST
, VALUE
)
1600 enum namespace NAMESPACE
;
1601 enum address_class CLASS
;
1602 struct psymbol_allocation_list
*PLIST
;
1603 unsigned long VALUE
;
1605 register struct partial_symbol
*psym
;
1610 (LIST
).list
+ (LIST
).size
)
1612 (LIST
).list
= (struct partial_symbol
*)
1613 xrealloc ((LIST
).list
,
1615 * sizeof (struct partial_symbol
)));
1616 /* Next assumes we only went one over. Should be good if
1617 program works correctly */
1619 (LIST
).list
+ (LIST
).size
;
1622 psym
= (LIST
).next
++;
1625 SYMBOL_NAME (psym
) = (char *) obstack_alloc (psymbol_obstack
,
1627 strncpy (SYMBOL_NAME (psym
), (NAME
), (NAMELENGTH
));
1628 SYMBOL_NAME (psym
)[(NAMELENGTH
)] = '\0';
1629 SYMBOL_NAMESPACE (psym
) = (NAMESPACE
);
1630 SYMBOL_CLASS (psym
) = (CLASS
);
1631 SYMBOL_VALUE (psym
) = (VALUE
);
1635 /* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
1636 #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
1637 ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
1641 /* Given pointers to an a.out symbol table in core containing dbx
1642 style data, setup partial_symtab's describing each source file for
1643 which debugging information is available. NLISTLEN is the number
1644 of symbols in the symbol table. All symbol names are given as
1645 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
1646 STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
1647 and ADDR is its relocated address (if incremental) or 0 (if not). */
1650 read_dbx_symtab (symfile_name
, addr
,
1651 desc
, stringtab
, stringtab_size
, nlistlen
,
1652 text_addr
, text_size
)
1656 register char *stringtab
;
1657 register long stringtab_size
;
1658 register int nlistlen
;
1659 CORE_ADDR text_addr
;
1662 register struct nlist
*bufp
;
1663 register char *namestring
;
1664 register struct partial_symbol
*psym
;
1666 int past_first_source_file
= 0;
1667 CORE_ADDR last_o_file_start
= 0;
1668 struct cleanup
*old_chain
;
1671 /* End of the text segment of the executable file. */
1672 CORE_ADDR end_of_text_addr
;
1674 /* Current partial symtab */
1675 struct partial_symtab
*pst
;
1677 /* List of current psymtab's include files */
1678 char **psymtab_include_list
;
1679 int includes_allocated
;
1682 /* Index within current psymtab dependency list */
1683 struct partial_symtab
**dependency_list
;
1684 int dependencies_used
, dependencies_allocated
;
1686 stringtab_global
= stringtab
;
1688 pst
= (struct partial_symtab
*) 0;
1690 includes_allocated
= 30;
1692 psymtab_include_list
= (char **) alloca (includes_allocated
*
1695 dependencies_allocated
= 30;
1696 dependencies_used
= 0;
1698 (struct partial_symtab
**) alloca (dependencies_allocated
*
1699 sizeof (struct partial_symtab
*));
1701 /* FIXME!! If an error occurs, this blows away the whole symbol table!
1702 It should only blow away the psymtabs created herein. We could
1703 be reading a shared library or a dynloaded file! */
1704 old_chain
= make_cleanup (free_all_psymtabs
, 0);
1706 /* Init bincl list */
1707 init_bincl_list (20);
1708 make_cleanup (free_bincl_list
, 0);
1710 last_source_file
= 0;
1712 #ifdef END_OF_TEXT_DEFAULT
1713 end_of_text_addr
= END_OF_TEXT_DEFAULT
;
1715 end_of_text_addr
= text_addr
+ text_size
;
1718 symtab_input_desc
= desc
; /* This is needed for fill_symbuf below */
1719 symbuf_end
= symbuf_idx
= 0;
1721 for (symnum
= 0; symnum
< nlistlen
; symnum
++)
1723 /* Get the symbol for this run and pull out some info */
1724 QUIT
; /* allow this to be interruptable */
1725 if (symbuf_idx
== symbuf_end
)
1727 bufp
= &symbuf
[symbuf_idx
++];
1730 * Special case to speed up readin.
1732 if (bufp
->n_type
== (unsigned char)N_SLINE
) continue;
1736 /* Ok. There is a lot of code duplicated in the rest of this
1737 switch statement (for efficiency reasons). Since I don't
1738 like duplicating code, I will do my penance here, and
1739 describe the code which is duplicated:
1741 *) The assignment to namestring.
1742 *) The call to strchr.
1743 *) The addition of a partial symbol the the two partial
1744 symbol lists. This last is a large section of code, so
1745 I've imbedded it in the following macro.
1748 /* Set namestring based on bufp. If the string table index is invalid,
1749 give a fake name, and print a single error message per symbol file read,
1750 rather than abort the symbol reading or flood the user with messages. */
1751 #define SET_NAMESTRING()\
1752 if (bufp->n_un.n_strx < 0 || bufp->n_un.n_strx >= stringtab_size) { \
1753 complain (&string_table_offset_complaint, symnum); \
1754 namestring = "foo"; \
1756 namestring = bufp->n_un.n_strx + stringtab
1758 /* Add a symbol with an integer value to a psymtab. */
1759 /* This is a macro unless we're debugging. See above this function. */
1761 # define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
1762 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
1766 /* Add a symbol with a CORE_ADDR value to a psymtab. */
1767 #define ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
1768 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
1769 SYMBOL_VALUE_ADDRESS)
1771 /* Add any kind of symbol to a psymtab. */
1772 #define ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, VT)\
1774 if ((LIST).next >= \
1775 (LIST).list + (LIST).size) \
1777 (LIST).list = (struct partial_symbol *) \
1778 xrealloc ((LIST).list, \
1780 * sizeof (struct partial_symbol))); \
1781 /* Next assumes we only went one over. Should be good if \
1782 program works correctly */ \
1784 (LIST).list + (LIST).size; \
1787 psym = (LIST).next++; \
1789 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \
1790 (NAMELENGTH) + 1); \
1791 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \
1792 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \
1793 SYMBOL_NAMESPACE (psym) = (NAMESPACE); \
1794 SYMBOL_CLASS (psym) = (CLASS); \
1795 VT (psym) = (VALUE); \
1798 /* End of macro definitions, now let's handle them symbols! */
1800 switch (bufp
->n_type
)
1803 * Standard, external, non-debugger, symbols
1806 case N_TEXT
| N_EXT
:
1807 case N_NBTEXT
| N_EXT
:
1808 case N_NBDATA
| N_EXT
:
1809 case N_NBBSS
| N_EXT
:
1810 case N_SETV
| N_EXT
:
1812 case N_DATA
| N_EXT
:
1815 bufp
->n_value
+= addr
; /* Relocate */
1820 record_misc_function (namestring
, bufp
->n_value
,
1821 bufp
->n_type
); /* Always */
1825 /* Standard, local, non-debugger, symbols */
1829 /* We need to be able to deal with both N_FN or N_TEXT,
1830 because we have no way of knowing whether the sys-supplied ld
1831 or GNU ld was used to make the executable. */
1832 #if ! (N_FN & N_EXT)
1837 bufp
->n_value
+= addr
; /* Relocate */
1839 if ((namestring
[0] == '-' && namestring
[1] == 'l')
1840 || (namestring
[(nsl
= strlen (namestring
)) - 1] == 'o'
1841 && namestring
[nsl
- 2] == '.'))
1843 if (entry_point
< bufp
->n_value
1844 && entry_point
>= last_o_file_start
1845 && addr
== 0) /* FIXME nogood nomore */
1847 startup_file_start
= last_o_file_start
;
1848 startup_file_end
= bufp
->n_value
;
1850 if (past_first_source_file
&& pst
1851 /* The gould NP1 uses low values for .o and -l symbols
1852 which are not the address. */
1853 && bufp
->n_value
> pst
->textlow
)
1855 end_psymtab (pst
, psymtab_include_list
, includes_used
,
1856 symnum
* sizeof (struct nlist
), bufp
->n_value
,
1857 dependency_list
, dependencies_used
,
1858 global_psymbols
.next
, static_psymbols
.next
);
1859 pst
= (struct partial_symtab
*) 0;
1861 dependencies_used
= 0;
1864 past_first_source_file
= 1;
1865 last_o_file_start
= bufp
->n_value
;
1870 bufp
->n_value
+= addr
; /* Relocate */
1872 /* Check for __DYNAMIC, which is used by Sun shared libraries.
1873 Record it even if it's local, not global, so we can find it. */
1874 if (namestring
[8] == 'C' && (strcmp ("__DYNAMIC", namestring
) == 0))
1876 /* Not really a function here, but... */
1877 record_misc_function (namestring
, bufp
->n_value
,
1878 bufp
->n_type
); /* Always */
1882 case N_UNDF
| N_EXT
:
1883 if (bufp
->n_value
!= 0) {
1884 /* This is a "Fortran COMMON" symbol. See if the target
1885 environment knows where it has been relocated to. */
1890 if (target_lookup_symbol (namestring
, &reladdr
)) {
1891 continue; /* Error in lookup; ignore symbol for now. */
1893 bufp
->n_type
^= (N_BSS
^N_UNDF
); /* Define it as a bss-symbol */
1894 bufp
->n_value
= reladdr
;
1895 goto bss_ext_symbol
;
1897 continue; /* Just undefined, not COMMON */
1899 /* Lots of symbol types we can just ignore. */
1908 /* Keep going . . .*/
1911 * Special symbol types for GNU
1914 case N_INDR
| N_EXT
:
1916 case N_SETA
| N_EXT
:
1918 case N_SETT
| N_EXT
:
1920 case N_SETD
| N_EXT
:
1922 case N_SETB
| N_EXT
:
1931 unsigned long valu
= bufp
->n_value
;
1932 /* Symbol number of the first symbol of this file (i.e. the N_SO
1933 if there is just one, or the first if we have a pair). */
1934 int first_symnum
= symnum
;
1936 /* End the current partial symtab and start a new one */
1940 /* Peek at the next symbol. If it is also an N_SO, the
1941 first one just indicates the directory. */
1942 if (symbuf_idx
== symbuf_end
)
1944 bufp
= &symbuf
[symbuf_idx
];
1945 /* n_type is only a char, so swapping swapping is irrelevant. */
1946 if (bufp
->n_type
== (unsigned char)N_SO
)
1950 valu
= bufp
->n_value
;
1954 valu
+= addr
; /* Relocate */
1956 if (pst
&& past_first_source_file
)
1958 end_psymtab (pst
, psymtab_include_list
, includes_used
,
1959 first_symnum
* sizeof (struct nlist
), valu
,
1960 dependency_list
, dependencies_used
,
1961 global_psymbols
.next
, static_psymbols
.next
);
1962 pst
= (struct partial_symtab
*) 0;
1964 dependencies_used
= 0;
1967 past_first_source_file
= 1;
1969 pst
= start_psymtab (symfile_name
, addr
,
1971 first_symnum
* sizeof (struct nlist
),
1972 global_psymbols
.next
, static_psymbols
.next
);
1978 /* Add this bincl to the bincl_list for future EXCLs. No
1979 need to save the string; it'll be around until
1980 read_dbx_symtab function returns */
1984 add_bincl_to_list (pst
, namestring
, bufp
->n_value
);
1986 /* Mark down an include file in the current psymtab */
1988 psymtab_include_list
[includes_used
++] = namestring
;
1989 if (includes_used
>= includes_allocated
)
1991 char **orig
= psymtab_include_list
;
1993 psymtab_include_list
= (char **)
1994 alloca ((includes_allocated
*= 2) *
1996 bcopy (orig
, psymtab_include_list
,
1997 includes_used
* sizeof (char *));
2003 /* Mark down an include file in the current psymtab */
2007 /* In C++, one may expect the same filename to come round many
2008 times, when code is coming alternately from the main file
2009 and from inline functions in other files. So I check to see
2010 if this is a file we've seen before.
2012 This seems to be a lot of time to be spending on N_SOL, but
2013 things like "break expread.y:435" need to work (I
2014 suppose the psymtab_include_list could be hashed or put
2015 in a binary tree, if profiling shows this is a major hog). */
2018 for (i
= 0; i
< includes_used
; i
++)
2019 if (!strcmp (namestring
, psymtab_include_list
[i
]))
2028 psymtab_include_list
[includes_used
++] = namestring
;
2029 if (includes_used
>= includes_allocated
)
2031 char **orig
= psymtab_include_list
;
2033 psymtab_include_list
= (char **)
2034 alloca ((includes_allocated
*= 2) *
2036 bcopy (orig
, psymtab_include_list
,
2037 includes_used
* sizeof (char *));
2041 case N_LSYM
: /* Typedef or automatic variable. */
2044 p
= (char *) strchr (namestring
, ':');
2046 /* Skip if there is no :. */
2052 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2053 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2054 static_psymbols
, bufp
->n_value
);
2057 /* Also a typedef with the same name. */
2058 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2059 VAR_NAMESPACE
, LOC_TYPEDEF
,
2060 static_psymbols
, bufp
->n_value
);
2065 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2066 VAR_NAMESPACE
, LOC_TYPEDEF
,
2067 static_psymbols
, bufp
->n_value
);
2069 /* If this is an enumerated type, we need to
2070 add all the enum constants to the partial symbol
2071 table. This does not cover enums without names, e.g.
2072 "enum {a, b} c;" in C, but fortunately those are
2073 rare. There is no way for GDB to find those from the
2074 enum type without spending too much time on it. Thus
2075 to solve this problem, the compiler needs to put out separate
2076 constant symbols ('c' N_LSYMS) for enum constants in
2077 enums without names, or put out a dummy type. */
2079 /* We are looking for something of the form
2080 <name> ":" ("t" | "T") [<number> "="] "e"
2081 {<constant> ":" <value> ","} ";". */
2083 /* Skip over the colon and the 't' or 'T'. */
2085 /* This type may be given a number. Skip over it. */
2086 while ((*p
>= '0' && *p
<= '9')
2092 /* We have found an enumerated type. */
2093 /* According to comments in read_enum_type
2094 a comma could end it instead of a semicolon.
2095 I don't know where that happens.
2097 while (*p
&& *p
!= ';' && *p
!= ',')
2101 /* Check for and handle cretinous dbx symbol name
2104 p
= next_symbol_text ();
2106 /* Point to the character after the name
2107 of the enum constant. */
2108 for (q
= p
; *q
&& *q
!= ':'; q
++)
2110 /* Note that the value doesn't matter for
2111 enum constants in psymtabs, just in symtabs. */
2112 ADD_PSYMBOL_TO_LIST (p
, q
- p
,
2113 VAR_NAMESPACE
, LOC_CONST
,
2114 static_psymbols
, 0);
2115 /* Point past the name. */
2117 /* Skip over the value. */
2118 while (*p
&& *p
!= ',')
2120 /* Advance past the comma. */
2128 /* Constant, e.g. from "const" in Pascal. */
2129 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2130 VAR_NAMESPACE
, LOC_CONST
,
2131 static_psymbols
, bufp
->n_value
);
2134 /* Skip if the thing following the : is
2135 not a letter (which indicates declaration of a local
2136 variable, which we aren't interested in). */
2141 case N_GSYM
: /* Global (extern) variable; can be
2142 data or bss (sigh). */
2143 case N_STSYM
: /* Data seg var -- static */
2144 case N_LCSYM
: /* BSS " */
2146 case N_NBSTS
: /* Gould nobase. */
2147 case N_NBLCS
: /* symbols. */
2149 /* Following may probably be ignored; I'll leave them here
2150 for now (until I do Pascal and Modula 2 extensions). */
2152 case N_PC
: /* I may or may not need this; I
2154 case N_M2C
: /* I suspect that I can ignore this here. */
2155 case N_SCOPE
: /* Same. */
2159 p
= (char *) strchr (namestring
, ':');
2161 continue; /* Not a debugging symbol. */
2165 /* Main processing section for debugging symbols which
2166 the initial read through the symbol tables needs to worry
2167 about. If we reach this point, the symbol which we are
2168 considering is definitely one we are interested in.
2169 p must also contain the (valid) index into the namestring
2170 which indicates the debugging type symbol. */
2175 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2176 VAR_NAMESPACE
, LOC_CONST
,
2177 static_psymbols
, bufp
->n_value
);
2180 bufp
->n_value
+= addr
; /* Relocate */
2181 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
2182 VAR_NAMESPACE
, LOC_STATIC
,
2183 static_psymbols
, bufp
->n_value
);
2186 bufp
->n_value
+= addr
; /* Relocate */
2187 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
2188 VAR_NAMESPACE
, LOC_EXTERNAL
,
2189 global_psymbols
, bufp
->n_value
);
2193 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2194 VAR_NAMESPACE
, LOC_TYPEDEF
,
2195 global_psymbols
, bufp
->n_value
);
2199 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2200 VAR_NAMESPACE
, LOC_BLOCK
,
2201 static_psymbols
, bufp
->n_value
);
2204 /* Two things show up here (hopefully); static symbols of
2205 local scope (static used inside braces) or extensions
2206 of structure symbols. We can ignore both. */
2219 /* Global functions are ignored here. I'm not
2220 sure what psymtab they go into (or just the misc
2221 function vector). */
2226 /* Unexpected symbol. Ignore it; perhaps it is an extension
2227 that we don't know about.
2229 Someone says sun cc puts out symbols like
2230 /foo/baz/maclib::/usr/local/bin/maclib,
2231 which would get here with a symbol type of ':'. */
2239 /* Find the corresponding bincl and mark that psymtab on the
2240 psymtab dependency list */
2242 struct partial_symtab
*needed_pst
=
2243 find_corresponding_bincl_psymtab (namestring
, bufp
->n_value
);
2245 /* If this include file was defined earlier in this file,
2247 if (needed_pst
== pst
) continue;
2254 for (i
= 0; i
< dependencies_used
; i
++)
2255 if (dependency_list
[i
] == needed_pst
)
2261 /* If it's already in the list, skip the rest. */
2262 if (found
) continue;
2264 dependency_list
[dependencies_used
++] = needed_pst
;
2265 if (dependencies_used
>= dependencies_allocated
)
2267 struct partial_symtab
**orig
= dependency_list
;
2269 (struct partial_symtab
**)
2270 alloca ((dependencies_allocated
*= 2)
2271 * sizeof (struct partial_symtab
*));
2272 bcopy (orig
, dependency_list
,
2274 * sizeof (struct partial_symtab
*)));
2276 fprintf (stderr
, "Had to reallocate dependency list.\n");
2277 fprintf (stderr
, "New dependencies allocated: %d\n",
2278 dependencies_allocated
);
2283 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
2291 case N_SSYM
: /* Claim: Structure or union element.
2292 Hopefully, I can ignore this. */
2293 case N_ENTRY
: /* Alternate entry point; can ignore. */
2294 case N_MAIN
: /* Can definitely ignore this. */
2295 case N_CATCH
: /* These are GNU C++ extensions */
2296 case N_EHDECL
: /* that can safely be ignored here. */
2307 case N_NSYMS
: /* Ultrix 4.0: symbol count */
2308 /* These symbols aren't interesting; don't worry about them */
2313 /* If we haven't found it yet, ignore it. It's probably some
2314 new type we don't know about yet. */
2315 complain (&unknown_symtype_complaint
, bufp
->n_type
);
2320 /* If there's stuff to be cleaned up, clean it up. */
2321 if (entry_point
< bufp
->n_value
2322 && entry_point
>= last_o_file_start
)
2324 startup_file_start
= last_o_file_start
;
2325 startup_file_end
= bufp
->n_value
;
2330 end_psymtab (pst
, psymtab_include_list
, includes_used
,
2331 symnum
* sizeof (struct nlist
), end_of_text_addr
,
2332 dependency_list
, dependencies_used
,
2333 global_psymbols
.next
, static_psymbols
.next
);
2335 dependencies_used
= 0;
2336 pst
= (struct partial_symtab
*) 0;
2340 discard_cleanups (old_chain
);
2344 * Allocate and partially fill a partial symtab. It will be
2345 * completely filled at the end of the symbol list.
2347 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2348 is the address relative to which its symbols are (incremental) or 0
2350 static struct partial_symtab
*
2351 start_psymtab (symfile_name
, addr
,
2352 filename
, textlow
, ldsymoff
, global_syms
, static_syms
)
2358 struct partial_symbol
*global_syms
;
2359 struct partial_symbol
*static_syms
;
2361 struct partial_symtab
*result
=
2362 (struct partial_symtab
*) obstack_alloc (psymbol_obstack
,
2363 sizeof (struct partial_symtab
));
2365 result
->addr
= addr
;
2367 result
->symfile_name
=
2368 (char *) obstack_alloc (psymbol_obstack
,
2369 strlen (symfile_name
) + 1);
2370 strcpy (result
->symfile_name
, symfile_name
);
2373 (char *) obstack_alloc (psymbol_obstack
,
2374 strlen (filename
) + 1);
2375 strcpy (result
->filename
, filename
);
2377 result
->textlow
= textlow
;
2378 result
->ldsymoff
= ldsymoff
;
2382 result
->read_symtab
= dbx_psymtab_to_symtab
;
2384 result
->globals_offset
= global_syms
- global_psymbols
.list
;
2385 result
->statics_offset
= static_syms
- static_psymbols
.list
;
2387 result
->n_global_syms
= 0;
2388 result
->n_static_syms
= 0;
2395 compare_psymbols (s1
, s2
)
2396 register struct partial_symbol
*s1
, *s2
;
2399 *st1
= SYMBOL_NAME (s1
),
2400 *st2
= SYMBOL_NAME (s2
);
2402 return (st1
[0] - st2
[0] ? st1
[0] - st2
[0] :
2403 strcmp (st1
+ 1, st2
+ 1));
2407 /* Close off the current usage of a partial_symbol table entry. This
2408 involves setting the correct number of includes (with a realloc),
2409 setting the high text mark, setting the symbol length in the
2410 executable, and setting the length of the global and static lists
2413 The global symbols and static symbols are then seperately sorted.
2415 Then the partial symtab is put on the global list.
2416 *** List variables and peculiarities of same. ***
2419 end_psymtab (pst
, include_list
, num_includes
, capping_symbol_offset
,
2420 capping_text
, dependency_list
, number_dependencies
,
2421 capping_global
, capping_static
)
2422 struct partial_symtab
*pst
;
2423 char **include_list
;
2425 int capping_symbol_offset
;
2426 CORE_ADDR capping_text
;
2427 struct partial_symtab
**dependency_list
;
2428 int number_dependencies
;
2429 struct partial_symbol
*capping_global
, *capping_static
;
2433 pst
->ldsymlen
= capping_symbol_offset
- pst
->ldsymoff
;
2434 pst
->texthigh
= capping_text
;
2436 pst
->n_global_syms
=
2437 capping_global
- (global_psymbols
.list
+ pst
->globals_offset
);
2438 pst
->n_static_syms
=
2439 capping_static
- (static_psymbols
.list
+ pst
->statics_offset
);
2441 pst
->number_of_dependencies
= number_dependencies
;
2442 if (number_dependencies
)
2444 pst
->dependencies
= (struct partial_symtab
**)
2445 obstack_alloc (psymbol_obstack
,
2446 number_dependencies
* sizeof (struct partial_symtab
*));
2447 bcopy (dependency_list
, pst
->dependencies
,
2448 number_dependencies
* sizeof (struct partial_symtab
*));
2451 pst
->dependencies
= 0;
2453 for (i
= 0; i
< num_includes
; i
++)
2455 /* Eventually, put this on obstack */
2456 struct partial_symtab
*subpst
=
2457 (struct partial_symtab
*)
2458 obstack_alloc (psymbol_obstack
,
2459 sizeof (struct partial_symtab
));
2462 (char *) obstack_alloc (psymbol_obstack
,
2463 strlen (include_list
[i
]) + 1);
2464 strcpy (subpst
->filename
, include_list
[i
]);
2466 subpst
->symfile_name
= pst
->symfile_name
;
2467 subpst
->addr
= pst
->addr
;
2471 subpst
->texthigh
= 0;
2473 subpst
->dependencies
= (struct partial_symtab
**)
2474 obstack_alloc (psymbol_obstack
,
2475 sizeof (struct partial_symtab
*));
2476 subpst
->dependencies
[0] = pst
;
2477 subpst
->number_of_dependencies
= 1;
2479 subpst
->globals_offset
=
2480 subpst
->n_global_syms
=
2481 subpst
->statics_offset
=
2482 subpst
->n_static_syms
= 0;
2485 subpst
->read_symtab
= dbx_psymtab_to_symtab
;
2487 subpst
->next
= partial_symtab_list
;
2488 partial_symtab_list
= subpst
;
2491 /* Sort the global list; don't sort the static list */
2492 qsort (global_psymbols
.list
+ pst
->globals_offset
, pst
->n_global_syms
,
2493 sizeof (struct partial_symbol
), compare_psymbols
);
2495 /* Put the psymtab on the psymtab list */
2496 pst
->next
= partial_symtab_list
;
2497 partial_symtab_list
= pst
;
2501 psymtab_to_symtab_1 (pst
, desc
, stringtab
, stringtab_size
, sym_offset
)
2502 struct partial_symtab
*pst
;
2508 struct cleanup
*old_chain
;
2516 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2521 /* Read in all partial symbtabs on which this one is dependent */
2522 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2523 if (!pst
->dependencies
[i
]->readin
)
2525 /* Inform about additional files that need to be read in. */
2528 fputs_filtered (" ", stdout
);
2530 fputs_filtered ("and ", stdout
);
2532 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2533 wrap_here (""); /* Flush output */
2536 psymtab_to_symtab_1 (pst
->dependencies
[i
], desc
,
2537 stringtab
, stringtab_size
, sym_offset
);
2540 if (pst
->ldsymlen
) /* Otherwise it's a dummy */
2542 /* Init stuff necessary for reading in symbols */
2547 old_chain
= make_cleanup (really_free_pendings
, 0);
2549 /* Read in this files symbols */
2550 lseek (desc
, sym_offset
, L_SET
);
2551 read_ofile_symtab (desc
, stringtab
, stringtab_size
,
2553 pst
->ldsymlen
, pst
->textlow
,
2554 pst
->texthigh
- pst
->textlow
, pst
->addr
);
2555 sort_symtab_syms (symtab_list
); /* At beginning since just added */
2557 do_cleanups (old_chain
);
2564 * Read in all of the symbols for a given psymtab for real.
2565 * Be verbose about it if the user wants that.
2568 dbx_psymtab_to_symtab (pst
)
2569 struct partial_symtab
*pst
;
2574 struct stat statbuf
;
2575 struct cleanup
*old_chain
;
2584 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2589 if (pst
->ldsymlen
|| pst
->number_of_dependencies
)
2591 /* Print the message now, before reading the string table,
2592 to avoid disconcerting pauses. */
2595 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2599 /* Open symbol file and read in string table. Symbol_file_command
2600 guarantees that the symbol file name will be absolute, so there is
2601 no need for openp. */
2602 desc
= open(pst
->symfile_name
, O_RDONLY
, 0);
2605 perror_with_name (pst
->symfile_name
);
2607 sym_bfd
= bfd_fdopenr (pst
->symfile_name
, NULL
, desc
);
2611 error ("Could not open `%s' to read symbols: %s",
2612 pst
->symfile_name
, bfd_errmsg (bfd_error
));
2614 old_chain
= make_cleanup (bfd_close
, sym_bfd
);
2615 if (!bfd_check_format (sym_bfd
, bfd_object
))
2616 error ("\"%s\": can't read symbols: %s.",
2617 pst
->symfile_name
, bfd_errmsg (bfd_error
));
2619 /* We keep the string table for symfile resident in memory, but
2620 not the string table for any other symbol files. */
2621 if (0 != strcmp(pst
->symfile_name
, symfile
))
2623 /* Read in the string table */
2625 /* FIXME, this uses internal BFD variables. See above in
2626 dbx_symbol_file_open where the macro is defined! */
2627 lseek (desc
, STRING_TABLE_OFFSET
, L_SET
);
2629 val
= myread (desc
, &st_temp
, sizeof st_temp
);
2631 perror_with_name (pst
->symfile_name
);
2632 stsize
= bfd_h_getlong (sym_bfd
, (unsigned char *)&st_temp
);
2633 if (fstat (desc
, &statbuf
) < 0)
2634 perror_with_name (pst
->symfile_name
);
2636 if (stsize
>= 0 && stsize
< statbuf
.st_size
)
2638 #ifdef BROKEN_LARGE_ALLOCA
2639 stringtab
= (char *) xmalloc (stsize
);
2640 make_cleanup (free
, stringtab
);
2642 stringtab
= (char *) alloca (stsize
);
2647 if (stringtab
== NULL
&& stsize
!= 0)
2648 error ("ridiculous string table size: %d bytes", stsize
);
2650 /* FIXME, this uses internal BFD variables. See above in
2651 dbx_symbol_file_open where the macro is defined! */
2652 val
= lseek (desc
, STRING_TABLE_OFFSET
, L_SET
);
2654 perror_with_name (pst
->symfile_name
);
2655 val
= myread (desc
, stringtab
, stsize
);
2657 perror_with_name (pst
->symfile_name
);
2661 stringtab
= symfile_string_table
;
2662 stsize
= symfile_string_table_size
;
2665 symfile_bfd
= sym_bfd
; /* Kludge for SWAP_SYMBOL */
2667 /* FIXME, this uses internal BFD variables. See above in
2668 dbx_symbol_file_open where the macro is defined! */
2669 psymtab_to_symtab_1 (pst
, desc
, stringtab
, stsize
,
2670 SYMBOL_TABLE_OFFSET
);
2672 /* Match with global symbols. This only needs to be done once,
2673 after all of the symtabs and dependencies have been read in. */
2674 scan_file_globals ();
2676 do_cleanups (old_chain
);
2678 /* Finish up the debug error message. */
2680 printf_filtered ("done.\n");
2685 * Scan through all of the global symbols defined in the object file,
2686 * assigning values to the debugging symbols that need to be assigned
2687 * to. Get these symbols from the misc function list.
2690 scan_file_globals ()
2695 for (mf
= 0; mf
< misc_function_count
; mf
++)
2697 char *namestring
= misc_function_vector
[mf
].name
;
2698 struct symbol
*sym
, *prev
;
2702 prev
= (struct symbol
*) 0;
2704 /* Get the hash index and check all the symbols
2705 under that hash index. */
2707 hash
= hashname (namestring
);
2709 for (sym
= global_sym_chain
[hash
]; sym
;)
2711 if (*namestring
== SYMBOL_NAME (sym
)[0]
2712 && !strcmp(namestring
+ 1, SYMBOL_NAME (sym
) + 1))
2714 /* Splice this symbol out of the hash chain and
2715 assign the value we have to it. */
2717 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
2719 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
2721 /* Check to see whether we need to fix up a common block. */
2722 /* Note: this code might be executed several times for
2723 the same symbol if there are multiple references. */
2724 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2725 fix_common_block (sym
, misc_function_vector
[mf
].address
);
2727 SYMBOL_VALUE_ADDRESS (sym
) = misc_function_vector
[mf
].address
;
2730 sym
= SYMBOL_VALUE_CHAIN (prev
);
2732 sym
= global_sym_chain
[hash
];
2737 sym
= SYMBOL_VALUE_CHAIN (sym
);
2743 /* Process a pair of symbols. Currently they must both be N_SO's. */
2745 process_symbol_pair (type1
, desc1
, value1
, name1
,
2746 type2
, desc2
, value2
, name2
)
2756 /* No need to check PCC_SOL_BROKEN, on the assumption that such
2757 broken PCC's don't put out N_SO pairs. */
2758 if (last_source_file
)
2759 end_symtab (value2
);
2760 start_symtab (name2
, name1
, value2
);
2764 * Read in a defined section of a specific object file's symbols.
2766 * DESC is the file descriptor for the file, positioned at the
2767 * beginning of the symtab
2768 * STRINGTAB is a pointer to the files string
2769 * table, already read in
2770 * SYM_OFFSET is the offset within the file of
2771 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
2772 * number of symbols to read
2773 * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
2774 * TEXT_SIZE is the size of the text segment read in.
2775 * OFFSET is a relocation offset which gets added to each symbol
2779 read_ofile_symtab (desc
, stringtab
, stringtab_size
, sym_offset
,
2780 sym_size
, text_offset
, text_size
, offset
)
2782 register char *stringtab
;
2783 unsigned int stringtab_size
;
2786 CORE_ADDR text_offset
;
2790 register char *namestring
;
2795 stringtab_global
= stringtab
;
2796 last_source_file
= 0;
2798 symtab_input_desc
= desc
;
2799 symbuf_end
= symbuf_idx
= 0;
2801 /* It is necessary to actually read one symbol *before* the start
2802 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
2803 occurs before the N_SO symbol.
2805 Detecting this in read_dbx_symtab
2806 would slow down initial readin, so we look for it here instead. */
2807 if (sym_offset
>= (int)sizeof (struct nlist
))
2809 lseek (desc
, sym_offset
- sizeof (struct nlist
), L_INCR
);
2811 bufp
= &symbuf
[symbuf_idx
++];
2814 if (bufp
->n_un
.n_strx
< 0 || bufp
->n_un
.n_strx
>= stringtab_size
)
2815 error ("Invalid symbol data: bad string table offset: %d",
2817 namestring
= bufp
->n_un
.n_strx
+ stringtab
;
2819 processing_gcc_compilation
=
2820 (bufp
->n_type
== N_TEXT
2821 && !strcmp (namestring
, GCC_COMPILED_FLAG_SYMBOL
));
2825 /* The N_SO starting this symtab is the first symbol, so we
2826 better not check the symbol before it. I'm not this can
2827 happen, but it doesn't hurt to check for it. */
2828 lseek(desc
, sym_offset
, L_INCR
);
2829 processing_gcc_compilation
= 0;
2832 if (symbuf_idx
== symbuf_end
)
2834 bufp
= &symbuf
[symbuf_idx
];
2835 if (bufp
->n_type
!= (unsigned char)N_SO
)
2836 error("First symbol in segment of executable not a source symbol");
2839 symnum
< sym_size
/ sizeof(struct nlist
);
2842 QUIT
; /* Allow this to be interruptable */
2843 if (symbuf_idx
== symbuf_end
)
2845 bufp
= &symbuf
[symbuf_idx
++];
2848 type
= bufp
->n_type
& N_TYPE
;
2849 if (type
== (unsigned char)N_CATCH
)
2851 /* N_CATCH is not fixed up by the linker, and unfortunately,
2852 there's no other place to put it in the .stab map. */
2853 /* FIXME, do we also have to add OFFSET or something? -- gnu@cygnus */
2854 bufp
->n_value
+= text_offset
;
2856 else if (type
== N_TEXT
|| type
== N_DATA
|| type
== N_BSS
)
2857 bufp
->n_value
+= offset
;
2859 type
= bufp
->n_type
;
2860 if (bufp
->n_un
.n_strx
< 0 || bufp
->n_un
.n_strx
>= stringtab_size
)
2861 error ("Invalid symbol data: bad string table offset: %d",
2863 namestring
= bufp
->n_un
.n_strx
+ stringtab
;
2867 short desc
= bufp
->n_desc
;
2868 unsigned long valu
= bufp
->n_value
;
2870 /* Check for a pair of N_SO symbols. */
2871 if (type
== (unsigned char)N_SO
)
2873 if (symbuf_idx
== symbuf_end
)
2875 bufp
= &symbuf
[symbuf_idx
];
2876 if (bufp
->n_type
== (unsigned char)N_SO
)
2881 bufp
->n_value
+= offset
; /* Relocate */
2885 if (bufp
->n_un
.n_strx
< 0
2886 || bufp
->n_un
.n_strx
>= stringtab_size
)
2887 error ("Invalid symbol data: bad string table offset: %d",
2889 namestring2
= bufp
->n_un
.n_strx
+ stringtab
;
2891 process_symbol_pair (N_SO
, desc
, valu
, namestring
,
2892 N_SO
, bufp
->n_desc
, bufp
->n_value
,
2896 process_one_symbol(type
, desc
, valu
, namestring
);
2899 process_one_symbol (type
, desc
, valu
, namestring
);
2901 /* We skip checking for a new .o or -l file; that should never
2902 happen in this routine. */
2903 else if (type
== N_TEXT
2904 && !strcmp (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
2905 /* I don't think this code will ever be executed, because
2906 the GCC_COMPILED_FLAG_SYMBOL usually is right before
2907 the N_SO symbol which starts this source file.
2908 However, there is no reason not to accept
2909 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
2910 processing_gcc_compilation
= 1;
2911 else if (type
& N_EXT
|| type
== (unsigned char)N_TEXT
2912 || type
== (unsigned char)N_NBTEXT
2914 /* Global symbol: see if we came across a dbx defintion for
2915 a corresponding symbol. If so, store the value. Remove
2916 syms from the chain when their values are stored, but
2917 search the whole chain, as there may be several syms from
2918 different files with the same name. */
2919 /* This is probably not true. Since the files will be read
2920 in one at a time, each reference to a global symbol will
2921 be satisfied in each file as it appears. So we skip this
2925 end_symtab (text_offset
+ text_size
);
2932 register char *p
= name
;
2933 register int total
= p
[0];
2946 /* Ensure result is positive. */
2947 if (total
< 0) total
+= (1000 << 6);
2948 return total
% HASHSIZE
;
2953 process_one_symbol (type
, desc
, valu
, name
)
2958 #ifndef SUN_FIXED_LBRAC_BUG
2959 /* This records the last pc address we've seen. We depend on their being
2960 an SLINE or FUN or SO before the first LBRAC, since the variable does
2961 not get reset in between reads of different symbol files. */
2962 static CORE_ADDR last_pc_address
;
2964 register struct context_stack
*new;
2967 /* Something is wrong if we see real data before
2968 seeing a source file name. */
2970 if (last_source_file
== 0 && type
!= (unsigned char)N_SO
)
2972 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
2973 where that code is defined. */
2974 if (IGNORE_SYMBOL (type
))
2977 /* FIXME, this should not be an error, since it precludes extending
2978 the symbol table information in this way... */
2979 error ("Invalid symbol data: does not start by identifying a source file.");
2986 /* Either of these types of symbols indicates the start of
2987 a new function. We must process its "name" normally for dbx,
2988 but also record the start of a new lexical context, and possibly
2989 also the end of the lexical context for the previous function. */
2990 /* This is not always true. This type of symbol may indicate a
2991 text segment variable. */
2993 #ifndef SUN_FIXED_LBRAC_BUG
2994 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
2997 colon_pos
= strchr (name
, ':');
2999 || (*colon_pos
!= 'f' && *colon_pos
!= 'F'))
3001 define_symbol (valu
, name
, desc
, type
);
3005 within_function
= 1;
3006 if (context_stack_depth
> 0)
3008 new = &context_stack
[--context_stack_depth
];
3009 /* Make a block for the local symbols within. */
3010 finish_block (new->name
, &local_symbols
, new->old_blocks
,
3011 new->start_addr
, valu
);
3013 /* Stack must be empty now. */
3014 if (context_stack_depth
!= 0)
3015 error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.",
3018 new = &context_stack
[context_stack_depth
++];
3019 new->old_blocks
= pending_blocks
;
3020 new->start_addr
= valu
;
3021 new->name
= define_symbol (valu
, name
, desc
, type
);
3026 /* Record the address at which this catch takes place. */
3027 define_symbol (valu
, name
, desc
, type
);
3031 /* Don't know what to do with these yet. */
3032 error ("action uncertain for eh extensions");
3036 /* This "symbol" just indicates the start of an inner lexical
3037 context within a function. */
3039 #if !defined (BLOCK_ADDRESS_ABSOLUTE)
3040 /* On most machines, the block addresses are relative to the
3041 N_SO, the linker did not relocate them (sigh). */
3042 valu
+= last_source_start_addr
;
3045 #ifndef SUN_FIXED_LBRAC_BUG
3046 if (valu
< last_pc_address
) {
3047 /* Patch current LBRAC pc value to match last handy pc value */
3048 complain (&lbrac_complaint
, 0);
3049 valu
= last_pc_address
;
3052 if (context_stack_depth
== context_stack_size
)
3054 context_stack_size
*= 2;
3055 context_stack
= (struct context_stack
*)
3056 xrealloc (context_stack
,
3058 * sizeof (struct context_stack
)));
3061 new = &context_stack
[context_stack_depth
++];
3063 new->locals
= local_symbols
;
3064 new->old_blocks
= pending_blocks
;
3065 new->start_addr
= valu
;
3071 /* This "symbol" just indicates the end of an inner lexical
3072 context that was started with N_LBRAC. */
3074 #if !defined (BLOCK_ADDRESS_ABSOLUTE)
3075 /* On most machines, the block addresses are relative to the
3076 N_SO, the linker did not relocate them (sigh). */
3077 valu
+= last_source_start_addr
;
3080 new = &context_stack
[--context_stack_depth
];
3081 if (desc
!= new->depth
)
3082 error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum
);
3084 /* Some compilers put the variable decls inside of an
3085 LBRAC/RBRAC block. This macro should be nonzero if this
3086 is true. DESC is N_DESC from the N_RBRAC symbol.
3087 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL. */
3088 #if !defined (VARIABLES_INSIDE_BLOCK)
3089 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
3092 /* Can only use new->locals as local symbols here if we're in
3093 gcc or on a machine that puts them before the lbrack. */
3094 if (!VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
))
3095 local_symbols
= new->locals
;
3097 /* If this is not the outermost LBRAC...RBRAC pair in the
3098 function, its local symbols preceded it, and are the ones
3099 just recovered from the context stack. Defined the block for them.
3101 If this is the outermost LBRAC...RBRAC pair, there is no
3102 need to do anything; leave the symbols that preceded it
3103 to be attached to the function's own block. However, if
3104 it is so, we need to indicate that we just moved outside
3107 && (context_stack_depth
3108 > !VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
)))
3110 /* FIXME Muzzle a compiler bug that makes end < start. */
3111 if (new->start_addr
> valu
)
3113 complain(&lbrac_rbrac_complaint
, 0);
3114 new->start_addr
= valu
;
3116 /* Make a block for the local symbols within. */
3117 finish_block (0, &local_symbols
, new->old_blocks
,
3118 new->start_addr
, valu
);
3122 within_function
= 0;
3124 if (VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
))
3125 /* Now pop locals of block just finished. */
3126 local_symbols
= new->locals
;
3130 /* This kind of symbol supposedly indicates the start
3131 of an object file. In fact this type does not appear. */
3135 /* This type of symbol indicates the start of data
3136 for one source file.
3137 Finish the symbol table of the previous source file
3138 (if any) and start accumulating a new symbol table. */
3139 #ifndef SUN_FIXED_LBRAC_BUG
3140 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
3143 #ifdef PCC_SOL_BROKEN
3144 /* pcc bug, occasionally puts out SO for SOL. */
3145 if (context_stack_depth
> 0)
3147 start_subfile (name
, NULL
);
3151 if (last_source_file
)
3153 start_symtab (name
, NULL
, valu
);
3157 /* This type of symbol indicates the start of data for
3158 a sub-source-file, one whose contents were copied or
3159 included in the compilation of the main source file
3160 (whose name was given in the N_SO symbol.) */
3161 start_subfile (name
, NULL
);
3166 add_new_header_file (name
, valu
);
3167 start_subfile (name
, NULL
);
3171 start_subfile (pop_subfile (), NULL
);
3175 add_old_header_file (name
, valu
);
3179 /* This type of "symbol" really just records
3180 one line-number -- core-address correspondence.
3181 Enter it in the line list for this symbol table. */
3182 #ifndef SUN_FIXED_LBRAC_BUG
3183 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
3185 record_line (desc
, valu
);
3190 error ("Invalid symbol data: common within common at symtab pos %d",
3192 common_block
= local_symbols
;
3193 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3197 /* Symbols declared since the BCOMM are to have the common block
3198 start address added in when we know it. common_block points to
3199 the first symbol after the BCOMM in the local_symbols list;
3200 copy the list and hang it off the symbol for the common block name
3204 struct symbol
*sym
=
3205 (struct symbol
*) xmalloc (sizeof (struct symbol
));
3206 bzero (sym
, sizeof *sym
);
3207 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
3208 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3209 SYMBOL_NAMESPACE (sym
) = (enum namespace)((long)
3210 copy_pending (local_symbols
, common_block_i
, common_block
));
3211 i
= hashname (SYMBOL_NAME (sym
));
3212 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3213 global_sym_chain
[i
] = sym
;
3224 define_symbol (valu
, name
, desc
, type
);
3228 /* Read a number by which a type is referred to in dbx data,
3229 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
3230 Just a single number N is equivalent to (0,N).
3231 Return the two numbers by storing them in the vector TYPENUMS.
3232 TYPENUMS will then be used as an argument to dbx_lookup_type. */
3235 read_type_number (pp
, typenums
)
3237 register int *typenums
;
3242 typenums
[0] = read_number (pp
, ',');
3243 typenums
[1] = read_number (pp
, ')');
3248 typenums
[1] = read_number (pp
, 0);
3252 /* To handle GNU C++ typename abbreviation, we need to be able to
3253 fill in a type's name as soon as space for that type is allocated.
3254 `type_synonym_name' is the name of the type being allocated.
3255 It is cleared as soon as it is used (lest all allocated types
3257 static char *type_synonym_name
;
3259 static struct symbol
*
3260 define_symbol (valu
, string
, desc
, type
)
3266 register struct symbol
*sym
;
3267 char *p
= (char *) strchr (string
, ':');
3272 /* Ignore syms with empty names. */
3276 /* Ignore old-style symbols from cc -go */
3280 sym
= (struct symbol
*)obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
3282 if (processing_gcc_compilation
) {
3283 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
3284 number of bytes occupied by a type or object, which we ignore. */
3285 SYMBOL_LINE(sym
) = desc
;
3287 SYMBOL_LINE(sym
) = 0; /* unknown */
3290 if (string
[0] == CPLUS_MARKER
)
3292 /* Special GNU C++ names. */
3296 SYMBOL_NAME (sym
) = "this";
3298 case 'v': /* $vtbl_ptr_type */
3299 /* Was: SYMBOL_NAME (sym) = "vptr"; */
3302 SYMBOL_NAME (sym
) = "eh_throw";
3306 /* This was an anonymous type that was never fixed up. */
3317 = (char *) obstack_alloc (symbol_obstack
, ((p
- string
) + 1));
3318 /* Open-coded bcopy--saves function call time. */
3320 register char *p1
= string
;
3321 register char *p2
= SYMBOL_NAME (sym
);
3328 /* Determine the type of name being defined. */
3329 /* The Acorn RISC machine's compiler can put out locals that don't
3330 start with "234=" or "(3,4)=", so assume anything other than the
3331 deftypes we know how to handle is a local. */
3332 /* (Peter Watkins @ Computervision)
3333 Handle Sun-style local fortran array types 'ar...' .
3334 (gnu@cygnus.com) -- this strchr() handles them properly?
3335 (tiemann@cygnus.com) -- 'C' is for catch. */
3336 if (!strchr ("cfFGpPrStTvVXC", *p
))
3341 /* c is a special case, not followed by a type-number.
3342 SYMBOL:c=iVALUE for an integer constant symbol.
3343 SYMBOL:c=rVALUE for a floating constant symbol.
3344 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3345 e.g. "b:c=e6,0" for "const b = blob1"
3346 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3350 error ("Invalid symbol data at symtab pos %d.", symnum
);
3355 double d
= atof (p
);
3358 SYMBOL_TYPE (sym
) = builtin_type_double
;
3359 valu
= (char *) obstack_alloc (symbol_obstack
, sizeof (double));
3360 bcopy (&d
, valu
, sizeof (double));
3361 SWAP_TARGET_AND_HOST (valu
, sizeof (double));
3362 SYMBOL_VALUE_BYTES (sym
) = valu
;
3363 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
3368 SYMBOL_TYPE (sym
) = builtin_type_int
;
3369 SYMBOL_VALUE (sym
) = atoi (p
);
3370 SYMBOL_CLASS (sym
) = LOC_CONST
;
3374 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3375 e.g. "b:c=e6,0" for "const b = blob1"
3376 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3380 read_type_number (&p
, typenums
);
3382 error ("Invalid symbol data: no comma in enum const symbol");
3384 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
3385 SYMBOL_VALUE (sym
) = atoi (p
);
3386 SYMBOL_CLASS (sym
) = LOC_CONST
;
3390 error ("Invalid symbol data at symtab pos %d.", symnum
);
3392 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3393 add_symbol_to_list (sym
, &file_symbols
);
3397 /* Now usually comes a number that says which data type,
3398 and possibly more stuff to define the type
3399 (all of which is handled by read_type) */
3401 if (deftype
== 'p' && *p
== 'F')
3402 /* pF is a two-letter code that means a function parameter in Fortran.
3403 The type-number specifies the type of the return value.
3404 Translate it into a pointer-to-function type. */
3408 = lookup_pointer_type (lookup_function_type (read_type (&p
)));
3413 synonym
= *p
== 't';
3418 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
3419 strlen (SYMBOL_NAME (sym
)));
3422 type
= read_type (&p
);
3424 if ((deftype
== 'F' || deftype
== 'f')
3425 && TYPE_CODE (type
) != TYPE_CODE_FUNC
)
3426 SYMBOL_TYPE (sym
) = lookup_function_type (type
);
3428 SYMBOL_TYPE (sym
) = type
;
3434 /* The name of a caught exception. */
3435 SYMBOL_CLASS (sym
) = LOC_LABEL
;
3436 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3437 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
3438 add_symbol_to_list (sym
, &local_symbols
);
3442 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3443 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3444 add_symbol_to_list (sym
, &file_symbols
);
3448 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3449 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3450 add_symbol_to_list (sym
, &global_symbols
);
3454 /* For a class G (global) symbol, it appears that the
3455 value is not correct. It is necessary to search for the
3456 corresponding linker definition to find the value.
3457 These definitions appear at the end of the namelist. */
3458 i
= hashname (SYMBOL_NAME (sym
));
3459 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3460 global_sym_chain
[i
] = sym
;
3461 SYMBOL_CLASS (sym
) = LOC_STATIC
;
3462 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3463 add_symbol_to_list (sym
, &global_symbols
);
3466 /* This case is faked by a conditional above,
3467 when there is no code letter in the dbx data.
3468 Dbx data never actually contains 'l'. */
3470 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
3471 SYMBOL_VALUE (sym
) = valu
;
3472 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3473 add_symbol_to_list (sym
, &local_symbols
);
3477 /* Normally this is a parameter, a LOC_ARG. On the i960, it
3478 can also be a LOC_LOCAL_ARG depending on symbol type. */
3479 #ifndef DBX_PARM_SYMBOL_CLASS
3480 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
3482 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
3483 SYMBOL_VALUE (sym
) = valu
;
3484 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3485 add_symbol_to_list (sym
, &local_symbols
);
3487 /* If it's gcc-compiled, if it says `short', believe it. */
3488 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
3491 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
3492 /* This macro is defined on machines (e.g. sparc) where
3493 we should believe the type of a PCC 'short' argument,
3494 but shouldn't believe the address (the address is
3495 the address of the corresponding int). Note that
3496 this is only different from the BELIEVE_PCC_PROMOTION
3497 case on big-endian machines.
3499 My guess is that this correction, as opposed to changing
3500 the parameter to an 'int' (as done below, for PCC
3501 on most machines), is the right thing to do
3502 on all machines, but I don't want to risk breaking
3503 something that already works. On most PCC machines,
3504 the sparc problem doesn't come up because the calling
3505 function has to zero the top bytes (not knowing whether
3506 the called function wants an int or a short), so there
3507 is no practical difference between an int and a short
3508 (except perhaps what happens when the GDB user types
3509 "print short_arg = 0x10000;").
3511 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
3512 actually produces the correct address (we don't need to fix it
3513 up). I made this code adapt so that it will offset the symbol
3514 if it was pointing at an int-aligned location and not
3515 otherwise. This way you can use the same gdb for 4.0.x and
3518 if (0 == SYMBOL_VALUE (sym
) % sizeof (int))
3520 if (SYMBOL_TYPE (sym
) == builtin_type_char
3521 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
)
3522 SYMBOL_VALUE (sym
) += 3;
3523 else if (SYMBOL_TYPE (sym
) == builtin_type_short
3524 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
3525 SYMBOL_VALUE (sym
) += 2;
3529 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
3531 /* If PCC says a parameter is a short or a char,
3532 it is really an int. */
3533 if (SYMBOL_TYPE (sym
) == builtin_type_char
3534 || SYMBOL_TYPE (sym
) == builtin_type_short
)
3535 SYMBOL_TYPE (sym
) = builtin_type_int
;
3536 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
3537 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
3538 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
3541 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
3544 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
3545 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
3546 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3547 add_symbol_to_list (sym
, &local_symbols
);
3551 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
3552 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
3553 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3554 add_symbol_to_list (sym
, &local_symbols
);
3558 /* Static symbol at top level of file */
3559 SYMBOL_CLASS (sym
) = LOC_STATIC
;
3560 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
3561 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3562 add_symbol_to_list (sym
, &file_symbols
);
3566 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
3567 SYMBOL_VALUE (sym
) = valu
;
3568 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3569 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
3570 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
3571 TYPE_NAME (SYMBOL_TYPE (sym
)) =
3572 obsavestring (SYMBOL_NAME (sym
),
3573 strlen (SYMBOL_NAME (sym
)));
3574 /* C++ vagaries: we may have a type which is derived from
3575 a base type which did not have its name defined when the
3576 derived class was output. We fill in the derived class's
3577 base part member's name here in that case. */
3578 else if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
3579 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
3580 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
3583 for (i
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; i
>= 0; i
--)
3584 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), i
) == 0)
3585 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), i
) =
3586 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), i
));
3589 add_symbol_to_list (sym
, &file_symbols
);
3593 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
3594 SYMBOL_VALUE (sym
) = valu
;
3595 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
3596 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
3597 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
3598 TYPE_NAME (SYMBOL_TYPE (sym
))
3600 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
3602 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
3603 ? "struct " : "union ")),
3605 add_symbol_to_list (sym
, &file_symbols
);
3609 register struct symbol
*typedef_sym
3610 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
3611 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
3612 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
3614 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
3615 SYMBOL_VALUE (typedef_sym
) = valu
;
3616 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
3617 add_symbol_to_list (typedef_sym
, &file_symbols
);
3622 /* Static symbol of local scope */
3623 SYMBOL_CLASS (sym
) = LOC_STATIC
;
3624 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
3625 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3626 add_symbol_to_list (sym
, &local_symbols
);
3630 /* Reference parameter */
3631 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
3632 SYMBOL_VALUE (sym
) = valu
;
3633 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3634 add_symbol_to_list (sym
, &local_symbols
);
3638 /* This is used by Sun FORTRAN for "function result value".
3639 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
3640 that Pascal uses it too, but when I tried it Pascal used
3641 "x:3" (local symbol) instead. */
3642 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
3643 SYMBOL_VALUE (sym
) = valu
;
3644 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3645 add_symbol_to_list (sym
, &local_symbols
);
3649 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
3654 /* What about types defined as forward references inside of a small lexical
3656 /* Add a type to the list of undefined types to be checked through
3657 once this file has been read in. */
3659 add_undefined_type (type
)
3662 if (undef_types_length
== undef_types_allocated
)
3664 undef_types_allocated
*= 2;
3665 undef_types
= (struct type
**)
3666 xrealloc (undef_types
,
3667 undef_types_allocated
* sizeof (struct type
*));
3669 undef_types
[undef_types_length
++] = type
;
3672 /* Add here something to go through each undefined type, see if it's
3673 still undefined, and do a full lookup if so. */
3675 cleanup_undefined_types ()
3679 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3681 /* Reasonable test to see if it's been defined since. */
3682 if (TYPE_NFIELDS (*type
) == 0)
3684 struct pending
*ppt
;
3686 /* Name of the type, without "struct" or "union" */
3687 char *typename
= TYPE_NAME (*type
);
3689 if (!strncmp (typename
, "struct ", 7))
3691 if (!strncmp (typename
, "union ", 6))
3694 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3695 for (i
= 0; i
< ppt
->nsyms
; i
++)
3697 struct symbol
*sym
= ppt
->symbol
[i
];
3699 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3700 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3701 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3703 && !strcmp (SYMBOL_NAME (sym
), typename
))
3704 bcopy (SYMBOL_TYPE (sym
), *type
, sizeof (struct type
));
3708 /* It has been defined; don't mark it as a stub. */
3709 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
3711 undef_types_length
= 0;
3714 /* Skip rest of this symbol and return an error type.
3716 General notes on error recovery: error_type always skips to the
3717 end of the symbol (modulo cretinous dbx symbol name continuation).
3718 Thus code like this:
3720 if (*(*pp)++ != ';')
3721 return error_type (pp);
3723 is wrong because if *pp starts out pointing at '\0' (typically as the
3724 result of an earlier error), it will be incremented to point to the
3725 start of the next symbol, which might produce strange results, at least
3726 if you run off the end of the string table. Instead use
3729 return error_type (pp);
3735 foo = error_type (pp);
3739 And in case it isn't obvious, the point of all this hair is so the compiler
3740 can define new types and new syntaxes, and old versions of the
3741 debugger will be able to read the new symbol tables. */
3743 static struct type
*
3747 complain (&error_type_complaint
, 0);
3750 /* Skip to end of symbol. */
3751 while (**pp
!= '\0')
3754 /* Check for and handle cretinous dbx symbol name continuation! */
3755 if ((*pp
)[-1] == '\\')
3756 *pp
= next_symbol_text ();
3760 return builtin_type_error
;
3763 /* Read a dbx type reference or definition;
3764 return the type that is meant.
3765 This can be just a number, in which case it references
3766 a type already defined and placed in type_vector.
3767 Or the number can be followed by an =, in which case
3768 it means to define a new type according to the text that
3776 register struct type
*type
= 0;
3781 /* Read type number if present. The type number may be omitted.
3782 for instance in a two-dimensional array declared with type
3783 "ar1;1;10;ar1;1;10;4". */
3784 if ((**pp
>= '0' && **pp
<= '9')
3787 read_type_number (pp
, typenums
);
3789 /* Detect random reference to type not yet defined.
3790 Allocate a type object but leave it zeroed. */
3792 return dbx_alloc_type (typenums
);
3798 /* 'typenums=' not present, type is anonymous. Read and return
3799 the definition, but don't put it in the type vector. */
3800 typenums
[0] = typenums
[1] = -1;
3808 enum type_code code
;
3810 /* Used to index through file_symbols. */
3811 struct pending
*ppt
;
3814 /* Name including "struct", etc. */
3817 /* Name without "struct", etc. */
3818 char *type_name_only
;
3824 /* Set the type code according to the following letter. */
3828 code
= TYPE_CODE_STRUCT
;
3832 code
= TYPE_CODE_UNION
;
3836 code
= TYPE_CODE_ENUM
;
3840 return error_type (pp
);
3843 to
= type_name
= (char *)
3844 obstack_alloc (symbol_obstack
,
3846 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
3848 /* Copy the prefix. */
3850 while (*to
++ = *from
++)
3854 type_name_only
= to
;
3856 /* Copy the name. */
3858 while ((*to
++ = *from
++) != ':')
3862 /* Set the pointer ahead of the name which we just read. */
3866 /* The following hack is clearly wrong, because it doesn't
3867 check whether we are in a baseclass. I tried to reproduce
3868 the case that it is trying to fix, but I couldn't get
3869 g++ to put out a cross reference to a basetype. Perhaps
3870 it doesn't do it anymore. */
3871 /* Note: for C++, the cross reference may be to a base type which
3872 has not yet been seen. In this case, we skip to the comma,
3873 which will mark the end of the base class name. (The ':'
3874 at the end of the base class name will be skipped as well.)
3875 But sometimes (ie. when the cross ref is the last thing on
3876 the line) there will be no ','. */
3877 from
= (char *) strchr (*pp
, ',');
3883 /* Now check to see whether the type has already been declared. */
3884 /* This is necessary at least in the case where the
3885 program says something like
3887 The compiler puts out a cross-reference; we better find
3888 set the length of the structure correctly so we can
3889 set the length of the array. */
3890 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3891 for (i
= 0; i
< ppt
->nsyms
; i
++)
3893 struct symbol
*sym
= ppt
->symbol
[i
];
3895 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3896 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3897 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
3898 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
3900 obstack_free (symbol_obstack
, type_name
);
3901 type
= SYMBOL_TYPE (sym
);
3906 /* Didn't find the type to which this refers, so we must
3907 be dealing with a forward reference. Allocate a type
3908 structure for it, and keep track of it so we can
3909 fill in the rest of the fields when we get the full
3911 type
= dbx_alloc_type (typenums
);
3912 TYPE_CODE (type
) = code
;
3913 TYPE_NAME (type
) = type_name
;
3915 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3917 add_undefined_type (type
);
3933 read_type_number (pp
, xtypenums
);
3934 type
= *dbx_lookup_type (xtypenums
);
3936 type
= builtin_type_void
;
3937 if (typenums
[0] != -1)
3938 *dbx_lookup_type (typenums
) = type
;
3942 type1
= read_type (pp
);
3943 type
= lookup_pointer_type (type1
);
3944 if (typenums
[0] != -1)
3945 *dbx_lookup_type (typenums
) = type
;
3950 struct type
*domain
= read_type (pp
);
3951 struct type
*memtype
;
3954 /* Invalid member type data format. */
3955 return error_type (pp
);
3958 memtype
= read_type (pp
);
3959 type
= dbx_alloc_type (typenums
);
3960 smash_to_member_type (type
, domain
, memtype
);
3965 if ((*pp
)[0] == '#')
3967 /* We'll get the parameter types from the name. */
3968 struct type
*return_type
;
3971 return_type
= read_type (pp
);
3972 if (*(*pp
)++ != ';')
3973 complain (&invalid_member_complaint
, symnum
);
3974 type
= lookup_function_type (return_type
);
3975 if (typenums
[0] != -1)
3976 *dbx_lookup_type (typenums
) = type
;
3977 TYPE_CODE (type
) = TYPE_CODE_METHOD
;
3978 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3982 struct type
*domain
= read_type (pp
);
3983 struct type
*return_type
;
3986 if (*(*pp
)++ != ',')
3987 error ("invalid member type data format, at symtab pos %d.",
3990 return_type
= read_type (pp
);
3991 args
= read_args (pp
, ';');
3992 type
= dbx_alloc_type (typenums
);
3993 smash_to_method_type (type
, domain
, return_type
, args
);
3998 type1
= read_type (pp
);
3999 type
= lookup_reference_type (type1
);
4000 if (typenums
[0] != -1)
4001 *dbx_lookup_type (typenums
) = type
;
4005 type1
= read_type (pp
);
4006 type
= lookup_function_type (type1
);
4007 if (typenums
[0] != -1)
4008 *dbx_lookup_type (typenums
) = type
;
4012 type
= read_range_type (pp
, typenums
);
4013 if (typenums
[0] != -1)
4014 *dbx_lookup_type (typenums
) = type
;
4018 type
= dbx_alloc_type (typenums
);
4019 type
= read_enum_type (pp
, type
);
4020 *dbx_lookup_type (typenums
) = type
;
4024 type
= dbx_alloc_type (typenums
);
4025 TYPE_NAME (type
) = type_synonym_name
;
4026 type_synonym_name
= 0;
4027 type
= read_struct_type (pp
, type
);
4031 type
= dbx_alloc_type (typenums
);
4032 TYPE_NAME (type
) = type_synonym_name
;
4033 type_synonym_name
= 0;
4034 type
= read_struct_type (pp
, type
);
4035 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4040 return error_type (pp
);
4043 type
= dbx_alloc_type (typenums
);
4044 type
= read_array_type (pp
, type
);
4048 return error_type (pp
);
4055 /* If this is an overriding temporary alteration for a header file's
4056 contents, and this type number is unknown in the global definition,
4057 put this type into the global definition at this type number. */
4058 if (header_file_prev_index
>= 0)
4060 register struct type
**tp
4061 = explicit_lookup_type (header_file_prev_index
, typenums
[1]);
4070 /* This would be a good idea, but it doesn't really work. The problem
4071 is that in order to get the virtual context for a particular type,
4072 you need to know the virtual info from all of its basetypes,
4073 and you need to have processed its methods. Since GDB reads
4074 symbols on a file-by-file basis, this means processing the symbols
4075 of all the files that are needed for each baseclass, which
4076 means potentially reading in all the debugging info just to fill
4077 in information we may never need. */
4079 /* This page contains subroutines of read_type. */
4081 /* FOR_TYPE is a struct type defining a virtual function NAME with type
4082 FN_TYPE. The `virtual context' for this virtual function is the
4083 first base class of FOR_TYPE in which NAME is defined with signature
4084 matching FN_TYPE. OFFSET serves as a hash on matches here.
4086 TYPE is the current type in which we are searching. */
4088 static struct type
*
4089 virtual_context (for_type
, type
, name
, fn_type
, offset
)
4090 struct type
*for_type
, *type
;
4092 struct type
*fn_type
;
4095 struct type
*basetype
= 0;
4098 if (for_type
!= type
)
4100 /* Check the methods of TYPE. */
4101 /* Need to do a check_stub_type here, but that breaks
4102 things because we can get infinite regress. */
4103 for (i
= TYPE_NFN_FIELDS (type
) - 1; i
>= 0; --i
)
4104 if (!strcmp (TYPE_FN_FIELDLIST_NAME (type
, i
), name
))
4108 int j
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
4109 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
4112 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == offset
-1)
4113 return TYPE_FN_FIELD_FCONTEXT (f
, j
);
4116 for (i
= TYPE_N_BASECLASSES (type
); i
> 0; i
--)
4118 basetype
= virtual_context (for_type
, TYPE_BASECLASS (type
, i
), name
,
4120 if (basetype
!= for_type
)
4127 /* Read the description of a structure (or union type)
4128 and return an object describing the type. */
4130 static struct type
*
4131 read_struct_type (pp
, type
)
4133 register struct type
*type
;
4135 /* Total number of methods defined in this class.
4136 If the class defines two `f' methods, and one `g' method,
4137 then this will have the value 3. */
4138 int total_length
= 0;
4142 struct nextfield
*next
;
4143 int visibility
; /* 0=public, 1=protected, 2=public */
4149 struct next_fnfield
*next
;
4150 int visibility
; /* 0=public, 1=protected, 2=public */
4151 struct fn_field fn_field
;
4154 struct next_fnfieldlist
4156 struct next_fnfieldlist
*next
;
4157 struct fn_fieldlist fn_fieldlist
;
4160 register struct nextfield
*list
= 0;
4161 struct nextfield
*new;
4166 register struct next_fnfieldlist
*mainlist
= 0;
4169 if (TYPE_MAIN_VARIANT (type
) == 0)
4171 TYPE_MAIN_VARIANT (type
) = type
;
4174 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4176 /* First comes the total size in bytes. */
4178 TYPE_LENGTH (type
) = read_number (pp
, 0);
4180 /* C++: Now, if the class is a derived class, then the next character
4181 will be a '!', followed by the number of base classes derived from.
4182 Each element in the list contains visibility information,
4183 the offset of this base class in the derived structure,
4184 and then the base type. */
4187 int i
, n_baseclasses
, offset
;
4188 struct type
*baseclass
;
4191 /* Nonzero if it is a virtual baseclass, i.e.,
4195 struct C : public B, public virtual A {};
4197 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
4198 2.0 language feature. */
4203 n_baseclasses
= read_number (pp
, ',');
4204 TYPE_FIELD_VIRTUAL_BITS (type
) =
4205 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (n_baseclasses
));
4206 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
4208 for (i
= 0; i
< n_baseclasses
; i
++)
4211 *pp
= next_symbol_text ();
4222 /* Bad visibility format. */
4223 return error_type (pp
);
4236 /* Bad visibility format. */
4237 return error_type (pp
);
4240 SET_TYPE_FIELD_VIRTUAL (type
, i
);
4243 /* Offset of the portion of the object corresponding to
4244 this baseclass. Always zero in the absence of
4245 multiple inheritance. */
4246 offset
= read_number (pp
, ',');
4247 baseclass
= read_type (pp
);
4248 *pp
+= 1; /* skip trailing ';' */
4251 /* One's understanding improves, grasshopper... */
4254 static int error_printed
= 0;
4259 "\nWarning: GDB has limited understanding of multiple inheritance...");
4261 fprintf(stderr
, "\n");
4267 /* Make this baseclass visible for structure-printing purposes. */
4268 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
4271 list
->visibility
= via_public
;
4272 list
->field
.type
= baseclass
;
4273 list
->field
.name
= type_name_no_tag (baseclass
);
4274 list
->field
.bitpos
= offset
;
4275 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
4278 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
4281 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
4282 At the end, we see a semicolon instead of a field.
4284 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
4287 The `?' is a placeholder for one of '/2' (public visibility),
4288 '/1' (protected visibility), '/0' (private visibility), or nothing
4289 (C style symbol table, public visibility). */
4291 /* We better set p right now, in case there are no fields at all... */
4296 /* Check for and handle cretinous dbx symbol name continuation! */
4297 if (**pp
== '\\') *pp
= next_symbol_text ();
4299 /* Get space to record the next field's data. */
4300 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
4304 /* Get the field name. */
4306 if (*p
== CPLUS_MARKER
)
4308 /* Special GNU C++ name. */
4311 char *prefix
, *name
; /* FIXME: NAME never set! */
4312 struct type
*context
;
4323 error ("invalid abbreviation at symtab pos %d.", symnum
);
4326 context
= read_type (pp
);
4327 if (type_name_no_tag (context
) == 0)
4330 error ("type name unknown at symtab pos %d.", symnum
);
4331 TYPE_NAME (context
) = obsavestring (name
, p
- name
- 1);
4333 list
->field
.name
= obconcat (prefix
, type_name_no_tag (context
), "");
4336 error ("invalid abbreviation at symtab pos %d.", symnum
);
4337 list
->field
.type
= read_type (pp
);
4338 (*pp
)++; /* Skip the comma. */
4339 list
->field
.bitpos
= read_number (pp
, ';');
4340 /* This field is unpacked. */
4341 list
->field
.bitsize
= 0;
4344 error ("invalid abbreviation at symtab pos %d.", symnum
);
4350 while (*p
!= ':') p
++;
4351 list
->field
.name
= obsavestring (*pp
, p
- *pp
);
4353 /* C++: Check to see if we have hit the methods yet. */
4359 /* This means we have a visibility for a field coming. */
4365 list
->visibility
= 0; /* private */
4370 list
->visibility
= 1; /* protected */
4375 list
->visibility
= 2; /* public */
4380 else /* normal dbx-style format. */
4381 list
->visibility
= 2; /* public */
4383 list
->field
.type
= read_type (pp
);
4386 /* Static class member. */
4387 list
->field
.bitpos
= (long)-1;
4389 while (*p
!= ';') p
++;
4390 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
4395 else if (**pp
!= ',')
4396 /* Bad structure-type format. */
4397 return error_type (pp
);
4399 (*pp
)++; /* Skip the comma. */
4400 list
->field
.bitpos
= read_number (pp
, ',');
4401 list
->field
.bitsize
= read_number (pp
, ';');
4404 /* FIXME tiemann: what is the story here? What does the compiler
4405 really do? Also, patch gdb.texinfo for this case; I document
4406 it as a possible problem there. Search for "DBX-style". */
4408 /* This is wrong because this is identical to the symbols
4409 produced for GCC 0-size arrays. For example:
4414 The code which dumped core in such circumstances should be
4415 fixed not to dump core. */
4417 /* g++ -g0 can put out bitpos & bitsize zero for a static
4418 field. This does not give us any way of getting its
4419 class, so we can't know its name. But we can just
4420 ignore the field so we don't dump core and other nasty
4422 if (list
->field
.bitpos
== 0
4423 && list
->field
.bitsize
== 0)
4425 complain (&dbx_class_complaint
, 0);
4426 /* Ignore this field. */
4432 /* Detect an unpacked field and mark it as such.
4433 dbx gives a bit size for all fields.
4434 Note that forward refs cannot be packed,
4435 and treat enums as if they had the width of ints. */
4436 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
4437 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
4438 list
->field
.bitsize
= 0;
4439 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
4440 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
4441 && (list
->field
.bitsize
4442 == 8 * TYPE_LENGTH (builtin_type_int
))
4446 list
->field
.bitpos
% 8 == 0)
4447 list
->field
.bitsize
= 0;
4453 /* chill the list of fields: the last entry (at the head)
4454 is a partially constructed entry which we now scrub. */
4457 /* Now create the vector of fields, and record how big it is.
4458 We need this info to record proper virtual function table information
4459 for this class's virtual functions. */
4461 TYPE_NFIELDS (type
) = nfields
;
4462 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
,
4463 sizeof (struct field
) * nfields
);
4465 TYPE_FIELD_PRIVATE_BITS (type
) =
4466 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
4467 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4469 TYPE_FIELD_PROTECTED_BITS (type
) =
4470 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
4471 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4473 /* Copy the saved-up fields into the field vector. */
4475 for (n
= nfields
; list
; list
= list
->next
)
4478 TYPE_FIELD (type
, n
) = list
->field
;
4479 if (list
->visibility
== 0)
4480 SET_TYPE_FIELD_PRIVATE (type
, n
);
4481 else if (list
->visibility
== 1)
4482 SET_TYPE_FIELD_PROTECTED (type
, n
);
4485 /* Now come the method fields, as NAME::methods
4486 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
4487 At the end, we see a semicolon instead of a field.
4489 For the case of overloaded operators, the format is
4490 OPERATOR::*.methods, where OPERATOR is the string "operator",
4491 `*' holds the place for an operator name (such as `+=')
4492 and `.' marks the end of the operator name. */
4495 /* Now, read in the methods. To simplify matters, we
4496 "unread" the name that has been read, so that we can
4497 start from the top. */
4499 /* For each list of method lists... */
4503 struct next_fnfield
*sublist
= 0;
4505 struct next_fnfieldlist
*new_mainlist
=
4506 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
4511 /* read in the name. */
4512 while (*p
!= ':') p
++;
4513 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
4515 /* This lets the user type "break operator+".
4516 We could just put in "+" as the name, but that wouldn't
4518 static char opname
[32] = "operator";
4519 char *o
= opname
+ 8;
4521 /* Skip past '::'. */
4525 main_fn_name
= savestring (opname
, o
- opname
);
4532 main_fn_name
= savestring (*pp
, p
- *pp
);
4533 /* Skip past '::'. */
4536 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
4540 struct next_fnfield
*new_sublist
=
4541 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
4543 /* Check for and handle cretinous dbx symbol name continuation! */
4544 if (**pp
== '\\') *pp
= next_symbol_text ();
4546 new_sublist
->fn_field
.type
= read_type (pp
);
4548 /* Invalid symtab info for method. */
4549 return error_type (pp
);
4553 while (*p
!= ';') p
++;
4554 /* If this is just a stub, then we don't have the
4556 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
4558 new_sublist
->visibility
= *(*pp
)++ - '0';
4559 if (**pp
== '\\') *pp
= next_symbol_text ();
4560 /* FIXME: tiemann needs to add const/volatile info
4561 to the methods. For now, just skip the char.
4562 In future, here's what we need to implement:
4564 A for normal functions.
4565 B for `const' member functions.
4566 C for `volatile' member functions.
4567 D for `const volatile' member functions. */
4568 if (**pp
== 'A' || **pp
== 'B' || **pp
== 'C' || **pp
== 'D')
4571 complain(&const_vol_complaint
, **pp
);
4576 /* virtual member function, followed by index. */
4577 /* The sign bit is set to distinguish pointers-to-methods
4578 from virtual function indicies. Since the array is
4579 in words, the quantity must be shifted left by 1
4580 on 16 bit machine, and by 2 on 32 bit machine, forcing
4581 the sign bit out, and usable as a valid index into
4582 the array. Remove the sign bit here. */
4583 new_sublist
->fn_field
.voffset
=
4584 (0x7fffffff & read_number (pp
, ';')) + 1;
4586 /* Figure out from whence this virtual function came.
4587 It may belong to virtual function table of
4588 one of its baseclasses. */
4589 new_sublist
->fn_field
.fcontext
= read_type (pp
);
4597 /* static member function. */
4598 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
4602 /* normal member function. */
4603 new_sublist
->fn_field
.voffset
= 0;
4607 new_sublist
->next
= sublist
;
4608 sublist
= new_sublist
;
4611 while (**pp
!= ';' && *pp
!= '\0');
4615 new_mainlist
->fn_fieldlist
.fn_fields
=
4616 (struct fn_field
*) obstack_alloc (symbol_obstack
,
4617 sizeof (struct fn_field
) * length
);
4618 TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
) =
4619 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
4620 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
), length
);
4622 TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
) =
4623 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
4624 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
), length
);
4626 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
4628 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
4629 if (sublist
->visibility
== 0)
4630 B_SET (new_mainlist
->fn_fieldlist
.private_fn_field_bits
, i
);
4631 else if (sublist
->visibility
== 1)
4632 B_SET (new_mainlist
->fn_fieldlist
.protected_fn_field_bits
, i
);
4635 new_mainlist
->fn_fieldlist
.length
= length
;
4636 new_mainlist
->next
= mainlist
;
4637 mainlist
= new_mainlist
;
4639 total_length
+= length
;
4641 while (**pp
!= ';');
4646 TYPE_FN_FIELDLISTS (type
) =
4647 (struct fn_fieldlist
*) obstack_alloc (symbol_obstack
,
4648 sizeof (struct fn_fieldlist
) * nfn_fields
);
4650 TYPE_NFN_FIELDS (type
) = nfn_fields
;
4651 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4655 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
4656 TYPE_NFN_FIELDS_TOTAL (type
) +=
4657 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
4660 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
)
4661 TYPE_FN_FIELDLISTS (type
)[--n
] = mainlist
->fn_fieldlist
;
4670 |= TYPE_FLAG_HAS_CONSTRUCTOR
| TYPE_FLAG_HAS_DESTRUCTOR
;
4673 else if (**pp
== '+')
4675 TYPE_FLAGS (type
) |= TYPE_FLAG_HAS_CONSTRUCTOR
;
4678 else if (**pp
== '-')
4680 TYPE_FLAGS (type
) |= TYPE_FLAG_HAS_DESTRUCTOR
;
4684 /* Read either a '%' or the final ';'. */
4685 if (*(*pp
)++ == '%')
4687 /* Now we must record the virtual function table pointer's
4688 field information. */
4695 while (*p
!= '\0' && *p
!= ';')
4698 /* Premature end of symbol. */
4699 return error_type (pp
);
4701 TYPE_VPTR_BASETYPE (type
) = t
;
4704 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
4705 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
4706 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
4707 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
4708 sizeof (vptr_name
) -1))
4710 TYPE_VPTR_FIELDNO (type
) = i
;
4714 /* Virtual function table field not found. */
4715 return error_type (pp
);
4718 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4723 TYPE_VPTR_BASETYPE (type
) = 0;
4724 TYPE_VPTR_FIELDNO (type
) = -1;
4729 TYPE_VPTR_BASETYPE (type
) = 0;
4730 TYPE_VPTR_FIELDNO (type
) = -1;
4736 /* Read a definition of an array type,
4737 and create and return a suitable type object.
4738 Also creates a range type which represents the bounds of that
4740 static struct type
*
4741 read_array_type (pp
, type
)
4743 register struct type
*type
;
4745 struct type
*index_type
, *element_type
, *range_type
;
4749 /* Format of an array type:
4750 "ar<index type>;lower;upper;<array_contents_type>". Put code in
4753 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4754 for these, produce a type like float[][]. */
4756 index_type
= read_type (pp
);
4758 /* Improper format of array type decl. */
4759 return error_type (pp
);
4762 if (!(**pp
>= '0' && **pp
<= '9'))
4767 lower
= read_number (pp
, ';');
4769 if (!(**pp
>= '0' && **pp
<= '9'))
4774 upper
= read_number (pp
, ';');
4776 element_type
= read_type (pp
);
4785 /* Create range type. */
4786 range_type
= (struct type
*) obstack_alloc (symbol_obstack
,
4787 sizeof (struct type
));
4788 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
4789 TYPE_TARGET_TYPE (range_type
) = index_type
;
4791 /* This should never be needed. */
4792 TYPE_LENGTH (range_type
) = sizeof (int);
4794 TYPE_NFIELDS (range_type
) = 2;
4795 TYPE_FIELDS (range_type
) =
4796 (struct field
*) obstack_alloc (symbol_obstack
,
4797 2 * sizeof (struct field
));
4798 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
4799 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
4802 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
4803 TYPE_TARGET_TYPE (type
) = element_type
;
4804 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
4805 TYPE_NFIELDS (type
) = 1;
4806 TYPE_FIELDS (type
) =
4807 (struct field
*) obstack_alloc (symbol_obstack
,
4808 sizeof (struct field
));
4809 TYPE_FIELD_TYPE (type
, 0) = range_type
;
4815 /* Read a definition of an enumeration type,
4816 and create and return a suitable type object.
4817 Also defines the symbols that represent the values of the type. */
4819 static struct type
*
4820 read_enum_type (pp
, type
)
4822 register struct type
*type
;
4827 register struct symbol
*sym
;
4829 struct pending
**symlist
;
4830 struct pending
*osyms
, *syms
;
4833 if (within_function
)
4834 symlist
= &local_symbols
;
4836 symlist
= &file_symbols
;
4838 o_nsyms
= osyms
? osyms
->nsyms
: 0;
4840 /* Read the value-names and their values.
4841 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4842 A semicolon or comman instead of a NAME means the end. */
4843 while (**pp
&& **pp
!= ';' && **pp
!= ',')
4845 /* Check for and handle cretinous dbx symbol name continuation! */
4846 if (**pp
== '\\') *pp
= next_symbol_text ();
4849 while (*p
!= ':') p
++;
4850 name
= obsavestring (*pp
, p
- *pp
);
4852 n
= read_number (pp
, ',');
4854 sym
= (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
4855 bzero (sym
, sizeof (struct symbol
));
4856 SYMBOL_NAME (sym
) = name
;
4857 SYMBOL_CLASS (sym
) = LOC_CONST
;
4858 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4859 SYMBOL_VALUE (sym
) = n
;
4860 add_symbol_to_list (sym
, symlist
);
4865 (*pp
)++; /* Skip the semicolon. */
4867 /* Now fill in the fields of the type-structure. */
4869 TYPE_LENGTH (type
) = sizeof (int);
4870 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4871 TYPE_NFIELDS (type
) = nsyms
;
4872 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
4874 /* Find the symbols for the values and put them into the type.
4875 The symbols can be found in the symlist that we put them on
4876 to cause them to be defined. osyms contains the old value
4877 of that symlist; everything up to there was defined by us. */
4878 /* Note that we preserve the order of the enum constants, so
4879 that in something like "enum {FOO, LAST_THING=FOO}" we print
4880 FOO, not LAST_THING. */
4882 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
4887 for (; j
< syms
->nsyms
; j
++,n
++)
4889 struct symbol
*sym
= syms
->symbol
[j
];
4890 SYMBOL_TYPE (sym
) = type
;
4891 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (sym
);
4892 TYPE_FIELD_VALUE (type
, n
) = 0;
4893 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (sym
);
4894 TYPE_FIELD_BITSIZE (type
, n
) = 0;
4903 /* Read a number from the string pointed to by *PP.
4904 The value of *PP is advanced over the number.
4905 If END is nonzero, the character that ends the
4906 number must match END, or an error happens;
4907 and that character is skipped if it does match.
4908 If END is zero, *PP is left pointing to that character.
4910 If the number fits in a long, set *VALUE and set *BITS to 0.
4911 If not, set *BITS to be the number of bits in the number.
4913 If encounter garbage, set *BITS to -1. */
4916 read_huge_number (pp
, end
, valu
, bits
)
4936 /* Leading zero means octal. GCC uses this to output values larger
4937 than an int (because that would be hard in decimal). */
4944 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
4946 if (n
<= LONG_MAX
/ radix
)
4949 n
+= c
- '0'; /* FIXME this overflows anyway */
4954 /* This depends on large values being output in octal, which is
4961 /* Ignore leading zeroes. */
4965 else if (c
== '2' || c
== '3')
4991 /* Large decimal constants are an error (because it is hard to
4992 count how many bits are in them). */
4998 /* -0x7f is the same as 0x80. So deal with it by adding one to
4999 the number of bits. */
5014 #define MAX_OF_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
5015 #define MIN_OF_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
5017 static struct type
*
5018 read_range_type (pp
, typenums
)
5026 struct type
*result_type
;
5028 /* First comes a type we are a subrange of.
5029 In C it is usually 0, 1 or the type being defined. */
5030 read_type_number (pp
, rangenums
);
5031 self_subrange
= (rangenums
[0] == typenums
[0] &&
5032 rangenums
[1] == typenums
[1]);
5034 /* A semicolon should now follow; skip it. */
5038 /* The remaining two operands are usually lower and upper bounds
5039 of the range. But in some special cases they mean something else. */
5040 read_huge_number (pp
, ';', &n2
, &n2bits
);
5041 read_huge_number (pp
, ';', &n3
, &n3bits
);
5043 if (n2bits
== -1 || n3bits
== -1)
5044 return error_type (pp
);
5046 /* If limits are huge, must be large integral type. */
5047 if (n2bits
!= 0 || n3bits
!= 0)
5049 char got_signed
= 0;
5050 char got_unsigned
= 0;
5051 /* Number of bits in the type. */
5054 /* Range from 0 to <large number> is an unsigned large integral type. */
5055 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
5060 /* Range from <large number> to <large number>-1 is a large signed
5062 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
5068 if (got_signed
|| got_unsigned
)
5070 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
5071 sizeof (struct type
));
5072 bzero (result_type
, sizeof (struct type
));
5073 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
5074 TYPE_MAIN_VARIANT (result_type
) = result_type
;
5075 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
5077 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
5081 return error_type (pp
);
5084 /* A type defined as a subrange of itself, with bounds both 0, is void. */
5085 if (self_subrange
&& n2
== 0 && n3
== 0)
5086 return builtin_type_void
;
5088 /* If n3 is zero and n2 is not, we want a floating type,
5089 and n2 is the width in bytes.
5091 Fortran programs appear to use this for complex types also,
5092 and they give no way to distinguish between double and single-complex!
5093 We don't have complex types, so we would lose on all fortran files!
5094 So return type `double' for all of those. It won't work right
5095 for the complex values, but at least it makes the file loadable. */
5097 if (n3
== 0 && n2
> 0)
5099 if (n2
== sizeof (float))
5100 return builtin_type_float
;
5101 return builtin_type_double
;
5104 /* If the upper bound is -1, it must really be an unsigned int. */
5106 else if (n2
== 0 && n3
== -1)
5108 if (sizeof (int) == sizeof (long))
5109 return builtin_type_unsigned_int
;
5111 return builtin_type_unsigned_long
;
5114 /* Special case: char is defined (Who knows why) as a subrange of
5115 itself with range 0-127. */
5116 else if (self_subrange
&& n2
== 0 && n3
== 127)
5117 return builtin_type_char
;
5119 /* Assumptions made here: Subrange of self is equivalent to subrange
5122 && (self_subrange
||
5123 *dbx_lookup_type (rangenums
) == builtin_type_int
))
5125 /* an unsigned type */
5127 if (n3
== - sizeof (long long))
5128 return builtin_type_unsigned_long_long
;
5130 if (n3
== (unsigned int)~0L)
5131 return builtin_type_unsigned_int
;
5132 if (n3
== (unsigned long)~0L)
5133 return builtin_type_unsigned_long
;
5134 if (n3
== (unsigned short)~0L)
5135 return builtin_type_unsigned_short
;
5136 if (n3
== (unsigned char)~0L)
5137 return builtin_type_unsigned_char
;
5140 else if (n3
== 0 && n2
== -sizeof (long long))
5141 return builtin_type_long_long
;
5143 else if (n2
== -n3
-1)
5146 if (n3
== (1 << (8 * sizeof (int) - 1)) - 1)
5147 return builtin_type_int
;
5148 if (n3
== (1 << (8 * sizeof (long) - 1)) - 1)
5149 return builtin_type_long
;
5150 if (n3
== (1 << (8 * sizeof (short) - 1)) - 1)
5151 return builtin_type_short
;
5152 if (n3
== (1 << (8 * sizeof (char) - 1)) - 1)
5153 return builtin_type_char
;
5156 /* We have a real range type on our hands. Allocate space and
5157 return a real pointer. */
5159 /* At this point I don't have the faintest idea how to deal with
5160 a self_subrange type; I'm going to assume that this is used
5161 as an idiom, and that all of them are special cases. So . . . */
5163 return error_type (pp
);
5165 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
5166 sizeof (struct type
));
5167 bzero (result_type
, sizeof (struct type
));
5169 TYPE_TARGET_TYPE (result_type
) = (self_subrange
?
5171 *dbx_lookup_type(rangenums
));
5173 /* We have to figure out how many bytes it takes to hold this
5174 range type. I'm going to assume that anything that is pushing
5175 the bounds of a long was taken care of above. */
5176 if (n2
>= MIN_OF_TYPE(char) && n3
<= MAX_OF_TYPE(char))
5177 TYPE_LENGTH (result_type
) = 1;
5178 else if (n2
>= MIN_OF_TYPE(short) && n3
<= MAX_OF_TYPE(short))
5179 TYPE_LENGTH (result_type
) = sizeof (short);
5180 else if (n2
>= MIN_OF_TYPE(int) && n3
<= MAX_OF_TYPE(int))
5181 TYPE_LENGTH (result_type
) = sizeof (int);
5182 else if (n2
>= MIN_OF_TYPE(long) && n3
<= MAX_OF_TYPE(long))
5183 TYPE_LENGTH (result_type
) = sizeof (long);
5185 /* Ranged type doesn't fit within known sizes. */
5186 return error_type (pp
);
5188 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
5189 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
5190 TYPE_NFIELDS (result_type
) = 2;
5191 TYPE_FIELDS (result_type
) =
5192 (struct field
*) obstack_alloc (symbol_obstack
,
5193 2 * sizeof (struct field
));
5194 bzero (TYPE_FIELDS (result_type
), 2 * sizeof (struct field
));
5195 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
5196 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
5201 /* Read a number from the string pointed to by *PP.
5202 The value of *PP is advanced over the number.
5203 If END is nonzero, the character that ends the
5204 number must match END, or an error happens;
5205 and that character is skipped if it does match.
5206 If END is zero, *PP is left pointing to that character. */
5209 read_number (pp
, end
)
5213 register char *p
= *pp
;
5214 register long n
= 0;
5218 /* Handle an optional leading minus sign. */
5226 /* Read the digits, as far as they go. */
5228 while ((c
= *p
++) >= '0' && c
<= '9')
5236 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
5245 /* Read in an argument list. This is a list of types, separated by commas
5246 and terminated with END. Return the list of types read in, or (struct type
5247 **)-1 if there is an error. */
5248 static struct type
**
5253 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
5259 /* Invalid argument list: no ','. */
5260 return (struct type
**)-1;
5263 /* Check for and handle cretinous dbx symbol name continuation! */
5265 *pp
= next_symbol_text ();
5267 types
[n
++] = read_type (pp
);
5269 *pp
+= 1; /* get past `end' (the ':' character) */
5273 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
5275 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
5277 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
5278 bzero (rval
+ n
, sizeof (struct type
*));
5282 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
5284 bcopy (types
, rval
, n
* sizeof (struct type
*));
5288 /* Copy a pending list, used to record the contents of a common
5289 block for later fixup. */
5290 static struct pending
*
5291 copy_pending (beg
, begi
, end
)
5292 struct pending
*beg
, *end
;
5295 struct pending
*new = 0;
5296 struct pending
*next
;
5298 for (next
= beg
; next
!= 0 && (next
!= end
|| begi
< end
->nsyms
);
5299 next
= next
->next
, begi
= 0)
5302 for (j
= begi
; j
< next
->nsyms
; j
++)
5303 add_symbol_to_list (next
->symbol
[j
], &new);
5308 /* Add a common block's start address to the offset of each symbol
5309 declared to be in it (by being between a BCOMM/ECOMM pair that uses
5310 the common block name). */
5313 fix_common_block (sym
, valu
)
5317 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
5318 for ( ; next
; next
= next
->next
)
5321 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
5322 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
5326 /* Register our willingness to decode symbols for SunOS and a.out and
5327 b.out files handled by BFD... */
5328 static struct sym_fns sunos_sym_fns
= {"sunOs", 6,
5329 dbx_new_init
, dbx_symfile_init
,
5330 dbx_symfile_read
, dbx_symfile_discard
};
5332 static struct sym_fns aout_sym_fns
= {"a.out", 5,
5333 dbx_new_init
, dbx_symfile_init
,
5334 dbx_symfile_read
, dbx_symfile_discard
};
5336 static struct sym_fns bout_sym_fns
= {"b.out", 5,
5337 dbx_new_init
, dbx_symfile_init
,
5338 dbx_symfile_read
, dbx_symfile_discard
};
5341 _initialize_dbxread ()
5343 add_symtab_fns(&sunos_sym_fns
);
5344 add_symtab_fns(&aout_sym_fns
);
5345 add_symtab_fns(&bout_sym_fns
);
5347 undef_types_allocated
= 20;
5348 undef_types_length
= 0;
5349 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
5350 sizeof (struct type
*));