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 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* This module provides three functions: dbx_symfile_init,
21 which initializes to read a symbol file; dbx_new_init, which
22 discards existing cached information when all symbols are being
23 discarded; and dbx_symfile_read, which reads a symbol table
26 dbx_symfile_read only does the minimum work necessary for letting the
27 user "name" things symbolically; it does not read the entire symtab.
28 Instead, it reads the external and static symbols and puts them in partial
29 symbol tables. When more extensive information is requested of a
30 file, the corresponding partial symbol table is mutated into a full
31 fledged symbol table by going back and reading the symbols
32 for real. dbx_psymtab_to_symtab() is the function that does this */
40 #include <sys/types.h>
47 #include <sys/param.h>
52 #include "breakpoint.h"
55 #include "gdbcore.h" /* for bfd stuff */
56 #include "libaout.h" /* FIXME Secret internal BFD stuff for a.out */
60 #include "stab.gnu.h" /* We always use GNU stabs, not native, now */
64 * Define specifically gnu symbols here.
67 /* The following type indicates the definition of a symbol as being
68 an indirect reference to another symbol. The other symbol
69 appears as an undefined reference, immediately following this symbol.
71 Indirection is asymmetrical. The other symbol's value will be used
72 to satisfy requests for the indirect symbol, but not vice versa.
73 If the other symbol does not have a definition, libraries will
74 be searched to find a definition. */
79 /* The following symbols refer to set elements.
80 All the N_SET[ATDB] symbols with the same name form one set.
81 Space is allocated for the set in the text section, and each set
82 element's value is stored into one word of the space.
83 The first word of the space is the length of the set (number of elements).
85 The address of the set is made into an N_SETV symbol
86 whose name is the same as the name of the set.
87 This symbol acts like a N_DATA global symbol
88 in that it can satisfy undefined external references. */
91 #define N_SETA 0x14 /* Absolute set element symbol */
92 #endif /* This is input to LD, in a .o file. */
95 #define N_SETT 0x16 /* Text set element symbol */
96 #endif /* This is input to LD, in a .o file. */
99 #define N_SETD 0x18 /* Data set element symbol */
100 #endif /* This is input to LD, in a .o file. */
103 #define N_SETB 0x1A /* Bss set element symbol */
104 #endif /* This is input to LD, in a .o file. */
106 /* Macros dealing with the set element symbols defined in a.out.h */
107 #define SET_ELEMENT_P(x) ((x)>=N_SETA&&(x)<=(N_SETB|N_EXT))
108 #define TYPE_OF_SET_ELEMENT(x) ((x)-N_SETA+N_ABS)
111 #define N_SETV 0x1C /* Pointer to set vector in data area. */
112 #endif /* This is output from LD. */
115 #define N_WARNING 0x1E /* Warning message to print if file included */
116 #endif /* This is input to ld */
118 #endif /* NO_GNU_STABS */
120 struct dbx_symfile_info
{
121 asection
*text_sect
; /* Text section accessor */
122 int symcount
; /* How many symbols are there in the file */
123 char *stringtab
; /* The actual string table */
124 int stringtab_size
; /* Its size */
125 off_t symtab_offset
; /* Offset in file to symbol table */
126 int desc
; /* File descriptor of symbol file */
129 extern void qsort ();
130 extern double atof ();
131 extern struct cmd_list_element
*cmdlist
;
133 extern void symbol_file_command ();
135 /* Forward declarations */
137 static void add_symbol_to_list ();
138 static void read_dbx_symtab ();
139 static void init_psymbol_list ();
140 static void process_one_symbol ();
141 static struct type
*read_type ();
142 static struct type
*read_range_type ();
143 static struct type
*read_enum_type ();
144 static struct type
*read_struct_type ();
145 static struct type
*read_array_type ();
146 static long read_number ();
147 static void finish_block ();
148 static struct blockvector
*make_blockvector ();
149 static struct symbol
*define_symbol ();
150 static void start_subfile ();
151 static int hashname ();
152 static struct pending
*copy_pending ();
153 static void fix_common_block ();
154 static void add_undefined_type ();
155 static void cleanup_undefined_types ();
156 static void scan_file_globals ();
157 static struct symtab
*read_ofile_symtab ();
158 static void dbx_psymtab_to_symtab ();
161 static struct type
**read_args ();
163 static const char vptr_name
[] = { '_','v','p','t','r',CPLUS_MARKER
,'\0' };
164 static const char vb_name
[] = { '_','v','b',CPLUS_MARKER
,'\0' };
166 /* Macro to determine which symbols to ignore when reading the first symbol
167 of a file. Some machines override this definition. */
168 #ifndef IGNORE_SYMBOL
169 /* This code is used on Ultrix systems. Ignore it */
170 #define IGNORE_SYMBOL(type) (type == (int)N_NSYMS)
173 /* Macro for name of symbol to indicate a file compiled with gcc. */
174 #ifndef GCC_COMPILED_FLAG_SYMBOL
175 #define GCC_COMPILED_FLAG_SYMBOL "gcc_compiled."
178 /* Convert stab register number (from `r' declaration) to a gdb REGNUM. */
180 #ifndef STAB_REG_TO_REGNUM
181 #define STAB_REG_TO_REGNUM(VALUE) (VALUE)
184 /* Define this as 1 if a pcc declaration of a char or short argument
185 gives the correct address. Otherwise assume pcc gives the
186 address of the corresponding int, which is not the same on a
187 big-endian machine. */
189 #ifndef BELIEVE_PCC_PROMOTION
190 #define BELIEVE_PCC_PROMOTION 0
193 /* Nonzero means give verbose info on gdb action. From main.c. */
194 extern int info_verbose
;
196 /* Name of source file whose symbol data we are now processing.
197 This comes from a symbol of type N_SO. */
199 static char *last_source_file
;
201 /* Core address of start of text of current source file.
202 This too comes from the N_SO symbol. */
204 static CORE_ADDR last_source_start_addr
;
206 /* The entry point of a file we are reading. */
207 CORE_ADDR entry_point
;
209 /* The list of sub-source-files within the current individual compilation.
210 Each file gets its own symtab with its own linetable and associated info,
211 but they all share one blockvector. */
215 struct subfile
*next
;
218 struct linetable
*line_vector
;
219 int line_vector_length
;
220 int line_vector_index
;
221 int prev_line_number
;
224 static struct subfile
*subfiles
;
226 static struct subfile
*current_subfile
;
228 /* Count symbols as they are processed, for error messages. */
230 static unsigned int symnum
;
232 /* Vector of types defined so far, indexed by their dbx type numbers.
233 (In newer sun systems, dbx uses a pair of numbers in parens,
234 as in "(SUBFILENUM,NUMWITHINSUBFILE)". Then these numbers must be
235 translated through the type_translations hash table to get
236 the index into the type vector.) */
238 static struct type
**type_vector
;
240 /* Number of elements allocated for type_vector currently. */
242 static int type_vector_length
;
244 /* Vector of line number information. */
246 static struct linetable
*line_vector
;
248 /* Index of next entry to go in line_vector_index. */
250 static int line_vector_index
;
252 /* Last line number recorded in the line vector. */
254 static int prev_line_number
;
256 /* Number of elements allocated for line_vector currently. */
258 static int line_vector_length
;
260 /* Hash table of global symbols whose values are not known yet.
261 They are chained thru the SYMBOL_VALUE_CHAIN, since we don't
262 have the correct data for that slot yet. */
263 /* The use of the LOC_BLOCK code in this chain is nonstandard--
264 it refers to a FORTRAN common block rather than the usual meaning. */
267 static struct symbol
*global_sym_chain
[HASHSIZE
];
269 /* Record the symbols defined for each context in a list.
270 We don't create a struct block for the context until we
271 know how long to make it. */
273 #define PENDINGSIZE 100
277 struct pending
*next
;
279 struct symbol
*symbol
[PENDINGSIZE
];
282 /* List of free `struct pending' structures for reuse. */
283 struct pending
*free_pendings
;
285 /* Here are the three lists that symbols are put on. */
287 struct pending
*file_symbols
; /* static at top level, and types */
289 struct pending
*global_symbols
; /* global functions and variables */
291 struct pending
*local_symbols
; /* everything local to lexical context */
293 /* List of symbols declared since the last BCOMM. This list is a tail
294 of local_symbols. When ECOMM is seen, the symbols on the list
295 are noted so their proper addresses can be filled in later,
296 using the common block base address gotten from the assembler
299 struct pending
*common_block
;
302 /* Stack representing unclosed lexical contexts
303 (that will become blocks, eventually). */
307 struct pending
*locals
;
308 struct pending_block
*old_blocks
;
310 CORE_ADDR start_addr
;
311 CORE_ADDR end_addr
; /* Temp slot for exception handling. */
315 struct context_stack
*context_stack
;
317 /* Index of first unused entry in context stack. */
318 int context_stack_depth
;
320 /* Currently allocated size of context stack. */
322 int context_stack_size
;
324 /* Nonzero if within a function (so symbols should be local,
325 if nothing says specifically). */
330 /* The type of the function we are currently reading in. This is
331 used by define_symbol to record the type of arguments to a function. */
333 static struct type
*in_function_type
;
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 /* The size of each symbol in the symbol file (in external form).
367 This is set by dbx_symfile_read when building psymtabs, and by
368 dbx_psymtab_to_symtab when building symtabs. */
370 static unsigned symbol_size
;
372 /* Setup a define to deal cleanly with the underscore problem */
374 #ifdef NAMES_HAVE_UNDERSCORE
375 #define HASH_OFFSET 1
377 #define HASH_OFFSET 0
380 /* Complaints about the symbols we have encountered. */
382 struct complaint innerblock_complaint
=
383 {"inner block not inside outer block in %s", 0, 0};
385 struct complaint blockvector_complaint
=
386 {"block at %x out of order", 0, 0};
388 struct complaint lbrac_complaint
=
389 {"bad block start address patched", 0, 0};
392 struct complaint dbx_class_complaint
=
393 {"encountered DBX-style class variable debugging information.\n\
394 You seem to have compiled your program with \
395 \"g++ -g0\" instead of \"g++ -g\".\n\
396 Therefore GDB will not know about your class variables", 0, 0};
399 struct complaint string_table_offset_complaint
=
400 {"bad string table offset in symbol %d", 0, 0};
402 struct complaint unknown_symtype_complaint
=
403 {"unknown symbol type %s", 0, 0};
405 struct complaint lbrac_rbrac_complaint
=
406 {"block start larger than block end", 0, 0};
408 struct complaint const_vol_complaint
=
409 {"const/volatile indicator missing (ok if using g++ v1.x), got '%c'", 0, 0};
411 struct complaint error_type_complaint
=
412 {"debug info mismatch between compiler and debugger", 0, 0};
414 struct complaint invalid_member_complaint
=
415 {"invalid (minimal) member type data format at symtab pos %d.", 0, 0};
417 struct complaint range_type_base_complaint
=
418 {"base type %d of range type is not defined", 0, 0};
420 /* Support for Sun changes to dbx symbol format */
422 /* For each identified header file, we have a table of types defined
425 header_files maps header file names to their type tables.
426 It is a vector of n_header_files elements.
427 Each element describes one header file.
428 It contains a vector of types.
430 Sometimes it can happen that the same header file produces
431 different results when included in different places.
432 This can result from conditionals or from different
433 things done before including the file.
434 When this happens, there are multiple entries for the file in this table,
435 one entry for each distinct set of results.
436 The entries are distinguished by the INSTANCE field.
437 The INSTANCE field appears in the N_BINCL and N_EXCL symbol table and is
438 used to match header-file references to their corresponding data. */
442 char *name
; /* Name of header file */
443 int instance
; /* Numeric code distinguishing instances
444 of one header file that produced
445 different results when included.
446 It comes from the N_BINCL or N_EXCL. */
447 struct type
**vector
; /* Pointer to vector of types */
448 int length
; /* Allocated length (# elts) of that vector */
451 static struct header_file
*header_files
= 0;
453 static int n_header_files
;
455 static int n_allocated_header_files
;
457 /* During initial symbol readin, we need to have a structure to keep
458 track of which psymtabs have which bincls in them. This structure
459 is used during readin to setup the list of dependencies within each
460 partial symbol table. */
462 struct header_file_location
464 char *name
; /* Name of header file */
465 int instance
; /* See above */
466 struct partial_symtab
*pst
; /* Partial symtab that has the
467 BINCL/EINCL defs for this file */
470 /* The actual list and controling variables */
471 static struct header_file_location
*bincl_list
, *next_bincl
;
472 static int bincls_allocated
;
474 /* Within each object file, various header files are assigned numbers.
475 A type is defined or referred to with a pair of numbers
476 (FILENUM,TYPENUM) where FILENUM is the number of the header file
477 and TYPENUM is the number within that header file.
478 TYPENUM is the index within the vector of types for that header file.
480 FILENUM == 1 is special; it refers to the main source of the object file,
481 and not to any header file. FILENUM != 1 is interpreted by looking it up
482 in the following table, which contains indices in header_files. */
484 static int *this_object_header_files
= 0;
486 static int n_this_object_header_files
;
488 static int n_allocated_this_object_header_files
;
490 /* When a header file is getting special overriding definitions
491 for one source file, record here the header_files index
492 of its normal definition vector.
493 At other times, this is -1. */
495 static int header_file_prev_index
;
497 /* Free up old header file tables, and allocate new ones.
498 We're reading a new symbol file now. */
501 free_and_init_header_files ()
504 for (i
= 0; i
< n_header_files
; i
++)
505 free (header_files
[i
].name
);
506 if (header_files
) /* First time null */
508 if (this_object_header_files
) /* First time null */
509 free (this_object_header_files
);
511 n_allocated_header_files
= 10;
512 header_files
= (struct header_file
*) xmalloc (10 * sizeof (struct header_file
));
515 n_allocated_this_object_header_files
= 10;
516 this_object_header_files
= (int *) xmalloc (10 * sizeof (int));
519 /* Called at the start of each object file's symbols.
520 Clear out the mapping of header file numbers to header files. */
523 new_object_header_files ()
525 /* Leave FILENUM of 0 free for builtin types and this file's types. */
526 n_this_object_header_files
= 1;
527 header_file_prev_index
= -1;
530 /* Add header file number I for this object file
531 at the next successive FILENUM. */
534 add_this_object_header_file (i
)
537 if (n_this_object_header_files
== n_allocated_this_object_header_files
)
539 n_allocated_this_object_header_files
*= 2;
540 this_object_header_files
541 = (int *) xrealloc (this_object_header_files
,
542 n_allocated_this_object_header_files
* sizeof (int));
545 this_object_header_files
[n_this_object_header_files
++] = i
;
548 /* Add to this file an "old" header file, one already seen in
549 a previous object file. NAME is the header file's name.
550 INSTANCE is its instance code, to select among multiple
551 symbol tables for the same header file. */
554 add_old_header_file (name
, instance
)
558 register struct header_file
*p
= header_files
;
561 for (i
= 0; i
< n_header_files
; i
++)
562 if (!strcmp (p
[i
].name
, name
) && instance
== p
[i
].instance
)
564 add_this_object_header_file (i
);
567 error ("Invalid symbol data: \"repeated\" header file that hasn't been seen before, at symtab pos %d.",
571 /* Add to this file a "new" header file: definitions for its types follow.
572 NAME is the header file's name.
573 Most often this happens only once for each distinct header file,
574 but not necessarily. If it happens more than once, INSTANCE has
575 a different value each time, and references to the header file
576 use INSTANCE values to select among them.
578 dbx output contains "begin" and "end" markers for each new header file,
579 but at this level we just need to know which files there have been;
580 so we record the file when its "begin" is seen and ignore the "end". */
583 add_new_header_file (name
, instance
)
588 header_file_prev_index
= -1;
590 /* Make sure there is room for one more header file. */
592 if (n_header_files
== n_allocated_header_files
)
594 n_allocated_header_files
*= 2;
595 header_files
= (struct header_file
*)
596 xrealloc (header_files
,
597 (n_allocated_header_files
598 * sizeof (struct header_file
)));
601 /* Create an entry for this header file. */
603 i
= n_header_files
++;
604 header_files
[i
].name
= savestring (name
, strlen(name
));
605 header_files
[i
].instance
= instance
;
606 header_files
[i
].length
= 10;
607 header_files
[i
].vector
608 = (struct type
**) xmalloc (10 * sizeof (struct type
*));
609 bzero (header_files
[i
].vector
, 10 * sizeof (struct type
*));
611 add_this_object_header_file (i
);
614 /* Look up a dbx type-number pair. Return the address of the slot
615 where the type for that number-pair is stored.
616 The number-pair is in TYPENUMS.
618 This can be used for finding the type associated with that pair
619 or for associating a new type with the pair. */
621 static struct type
**
622 dbx_lookup_type (typenums
)
625 register int filenum
= typenums
[0], index
= typenums
[1];
627 if (filenum
< 0 || filenum
>= n_this_object_header_files
)
628 error ("Invalid symbol data: type number (%d,%d) out of range at symtab pos %d.",
629 filenum
, index
, symnum
);
633 /* Type is defined outside of header files.
634 Find it in this object file's type vector. */
635 while (index
>= type_vector_length
)
637 type_vector_length
*= 2;
638 type_vector
= (struct type
**)
639 xrealloc (type_vector
,
640 (type_vector_length
* sizeof (struct type
*)));
641 bzero (&type_vector
[type_vector_length
/ 2],
642 type_vector_length
* sizeof (struct type
*) / 2);
644 return &type_vector
[index
];
648 register int real_filenum
= this_object_header_files
[filenum
];
649 register struct header_file
*f
;
652 if (real_filenum
>= n_header_files
)
655 f
= &header_files
[real_filenum
];
657 f_orig_length
= f
->length
;
658 if (index
>= f_orig_length
)
660 while (index
>= f
->length
)
662 f
->vector
= (struct type
**)
663 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
664 bzero (&f
->vector
[f_orig_length
],
665 (f
->length
- f_orig_length
) * sizeof (struct type
*));
667 return &f
->vector
[index
];
671 /* Create a type object. Occaisionally used when you need a type
672 which isn't going to be given a type number. */
677 register struct type
*type
=
678 (struct type
*) obstack_alloc (symbol_obstack
, sizeof (struct type
));
680 bzero (type
, sizeof (struct type
));
681 TYPE_VPTR_FIELDNO (type
) = -1;
682 TYPE_VPTR_BASETYPE (type
) = 0;
686 /* Make sure there is a type allocated for type numbers TYPENUMS
687 and return the type object.
688 This can create an empty (zeroed) type object.
689 TYPENUMS may be (-1, -1) to return a new type object that is not
690 put into the type vector, and so may not be referred to by number. */
693 dbx_alloc_type (typenums
)
696 register struct type
**type_addr
;
697 register struct type
*type
;
699 if (typenums
[1] != -1)
701 type_addr
= dbx_lookup_type (typenums
);
710 /* If we are referring to a type not known at all yet,
711 allocate an empty type for it.
712 We will fill it in later if we find out how. */
715 type
= dbx_create_type ();
724 static struct type
**
725 explicit_lookup_type (real_filenum
, index
)
726 int real_filenum
, index
;
728 register struct header_file
*f
= &header_files
[real_filenum
];
730 if (index
>= f
->length
)
733 f
->vector
= (struct type
**)
734 xrealloc (f
->vector
, f
->length
* sizeof (struct type
*));
735 bzero (&f
->vector
[f
->length
/ 2],
736 f
->length
* sizeof (struct type
*) / 2);
738 return &f
->vector
[index
];
742 /* maintain the lists of symbols and blocks */
744 /* Add a symbol to one of the lists of symbols. */
746 add_symbol_to_list (symbol
, listhead
)
747 struct symbol
*symbol
;
748 struct pending
**listhead
;
750 /* We keep PENDINGSIZE symbols in each link of the list.
751 If we don't have a link with room in it, add a new link. */
752 if (*listhead
== 0 || (*listhead
)->nsyms
== PENDINGSIZE
)
754 register struct pending
*link
;
757 link
= free_pendings
;
758 free_pendings
= link
->next
;
761 link
= (struct pending
*) xmalloc (sizeof (struct pending
));
763 link
->next
= *listhead
;
768 (*listhead
)->symbol
[(*listhead
)->nsyms
++] = symbol
;
771 /* At end of reading syms, or in case of quit,
772 really free as many `struct pending's as we can easily find. */
776 really_free_pendings (foo
)
779 struct pending
*next
, *next1
;
781 struct pending_block
*bnext
, *bnext1
;
784 for (next
= free_pendings
; next
; next
= next1
)
791 #if 0 /* Now we make the links in the symbol_obstack, so don't free them. */
792 for (bnext
= pending_blocks
; bnext
; bnext
= bnext1
)
794 bnext1
= bnext
->next
;
800 for (next
= file_symbols
; next
; next
= next1
)
807 for (next
= global_symbols
; next
; next
= next1
)
815 /* Take one of the lists of symbols and make a block from it.
816 Keep the order the symbols have in the list (reversed from the input file).
817 Put the block on the list of pending blocks. */
820 finish_block (symbol
, listhead
, old_blocks
, start
, end
)
821 struct symbol
*symbol
;
822 struct pending
**listhead
;
823 struct pending_block
*old_blocks
;
824 CORE_ADDR start
, end
;
826 register struct pending
*next
, *next1
;
827 register struct block
*block
;
828 register struct pending_block
*pblock
;
829 struct pending_block
*opblock
;
832 /* Count the length of the list of symbols. */
834 for (next
= *listhead
, i
= 0; next
; i
+= next
->nsyms
, next
= next
->next
)
837 block
= (struct block
*) obstack_alloc (symbol_obstack
,
838 (sizeof (struct block
)
840 * sizeof (struct symbol
*))));
842 /* Copy the symbols into the block. */
844 BLOCK_NSYMS (block
) = i
;
845 for (next
= *listhead
; next
; next
= next
->next
)
848 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
849 BLOCK_SYM (block
, --i
) = next
->symbol
[j
];
852 BLOCK_START (block
) = start
;
853 BLOCK_END (block
) = end
;
854 BLOCK_SUPERBLOCK (block
) = 0; /* Filled in when containing block is made */
855 BLOCK_GCC_COMPILED (block
) = processing_gcc_compilation
;
857 /* Put the block in as the value of the symbol that names it. */
861 SYMBOL_BLOCK_VALUE (symbol
) = block
;
862 BLOCK_FUNCTION (block
) = symbol
;
865 BLOCK_FUNCTION (block
) = 0;
867 /* Now "free" the links of the list, and empty the list. */
869 for (next
= *listhead
; next
; next
= next1
)
872 next
->next
= free_pendings
;
873 free_pendings
= next
;
877 /* Install this block as the superblock
878 of all blocks made since the start of this scope
879 that don't have superblocks yet. */
882 for (pblock
= pending_blocks
; pblock
!= old_blocks
; pblock
= pblock
->next
)
884 if (BLOCK_SUPERBLOCK (pblock
->block
) == 0) {
886 /* Check to be sure the blocks are nested as we receive them.
887 If the compiler/assembler/linker work, this just burns a small
889 if (BLOCK_START (pblock
->block
) < BLOCK_START (block
)
890 || BLOCK_END (pblock
->block
) > BLOCK_END (block
)) {
891 complain(&innerblock_complaint
, symbol
? SYMBOL_NAME (symbol
):
893 BLOCK_START (pblock
->block
) = BLOCK_START (block
);
894 BLOCK_END (pblock
->block
) = BLOCK_END (block
);
897 BLOCK_SUPERBLOCK (pblock
->block
) = block
;
902 /* Record this block on the list of all blocks in the file.
903 Put it after opblock, or at the beginning if opblock is 0.
904 This puts the block in the list after all its subblocks. */
906 /* Allocate in the symbol_obstack to save time.
907 It wastes a little space. */
908 pblock
= (struct pending_block
*)
909 obstack_alloc (symbol_obstack
,
910 sizeof (struct pending_block
));
911 pblock
->block
= block
;
914 pblock
->next
= opblock
->next
;
915 opblock
->next
= pblock
;
919 pblock
->next
= pending_blocks
;
920 pending_blocks
= pblock
;
924 static struct blockvector
*
927 register struct pending_block
*next
;
928 register struct blockvector
*blockvector
;
931 /* Count the length of the list of blocks. */
933 for (next
= pending_blocks
, i
= 0; next
; next
= next
->next
, i
++);
935 blockvector
= (struct blockvector
*)
936 obstack_alloc (symbol_obstack
,
937 (sizeof (struct blockvector
)
938 + (i
- 1) * sizeof (struct block
*)));
940 /* Copy the blocks into the blockvector.
941 This is done in reverse order, which happens to put
942 the blocks into the proper order (ascending starting address).
943 finish_block has hair to insert each block into the list
944 after its subblocks in order to make sure this is true. */
946 BLOCKVECTOR_NBLOCKS (blockvector
) = i
;
947 for (next
= pending_blocks
; next
; next
= next
->next
) {
948 BLOCKVECTOR_BLOCK (blockvector
, --i
) = next
->block
;
951 #if 0 /* Now we make the links in the obstack, so don't free them. */
952 /* Now free the links of the list, and empty the list. */
954 for (next
= pending_blocks
; next
; next
= next1
)
962 #if 1 /* FIXME, shut this off after a while to speed up symbol reading. */
963 /* Some compilers output blocks in the wrong order, but we depend
964 on their being in the right order so we can binary search.
965 Check the order and moan about it. FIXME. */
966 if (BLOCKVECTOR_NBLOCKS (blockvector
) > 1)
967 for (i
= 1; i
< BLOCKVECTOR_NBLOCKS (blockvector
); i
++) {
968 if (BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
-1))
969 > BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
))) {
970 complain (&blockvector_complaint
,
971 BLOCK_START(BLOCKVECTOR_BLOCK (blockvector
, i
)));
979 /* Manage the vector of line numbers. */
982 record_line (line
, pc
)
986 struct linetable_entry
*e
;
987 /* Ignore the dummy line number in libg.o */
992 /* Make sure line vector is big enough. */
994 if (line_vector_index
+ 1 >= line_vector_length
)
996 line_vector_length
*= 2;
997 line_vector
= (struct linetable
*)
998 xrealloc (line_vector
,
999 (sizeof (struct linetable
)
1000 + line_vector_length
* sizeof (struct linetable_entry
)));
1001 current_subfile
->line_vector
= line_vector
;
1004 e
= line_vector
->item
+ line_vector_index
++;
1005 e
->line
= line
; e
->pc
= pc
;
1008 /* Start a new symtab for a new source file.
1009 This is called when a dbx symbol of type N_SO is seen;
1010 it indicates the start of data for one original source file. */
1013 start_symtab (name
, dirname
, start_addr
)
1016 CORE_ADDR start_addr
;
1019 last_source_file
= name
;
1020 last_source_start_addr
= start_addr
;
1023 within_function
= 0;
1025 /* Context stack is initially empty, with room for 10 levels. */
1027 = (struct context_stack
*) xmalloc (10 * sizeof (struct context_stack
));
1028 context_stack_size
= 10;
1029 context_stack_depth
= 0;
1031 new_object_header_files ();
1033 type_vector_length
= 160;
1034 type_vector
= (struct type
**)
1035 xmalloc (type_vector_length
* sizeof (struct type
*));
1036 bzero (type_vector
, type_vector_length
* sizeof (struct type
*));
1038 /* Initialize the list of sub source files with one entry
1039 for this file (the top-level source file). */
1042 current_subfile
= 0;
1043 start_subfile (name
, dirname
);
1046 /* Handle an N_SOL symbol, which indicates the start of
1047 code that came from an included (or otherwise merged-in)
1048 source file with a different name. */
1051 start_subfile (name
, dirname
)
1055 register struct subfile
*subfile
;
1057 /* Save the current subfile's line vector data. */
1059 if (current_subfile
)
1061 current_subfile
->line_vector_index
= line_vector_index
;
1062 current_subfile
->line_vector_length
= line_vector_length
;
1063 current_subfile
->prev_line_number
= prev_line_number
;
1066 /* See if this subfile is already known as a subfile of the
1067 current main source file. */
1069 for (subfile
= subfiles
; subfile
; subfile
= subfile
->next
)
1071 if (!strcmp (subfile
->name
, name
))
1073 line_vector
= subfile
->line_vector
;
1074 line_vector_index
= subfile
->line_vector_index
;
1075 line_vector_length
= subfile
->line_vector_length
;
1076 prev_line_number
= subfile
->prev_line_number
;
1077 current_subfile
= subfile
;
1082 /* This subfile is not known. Add an entry for it. */
1084 line_vector_index
= 0;
1085 line_vector_length
= 1000;
1086 prev_line_number
= -2; /* Force first line number to be explicit */
1087 line_vector
= (struct linetable
*)
1088 xmalloc (sizeof (struct linetable
)
1089 + line_vector_length
* sizeof (struct linetable_entry
));
1091 /* Make an entry for this subfile in the list of all subfiles
1092 of the current main source file. */
1094 subfile
= (struct subfile
*) xmalloc (sizeof (struct subfile
));
1095 subfile
->next
= subfiles
;
1096 subfile
->name
= obsavestring (name
, strlen (name
));
1097 if (dirname
== NULL
)
1098 subfile
->dirname
= NULL
;
1100 subfile
->dirname
= obsavestring (dirname
, strlen (dirname
));
1102 subfile
->line_vector
= line_vector
;
1104 current_subfile
= subfile
;
1107 /* Finish the symbol definitions for one main source file,
1108 close off all the lexical contexts for that file
1109 (creating struct block's for them), then make the struct symtab
1110 for that file and put it in the list of all such.
1112 END_ADDR is the address of the end of the file's text. */
1114 static struct symtab
*
1115 end_symtab (end_addr
)
1118 register struct symtab
*symtab
;
1119 register struct blockvector
*blockvector
;
1120 register struct subfile
*subfile
;
1121 register struct linetable
*lv
;
1122 struct subfile
*nextsub
;
1124 /* Finish the lexical context of the last function in the file;
1125 pop the context stack. */
1127 if (context_stack_depth
> 0)
1129 register struct context_stack
*cstk
;
1130 context_stack_depth
--;
1131 cstk
= &context_stack
[context_stack_depth
];
1132 /* Make a block for the local symbols within. */
1133 finish_block (cstk
->name
, &local_symbols
, cstk
->old_blocks
,
1134 cstk
->start_addr
, end_addr
);
1137 /* Cleanup any undefined types that have been left hanging around
1138 (this needs to be done before the finish_blocks so that
1139 file_symbols is still good). */
1140 cleanup_undefined_types ();
1142 /* Define the STATIC_BLOCK and GLOBAL_BLOCK, and build the blockvector. */
1143 finish_block (0, &file_symbols
, 0, last_source_start_addr
, end_addr
);
1144 finish_block (0, &global_symbols
, 0, last_source_start_addr
, end_addr
);
1145 blockvector
= make_blockvector ();
1147 current_subfile
->line_vector_index
= line_vector_index
;
1149 /* Now create the symtab objects proper, one for each subfile. */
1150 /* (The main file is the last one on the chain.) */
1152 for (subfile
= subfiles
; subfile
; subfile
= nextsub
)
1154 symtab
= allocate_symtab (subfile
->name
);
1156 /* Fill in its components. */
1157 symtab
->blockvector
= blockvector
;
1158 lv
= subfile
->line_vector
;
1159 lv
->nitems
= subfile
->line_vector_index
;
1160 symtab
->linetable
= (struct linetable
*)
1161 xrealloc (lv
, (sizeof (struct linetable
)
1162 + lv
->nitems
* sizeof (struct linetable_entry
)));
1164 symtab
->dirname
= subfile
->dirname
;
1166 symtab
->free_code
= free_linetable
;
1167 symtab
->free_ptr
= 0;
1169 /* There should never already be a symtab for this name, since
1170 any prev dups have been removed when the psymtab was read in.
1171 FIXME, there ought to be a way to check this here. */
1172 /* FIXME blewit |= free_named_symtabs (symtab->filename); */
1174 /* Link the new symtab into the list of such. */
1175 symtab
->next
= symtab_list
;
1176 symtab_list
= symtab
;
1178 nextsub
= subfile
->next
;
1182 free ((char *) type_vector
);
1184 type_vector_length
= -1;
1186 line_vector_length
= -1;
1187 last_source_file
= 0;
1192 /* Handle the N_BINCL and N_EINCL symbol types
1193 that act like N_SOL for switching source files
1194 (different subfiles, as we call them) within one object file,
1195 but using a stack rather than in an arbitrary order. */
1197 struct subfile_stack
1199 struct subfile_stack
*next
;
1204 struct subfile_stack
*subfile_stack
;
1209 register struct subfile_stack
*tem
1210 = (struct subfile_stack
*) xmalloc (sizeof (struct subfile_stack
));
1212 tem
->next
= subfile_stack
;
1213 subfile_stack
= tem
;
1214 if (current_subfile
== 0 || current_subfile
->name
== 0)
1216 tem
->name
= current_subfile
->name
;
1217 tem
->prev_index
= header_file_prev_index
;
1223 register char *name
;
1224 register struct subfile_stack
*link
= subfile_stack
;
1230 subfile_stack
= link
->next
;
1231 header_file_prev_index
= link
->prev_index
;
1238 record_misc_function (name
, address
, type
)
1243 enum misc_function_type misc_type
;
1245 switch (type
&~ N_EXT
) {
1246 case N_TEXT
: misc_type
= mf_text
; break;
1247 case N_DATA
: misc_type
= mf_data
; break;
1248 case N_BSS
: misc_type
= mf_bss
; break;
1249 case N_ABS
: misc_type
= mf_abs
; break;
1251 case N_SETV
: misc_type
= mf_data
; break;
1253 default: misc_type
= mf_unknown
; break;
1256 prim_record_misc_function (obsavestring (name
, strlen (name
)),
1257 address
, misc_type
);
1260 /* The BFD for this file -- only good while we're actively reading
1261 symbols into a psymtab or a symtab. */
1263 static bfd
*symfile_bfd
;
1265 /* Scan and build partial symbols for a symbol file.
1266 We have been initialized by a call to dbx_symfile_init, which
1267 put all the relevant info into a "struct dbx_symfile_info"
1268 hung off the struct sym_fns SF.
1270 ADDR is the address relative to which the symbols in it are (e.g.
1271 the base address of the text segment).
1272 MAINLINE is true if we are reading the main symbol
1273 table (as opposed to a shared lib or dynamically loaded file). */
1276 dbx_symfile_read (sf
, addr
, mainline
)
1279 int mainline
; /* FIXME comments above */
1281 struct dbx_symfile_info
*info
= (struct dbx_symfile_info
*) (sf
->sym_private
);
1282 bfd
*sym_bfd
= sf
->sym_bfd
;
1284 char *filename
= bfd_get_filename (sym_bfd
);
1286 val
= lseek (info
->desc
, info
->symtab_offset
, L_SET
);
1288 perror_with_name (filename
);
1290 /* If mainline, set global string table pointers, and reinitialize global
1291 partial symbol list. */
1293 symfile_string_table
= info
->stringtab
;
1294 symfile_string_table_size
= info
->stringtab_size
;
1297 /* If we are reinitializing, or if we have never loaded syms yet, init */
1298 if (mainline
|| global_psymbols
.size
== 0 || static_psymbols
.size
== 0)
1299 init_psymbol_list (info
->symcount
);
1301 symfile_bfd
= sym_bfd
; /* Kludge for SWAP_SYMBOL */
1303 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1304 symbol_size
= obj_symbol_entry_size (sym_bfd
);
1307 make_cleanup (really_free_pendings
, 0);
1309 init_misc_bunches ();
1310 make_cleanup (discard_misc_bunches
, 0);
1312 /* Now that the symbol table data of the executable file are all in core,
1313 process them and define symbols accordingly. */
1315 read_dbx_symtab (filename
,
1316 addr
- bfd_section_vma (sym_bfd
, info
->text_sect
), /*offset*/
1317 info
->desc
, info
->stringtab
, info
->stringtab_size
,
1319 bfd_section_vma (sym_bfd
, info
->text_sect
),
1320 bfd_section_size (sym_bfd
, info
->text_sect
));
1322 /* Go over the misc symbol bunches and install them in vector. */
1324 condense_misc_bunches (!mainline
);
1326 /* Free up any memory we allocated for ourselves. */
1329 free (info
->stringtab
); /* Stringtab is only saved for mainline */
1332 sf
->sym_private
= 0; /* Zap pointer to our (now gone) info struct */
1334 if (!partial_symtab_list
) {
1336 printf_filtered ("(no debugging symbols found)...");
1341 /* Initialize anything that needs initializing when a completely new
1342 symbol file is specified (not just adding some symbols from another
1343 file, e.g. a shared library). */
1348 /* Empty the hash table of global syms looking for values. */
1349 bzero (global_sym_chain
, sizeof global_sym_chain
);
1355 /* Don't put these on the cleanup chain; they need to stick around
1356 until the next call to dbx_new_init. *Then* we'll free them. */
1357 if (symfile_string_table
)
1359 free (symfile_string_table
);
1360 symfile_string_table
= 0;
1361 symfile_string_table_size
= 0;
1363 free_and_init_header_files ();
1367 /* dbx_symfile_init ()
1368 is the dbx-specific initialization routine for reading symbols.
1369 It is passed a struct sym_fns which contains, among other things,
1370 the BFD for the file whose symbols are being read, and a slot for a pointer
1371 to "private data" which we fill with goodies.
1373 We read the string table into malloc'd space and stash a pointer to it.
1375 Since BFD doesn't know how to read debug symbols in a format-independent
1376 way (and may never do so...), we have to do it ourselves. We will never
1377 be called unless this is an a.out (or very similar) file.
1378 FIXME, there should be a cleaner peephole into the BFD environment here. */
1381 dbx_symfile_init (sf
)
1386 struct stat statbuf
;
1387 bfd
*sym_bfd
= sf
->sym_bfd
;
1388 char *name
= bfd_get_filename (sym_bfd
);
1389 struct dbx_symfile_info
*info
;
1390 unsigned char size_temp
[4];
1392 /* Allocate struct to keep track of the symfile */
1393 sf
->sym_private
= xmalloc (sizeof (*info
)); /* FIXME storage leak */
1394 info
= (struct dbx_symfile_info
*)sf
->sym_private
;
1396 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1397 desc
= fileno ((FILE *)(sym_bfd
->iostream
)); /* Raw file descriptor */
1398 #define STRING_TABLE_OFFSET (sym_bfd->origin + obj_str_filepos (sym_bfd))
1399 #define SYMBOL_TABLE_OFFSET (sym_bfd->origin + obj_sym_filepos (sym_bfd))
1400 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
1403 info
->text_sect
= bfd_get_section_by_name (sym_bfd
, ".text");
1404 if (!info
->text_sect
)
1406 info
->symcount
= bfd_get_symcount (sym_bfd
);
1408 /* Read the string table size and check it for bogosity. */
1409 val
= lseek (desc
, STRING_TABLE_OFFSET
, L_SET
);
1411 perror_with_name (name
);
1412 if (fstat (desc
, &statbuf
) == -1)
1413 perror_with_name (name
);
1415 val
= myread (desc
, size_temp
, sizeof (long));
1417 perror_with_name (name
);
1418 info
->stringtab_size
= bfd_h_get_32 (sym_bfd
, size_temp
);
1420 if (info
->stringtab_size
>= 0 && info
->stringtab_size
< statbuf
.st_size
)
1422 info
->stringtab
= (char *) xmalloc (info
->stringtab_size
);
1423 /* Caller is responsible for freeing the string table. No cleanup. */
1426 info
->stringtab
= NULL
;
1427 if (info
->stringtab
== NULL
&& info
->stringtab_size
!= 0)
1428 error ("ridiculous string table size: %d bytes", info
->stringtab_size
);
1430 /* Now read in the string table in one big gulp. */
1432 val
= lseek (desc
, STRING_TABLE_OFFSET
, L_SET
);
1434 perror_with_name (name
);
1435 val
= myread (desc
, info
->stringtab
, info
->stringtab_size
);
1437 perror_with_name (name
);
1439 /* Record the position of the symbol table for later use. */
1441 info
->symtab_offset
= SYMBOL_TABLE_OFFSET
;
1444 /* Buffer for reading the symbol table entries. */
1445 static struct internal_nlist symbuf
[4096];
1446 static int symbuf_idx
;
1447 static int symbuf_end
;
1449 /* I/O descriptor for reading the symbol table. */
1450 static int symtab_input_desc
;
1452 /* The address in memory of the string table of the object file we are
1453 reading (which might not be the "main" object file, but might be a
1454 shared library or some other dynamically loaded thing). This is set
1455 by read_dbx_symtab when building psymtabs, and by read_ofile_symtab
1456 when building symtabs, and is used only by next_symbol_text. */
1457 static char *stringtab_global
;
1459 /* Refill the symbol table input buffer
1460 and set the variables that control fetching entries from it.
1461 Reports an error if no data available.
1462 This function can read past the end of the symbol table
1463 (into the string table) but this does no harm. */
1468 int nbytes
= myread (symtab_input_desc
, symbuf
, sizeof (symbuf
));
1470 perror_with_name ("<symbol file>");
1471 else if (nbytes
== 0)
1472 error ("Premature end of file reading symbol table");
1473 symbuf_end
= nbytes
/ symbol_size
;
1478 #define SWAP_SYMBOL(symp) \
1480 (symp)->n_strx = bfd_h_get_32(symfile_bfd, \
1481 (unsigned char *)&(symp)->n_strx); \
1482 (symp)->n_desc = bfd_h_get_16 (symfile_bfd, \
1483 (unsigned char *)&(symp)->n_desc); \
1484 (symp)->n_value = bfd_h_get_32 (symfile_bfd, \
1485 (unsigned char *)&(symp)->n_value); \
1488 /* Invariant: The symbol pointed to by symbuf_idx is the first one
1489 that hasn't been swapped. Swap the symbol at the same time
1490 that symbuf_idx is incremented. */
1492 /* dbx allows the text of a symbol name to be continued into the
1493 next symbol name! When such a continuation is encountered
1494 (a \ at the end of the text of a name)
1495 call this function to get the continuation. */
1500 if (symbuf_idx
== symbuf_end
)
1503 SWAP_SYMBOL(&symbuf
[symbuf_idx
]);
1504 return symbuf
[symbuf_idx
++].n_strx
+ stringtab_global
;
1507 /* Initializes storage for all of the partial symbols that will be
1508 created by read_dbx_symtab and subsidiaries. */
1511 init_psymbol_list (total_symbols
)
1514 /* Free any previously allocated psymbol lists. */
1515 if (global_psymbols
.list
)
1516 free (global_psymbols
.list
);
1517 if (static_psymbols
.list
)
1518 free (static_psymbols
.list
);
1520 /* Current best guess is that there are approximately a twentieth
1521 of the total symbols (in a debugging file) are global or static
1523 global_psymbols
.size
= total_symbols
/ 10;
1524 static_psymbols
.size
= total_symbols
/ 10;
1525 global_psymbols
.next
= global_psymbols
.list
= (struct partial_symbol
*)
1526 xmalloc (global_psymbols
.size
* sizeof (struct partial_symbol
));
1527 static_psymbols
.next
= static_psymbols
.list
= (struct partial_symbol
*)
1528 xmalloc (static_psymbols
.size
* sizeof (struct partial_symbol
));
1531 /* Initialize the list of bincls to contain none and have some
1535 init_bincl_list (number
)
1538 bincls_allocated
= number
;
1539 next_bincl
= bincl_list
= (struct header_file_location
*)
1540 xmalloc (bincls_allocated
* sizeof(struct header_file_location
));
1543 /* Add a bincl to the list. */
1546 add_bincl_to_list (pst
, name
, instance
)
1547 struct partial_symtab
*pst
;
1551 if (next_bincl
>= bincl_list
+ bincls_allocated
)
1553 int offset
= next_bincl
- bincl_list
;
1554 bincls_allocated
*= 2;
1555 bincl_list
= (struct header_file_location
*)
1556 xrealloc ((char *)bincl_list
,
1557 bincls_allocated
* sizeof (struct header_file_location
));
1558 next_bincl
= bincl_list
+ offset
;
1560 next_bincl
->pst
= pst
;
1561 next_bincl
->instance
= instance
;
1562 next_bincl
++->name
= name
;
1565 /* Given a name, value pair, find the corresponding
1566 bincl in the list. Return the partial symtab associated
1567 with that header_file_location. */
1569 static struct partial_symtab
*
1570 find_corresponding_bincl_psymtab (name
, instance
)
1574 struct header_file_location
*bincl
;
1576 for (bincl
= bincl_list
; bincl
< next_bincl
; bincl
++)
1577 if (bincl
->instance
== instance
1578 && !strcmp (name
, bincl
->name
))
1581 return (struct partial_symtab
*) 0;
1584 /* Free the storage allocated for the bincl list. */
1590 bincls_allocated
= 0;
1593 static struct partial_symtab
*start_psymtab ();
1594 static void end_psymtab();
1597 /* This is normally a macro defined in read_dbx_symtab, but this
1598 is a lot easier to debug. */
1600 ADD_PSYMBOL_TO_PLIST(NAME
, NAMELENGTH
, NAMESPACE
, CLASS
, PLIST
, VALUE
)
1603 enum namespace NAMESPACE
;
1604 enum address_class CLASS
;
1605 struct psymbol_allocation_list
*PLIST
;
1606 unsigned long VALUE
;
1608 register struct partial_symbol
*psym
;
1613 (LIST
).list
+ (LIST
).size
)
1615 (LIST
).list
= (struct partial_symbol
*)
1616 xrealloc ((LIST
).list
,
1618 * sizeof (struct partial_symbol
)));
1619 /* Next assumes we only went one over. Should be good if
1620 program works correctly */
1622 (LIST
).list
+ (LIST
).size
;
1625 psym
= (LIST
).next
++;
1628 SYMBOL_NAME (psym
) = (char *) obstack_alloc (psymbol_obstack
,
1630 strncpy (SYMBOL_NAME (psym
), (NAME
), (NAMELENGTH
));
1631 SYMBOL_NAME (psym
)[(NAMELENGTH
)] = '\0';
1632 SYMBOL_NAMESPACE (psym
) = (NAMESPACE
);
1633 SYMBOL_CLASS (psym
) = (CLASS
);
1634 SYMBOL_VALUE (psym
) = (VALUE
);
1638 /* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
1639 #define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
1640 ADD_PSYMBOL_TO_PLIST(NAME, NAMELENGTH, NAMESPACE, CLASS, &LIST, VALUE)
1644 /* Given pointers to an a.out symbol table in core containing dbx
1645 style data, setup partial_symtab's describing each source file for
1646 which debugging information is available. NLISTLEN is the number
1647 of symbols in the symbol table. All symbol names are given as
1648 offsets relative to STRINGTAB. STRINGTAB_SIZE is the size of
1649 STRINGTAB. SYMFILE_NAME is the name of the file we are reading from
1650 and ADDR is its relocated address (if incremental) or 0 (if not). */
1653 read_dbx_symtab (symfile_name
, addr
,
1654 desc
, stringtab
, stringtab_size
, nlistlen
,
1655 text_addr
, text_size
)
1659 register char *stringtab
;
1660 register long stringtab_size
;
1661 register int nlistlen
;
1662 CORE_ADDR text_addr
;
1665 register struct internal_nlist
*bufp
;
1666 register char *namestring
;
1667 register struct partial_symbol
*psym
;
1669 int past_first_source_file
= 0;
1670 CORE_ADDR last_o_file_start
= 0;
1671 struct cleanup
*old_chain
;
1674 /* End of the text segment of the executable file. */
1675 CORE_ADDR end_of_text_addr
;
1677 /* Current partial symtab */
1678 struct partial_symtab
*pst
;
1680 /* List of current psymtab's include files */
1681 char **psymtab_include_list
;
1682 int includes_allocated
;
1685 /* Index within current psymtab dependency list */
1686 struct partial_symtab
**dependency_list
;
1687 int dependencies_used
, dependencies_allocated
;
1689 stringtab_global
= stringtab
;
1691 pst
= (struct partial_symtab
*) 0;
1693 includes_allocated
= 30;
1695 psymtab_include_list
= (char **) alloca (includes_allocated
*
1698 dependencies_allocated
= 30;
1699 dependencies_used
= 0;
1701 (struct partial_symtab
**) alloca (dependencies_allocated
*
1702 sizeof (struct partial_symtab
*));
1704 /* FIXME!! If an error occurs, this blows away the whole symbol table!
1705 It should only blow away the psymtabs created herein. We could
1706 be reading a shared library or a dynloaded file! */
1707 old_chain
= make_cleanup (free_all_psymtabs
, 0);
1709 /* Init bincl list */
1710 init_bincl_list (20);
1711 make_cleanup (free_bincl_list
, 0);
1713 last_source_file
= 0;
1715 #ifdef END_OF_TEXT_DEFAULT
1716 end_of_text_addr
= END_OF_TEXT_DEFAULT
;
1718 end_of_text_addr
= text_addr
+ addr
+ text_size
; /* Relocate */
1721 symtab_input_desc
= desc
; /* This is needed for fill_symbuf below */
1722 symbuf_end
= symbuf_idx
= 0;
1724 for (symnum
= 0; symnum
< nlistlen
; symnum
++)
1726 /* Get the symbol for this run and pull out some info */
1727 QUIT
; /* allow this to be interruptable */
1728 if (symbuf_idx
== symbuf_end
)
1730 bufp
= &symbuf
[symbuf_idx
++];
1733 * Special case to speed up readin.
1735 if (bufp
->n_type
== (unsigned char)N_SLINE
) continue;
1739 /* Ok. There is a lot of code duplicated in the rest of this
1740 switch statement (for efficiency reasons). Since I don't
1741 like duplicating code, I will do my penance here, and
1742 describe the code which is duplicated:
1744 *) The assignment to namestring.
1745 *) The call to strchr.
1746 *) The addition of a partial symbol the the two partial
1747 symbol lists. This last is a large section of code, so
1748 I've imbedded it in the following macro.
1751 /* Set namestring based on bufp. If the string table index is invalid,
1752 give a fake name, and print a single error message per symbol file read,
1753 rather than abort the symbol reading or flood the user with messages. */
1754 #define SET_NAMESTRING()\
1755 if (bufp->n_strx < 0 || bufp->n_strx >= stringtab_size) { \
1756 complain (&string_table_offset_complaint, symnum); \
1757 namestring = "foo"; \
1759 namestring = bufp->n_strx + stringtab
1761 /* Add a symbol with an integer value to a psymtab. */
1762 /* This is a macro unless we're debugging. See above this function. */
1764 # define ADD_PSYMBOL_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
1765 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
1769 /* Add a symbol with a CORE_ADDR value to a psymtab. */
1770 #define ADD_PSYMBOL_ADDR_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE) \
1771 ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, \
1772 SYMBOL_VALUE_ADDRESS)
1774 /* Add any kind of symbol to a psymtab. */
1775 #define ADD_PSYMBOL_VT_TO_LIST(NAME, NAMELENGTH, NAMESPACE, CLASS, LIST, VALUE, VT)\
1777 if ((LIST).next >= \
1778 (LIST).list + (LIST).size) \
1780 (LIST).list = (struct partial_symbol *) \
1781 xrealloc ((LIST).list, \
1783 * sizeof (struct partial_symbol))); \
1784 /* Next assumes we only went one over. Should be good if \
1785 program works correctly */ \
1787 (LIST).list + (LIST).size; \
1790 psym = (LIST).next++; \
1792 SYMBOL_NAME (psym) = (char *) obstack_alloc (psymbol_obstack, \
1793 (NAMELENGTH) + 1); \
1794 strncpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \
1795 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \
1796 SYMBOL_NAMESPACE (psym) = (NAMESPACE); \
1797 SYMBOL_CLASS (psym) = (CLASS); \
1798 VT (psym) = (VALUE); \
1801 /* End of macro definitions, now let's handle them symbols! */
1803 switch (bufp
->n_type
)
1806 * Standard, external, non-debugger, symbols
1809 case N_TEXT
| N_EXT
:
1810 case N_NBTEXT
| N_EXT
:
1811 case N_NBDATA
| N_EXT
:
1812 case N_NBBSS
| N_EXT
:
1813 case N_SETV
| N_EXT
:
1815 case N_DATA
| N_EXT
:
1818 bufp
->n_value
+= addr
; /* Relocate */
1823 record_misc_function (namestring
, bufp
->n_value
,
1824 bufp
->n_type
); /* Always */
1828 /* Standard, local, non-debugger, symbols */
1832 /* We need to be able to deal with both N_FN or N_TEXT,
1833 because we have no way of knowing whether the sys-supplied ld
1834 or GNU ld was used to make the executable. Sequents throw
1835 in another wrinkle -- they renumbered N_FN. */
1839 bufp
->n_value
+= addr
; /* Relocate */
1841 if ((namestring
[0] == '-' && namestring
[1] == 'l')
1842 || (namestring
[(nsl
= strlen (namestring
)) - 1] == 'o'
1843 && namestring
[nsl
- 2] == '.'))
1845 if (entry_point
< bufp
->n_value
1846 && entry_point
>= last_o_file_start
1847 && addr
== 0) /* FIXME nogood nomore */
1849 startup_file_start
= last_o_file_start
;
1850 startup_file_end
= bufp
->n_value
;
1852 if (past_first_source_file
&& pst
1853 /* The gould NP1 uses low values for .o and -l symbols
1854 which are not the address. */
1855 && bufp
->n_value
> pst
->textlow
)
1857 end_psymtab (pst
, psymtab_include_list
, includes_used
,
1858 symnum
* symbol_size
, bufp
->n_value
,
1859 dependency_list
, dependencies_used
,
1860 global_psymbols
.next
, static_psymbols
.next
);
1861 pst
= (struct partial_symtab
*) 0;
1863 dependencies_used
= 0;
1866 past_first_source_file
= 1;
1867 last_o_file_start
= bufp
->n_value
;
1872 bufp
->n_value
+= addr
; /* Relocate */
1874 /* Check for __DYNAMIC, which is used by Sun shared libraries.
1875 Record it even if it's local, not global, so we can find it.
1876 Same with virtual function tables, both global and static. */
1877 if ((namestring
[8] == 'C' && (strcmp ("__DYNAMIC", namestring
) == 0))
1878 || VTBL_PREFIX_P ((namestring
+HASH_OFFSET
)))
1880 /* Not really a function here, but... */
1881 record_misc_function (namestring
, bufp
->n_value
,
1882 bufp
->n_type
); /* Always */
1886 case N_UNDF
| N_EXT
:
1887 if (bufp
->n_value
!= 0) {
1888 /* This is a "Fortran COMMON" symbol. See if the target
1889 environment knows where it has been relocated to. */
1894 if (target_lookup_symbol (namestring
, &reladdr
)) {
1895 continue; /* Error in lookup; ignore symbol for now. */
1897 bufp
->n_type
^= (N_BSS
^N_UNDF
); /* Define it as a bss-symbol */
1898 bufp
->n_value
= reladdr
;
1899 goto bss_ext_symbol
;
1901 continue; /* Just undefined, not COMMON */
1903 /* Lots of symbol types we can just ignore. */
1912 /* Keep going . . .*/
1915 * Special symbol types for GNU
1918 case N_INDR
| N_EXT
:
1920 case N_SETA
| N_EXT
:
1922 case N_SETT
| N_EXT
:
1924 case N_SETD
| N_EXT
:
1926 case N_SETB
| N_EXT
:
1935 unsigned long valu
= bufp
->n_value
;
1936 /* Symbol number of the first symbol of this file (i.e. the N_SO
1937 if there is just one, or the first if we have a pair). */
1938 int first_symnum
= symnum
;
1940 /* End the current partial symtab and start a new one */
1944 /* Peek at the next symbol. If it is also an N_SO, the
1945 first one just indicates the directory. */
1946 if (symbuf_idx
== symbuf_end
)
1948 bufp
= &symbuf
[symbuf_idx
];
1949 /* n_type is only a char, so swapping swapping is irrelevant. */
1950 if (bufp
->n_type
== (unsigned char)N_SO
)
1954 valu
= bufp
->n_value
;
1958 valu
+= addr
; /* Relocate */
1960 if (pst
&& past_first_source_file
)
1962 end_psymtab (pst
, psymtab_include_list
, includes_used
,
1963 first_symnum
* symbol_size
, valu
,
1964 dependency_list
, dependencies_used
,
1965 global_psymbols
.next
, static_psymbols
.next
);
1966 pst
= (struct partial_symtab
*) 0;
1968 dependencies_used
= 0;
1971 past_first_source_file
= 1;
1973 pst
= start_psymtab (symfile_name
, addr
,
1975 first_symnum
* symbol_size
,
1976 global_psymbols
.next
, static_psymbols
.next
);
1981 /* Add this bincl to the bincl_list for future EXCLs. No
1982 need to save the string; it'll be around until
1983 read_dbx_symtab function returns */
1987 add_bincl_to_list (pst
, namestring
, bufp
->n_value
);
1989 /* Mark down an include file in the current psymtab */
1991 psymtab_include_list
[includes_used
++] = namestring
;
1992 if (includes_used
>= includes_allocated
)
1994 char **orig
= psymtab_include_list
;
1996 psymtab_include_list
= (char **)
1997 alloca ((includes_allocated
*= 2) *
1999 bcopy (orig
, psymtab_include_list
,
2000 includes_used
* sizeof (char *));
2006 /* Mark down an include file in the current psymtab */
2010 /* In C++, one may expect the same filename to come round many
2011 times, when code is coming alternately from the main file
2012 and from inline functions in other files. So I check to see
2013 if this is a file we've seen before -- either the main
2014 source file, or a previously included file.
2016 This seems to be a lot of time to be spending on N_SOL, but
2017 things like "break c-exp.y:435" need to work (I
2018 suppose the psymtab_include_list could be hashed or put
2019 in a binary tree, if profiling shows this is a major hog). */
2020 if (!strcmp (namestring
, pst
->filename
))
2024 for (i
= 0; i
< includes_used
; i
++)
2025 if (!strcmp (namestring
, psymtab_include_list
[i
]))
2034 psymtab_include_list
[includes_used
++] = namestring
;
2035 if (includes_used
>= includes_allocated
)
2037 char **orig
= psymtab_include_list
;
2039 psymtab_include_list
= (char **)
2040 alloca ((includes_allocated
*= 2) *
2042 bcopy (orig
, psymtab_include_list
,
2043 includes_used
* sizeof (char *));
2047 case N_LSYM
: /* Typedef or automatic variable. */
2048 case N_STSYM
: /* Data seg var -- static */
2049 case N_LCSYM
: /* BSS " */
2050 case N_NBSTS
: /* Gould nobase. */
2051 case N_NBLCS
: /* symbols. */
2055 p
= (char *) strchr (namestring
, ':');
2057 /* Skip if there is no :. */
2063 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2064 STRUCT_NAMESPACE
, LOC_TYPEDEF
,
2065 static_psymbols
, bufp
->n_value
);
2068 /* Also a typedef with the same name. */
2069 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2070 VAR_NAMESPACE
, LOC_TYPEDEF
,
2071 static_psymbols
, bufp
->n_value
);
2076 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2077 VAR_NAMESPACE
, LOC_TYPEDEF
,
2078 static_psymbols
, bufp
->n_value
);
2080 /* If this is an enumerated type, we need to
2081 add all the enum constants to the partial symbol
2082 table. This does not cover enums without names, e.g.
2083 "enum {a, b} c;" in C, but fortunately those are
2084 rare. There is no way for GDB to find those from the
2085 enum type without spending too much time on it. Thus
2086 to solve this problem, the compiler needs to put out separate
2087 constant symbols ('c' N_LSYMS) for enum constants in
2088 enums without names, or put out a dummy type. */
2090 /* We are looking for something of the form
2091 <name> ":" ("t" | "T") [<number> "="] "e"
2092 {<constant> ":" <value> ","} ";". */
2094 /* Skip over the colon and the 't' or 'T'. */
2096 /* This type may be given a number. Skip over it. */
2097 while ((*p
>= '0' && *p
<= '9')
2103 /* We have found an enumerated type. */
2104 /* According to comments in read_enum_type
2105 a comma could end it instead of a semicolon.
2106 I don't know where that happens.
2108 while (*p
&& *p
!= ';' && *p
!= ',')
2112 /* Check for and handle cretinous dbx symbol name
2115 p
= next_symbol_text ();
2117 /* Point to the character after the name
2118 of the enum constant. */
2119 for (q
= p
; *q
&& *q
!= ':'; q
++)
2121 /* Note that the value doesn't matter for
2122 enum constants in psymtabs, just in symtabs. */
2123 ADD_PSYMBOL_TO_LIST (p
, q
- p
,
2124 VAR_NAMESPACE
, LOC_CONST
,
2125 static_psymbols
, 0);
2126 /* Point past the name. */
2128 /* Skip over the value. */
2129 while (*p
&& *p
!= ',')
2131 /* Advance past the comma. */
2139 /* Constant, e.g. from "const" in Pascal. */
2140 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2141 VAR_NAMESPACE
, LOC_CONST
,
2142 static_psymbols
, bufp
->n_value
);
2145 /* Skip if the thing following the : is
2146 not a letter (which indicates declaration of a local
2147 variable, which we aren't interested in). */
2152 case N_GSYM
: /* Global (extern) variable; can be
2153 data or bss (sigh). */
2155 /* Following may probably be ignored; I'll leave them here
2156 for now (until I do Pascal and Modula 2 extensions). */
2158 case N_PC
: /* I may or may not need this; I
2160 case N_M2C
: /* I suspect that I can ignore this here. */
2161 case N_SCOPE
: /* Same. */
2165 p
= (char *) strchr (namestring
, ':');
2167 continue; /* Not a debugging symbol. */
2171 /* Main processing section for debugging symbols which
2172 the initial read through the symbol tables needs to worry
2173 about. If we reach this point, the symbol which we are
2174 considering is definitely one we are interested in.
2175 p must also contain the (valid) index into the namestring
2176 which indicates the debugging type symbol. */
2181 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2182 VAR_NAMESPACE
, LOC_CONST
,
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_STATIC
,
2189 static_psymbols
, bufp
->n_value
);
2192 bufp
->n_value
+= addr
; /* Relocate */
2193 /* The addresses in these entries are reported to be
2194 wrong. See the code that reads 'G's for symtabs. */
2195 ADD_PSYMBOL_ADDR_TO_LIST (namestring
, p
- namestring
,
2196 VAR_NAMESPACE
, LOC_STATIC
,
2197 global_psymbols
, bufp
->n_value
);
2201 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2202 VAR_NAMESPACE
, LOC_TYPEDEF
,
2203 static_psymbols
, bufp
->n_value
);
2207 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2208 VAR_NAMESPACE
, LOC_BLOCK
,
2209 static_psymbols
, bufp
->n_value
);
2212 /* Global functions were ignored here, but now they
2213 are put into the global psymtab like one would expect.
2214 They're also in the misc fn vector...
2215 FIXME, why did it used to ignore these? That broke
2216 "i fun" on these functions. */
2218 ADD_PSYMBOL_TO_LIST (namestring
, p
- namestring
,
2219 VAR_NAMESPACE
, LOC_BLOCK
,
2220 global_psymbols
, bufp
->n_value
);
2223 /* Two things show up here (hopefully); static symbols of
2224 local scope (static used inside braces) or extensions
2225 of structure symbols. We can ignore both. */
2241 /* Unexpected symbol. Ignore it; perhaps it is an extension
2242 that we don't know about.
2244 Someone says sun cc puts out symbols like
2245 /foo/baz/maclib::/usr/local/bin/maclib,
2246 which would get here with a symbol type of ':'. */
2254 /* Find the corresponding bincl and mark that psymtab on the
2255 psymtab dependency list */
2257 struct partial_symtab
*needed_pst
=
2258 find_corresponding_bincl_psymtab (namestring
, bufp
->n_value
);
2260 /* If this include file was defined earlier in this file,
2262 if (needed_pst
== pst
) continue;
2269 for (i
= 0; i
< dependencies_used
; i
++)
2270 if (dependency_list
[i
] == needed_pst
)
2276 /* If it's already in the list, skip the rest. */
2277 if (found
) continue;
2279 dependency_list
[dependencies_used
++] = needed_pst
;
2280 if (dependencies_used
>= dependencies_allocated
)
2282 struct partial_symtab
**orig
= dependency_list
;
2284 (struct partial_symtab
**)
2285 alloca ((dependencies_allocated
*= 2)
2286 * sizeof (struct partial_symtab
*));
2287 bcopy (orig
, dependency_list
,
2289 * sizeof (struct partial_symtab
*)));
2291 fprintf (stderr
, "Had to reallocate dependency list.\n");
2292 fprintf (stderr
, "New dependencies allocated: %d\n",
2293 dependencies_allocated
);
2298 error ("Invalid symbol data: \"repeated\" header file not previously seen, at symtab pos %d.",
2306 case N_SSYM
: /* Claim: Structure or union element.
2307 Hopefully, I can ignore this. */
2308 case N_ENTRY
: /* Alternate entry point; can ignore. */
2309 case N_MAIN
: /* Can definitely ignore this. */
2310 case N_CATCH
: /* These are GNU C++ extensions */
2311 case N_EHDECL
: /* that can safely be ignored here. */
2322 case N_NSYMS
: /* Ultrix 4.0: symbol count */
2323 case N_DEFD
: /* GNU Modula-2 */
2324 /* These symbols aren't interesting; don't worry about them */
2329 /* If we haven't found it yet, ignore it. It's probably some
2330 new type we don't know about yet. */
2331 complain (&unknown_symtype_complaint
, local_hex_string(bufp
->n_type
));
2336 /* If there's stuff to be cleaned up, clean it up. */
2337 if (nlistlen
> 0 /* We have some syms */
2338 && entry_point
< bufp
->n_value
2339 && entry_point
>= last_o_file_start
)
2341 startup_file_start
= last_o_file_start
;
2342 startup_file_end
= bufp
->n_value
;
2347 end_psymtab (pst
, psymtab_include_list
, includes_used
,
2348 symnum
* symbol_size
, end_of_text_addr
,
2349 dependency_list
, dependencies_used
,
2350 global_psymbols
.next
, static_psymbols
.next
);
2352 dependencies_used
= 0;
2353 pst
= (struct partial_symtab
*) 0;
2357 discard_cleanups (old_chain
);
2361 * Allocate and partially fill a partial symtab. It will be
2362 * completely filled at the end of the symbol list.
2364 SYMFILE_NAME is the name of the symbol-file we are reading from, and ADDR
2365 is the address relative to which its symbols are (incremental) or 0
2367 static struct partial_symtab
*
2368 start_psymtab (symfile_name
, addr
,
2369 filename
, textlow
, ldsymoff
, global_syms
, static_syms
)
2375 struct partial_symbol
*global_syms
;
2376 struct partial_symbol
*static_syms
;
2378 struct partial_symtab
*result
=
2379 (struct partial_symtab
*) obstack_alloc (psymbol_obstack
,
2380 sizeof (struct partial_symtab
));
2382 result
->addr
= addr
;
2384 result
->symfile_name
=
2385 (char *) obstack_alloc (psymbol_obstack
,
2386 strlen (symfile_name
) + 1);
2387 strcpy (result
->symfile_name
, symfile_name
);
2390 (char *) obstack_alloc (psymbol_obstack
,
2391 strlen (filename
) + 1);
2392 strcpy (result
->filename
, filename
);
2394 result
->textlow
= textlow
;
2395 result
->ldsymoff
= ldsymoff
;
2399 result
->read_symtab
= dbx_psymtab_to_symtab
;
2401 result
->globals_offset
= global_syms
- global_psymbols
.list
;
2402 result
->statics_offset
= static_syms
- static_psymbols
.list
;
2404 result
->n_global_syms
= 0;
2405 result
->n_static_syms
= 0;
2412 compare_psymbols (s1
, s2
)
2413 register struct partial_symbol
*s1
, *s2
;
2416 *st1
= SYMBOL_NAME (s1
),
2417 *st2
= SYMBOL_NAME (s2
);
2419 if (st1
[0] - st2
[0])
2420 return st1
[0] - st2
[0];
2421 if (st1
[1] - st2
[1])
2422 return st1
[1] - st2
[1];
2423 return strcmp (st1
+ 1, st2
+ 1);
2427 /* Close off the current usage of a partial_symbol table entry. This
2428 involves setting the correct number of includes (with a realloc),
2429 setting the high text mark, setting the symbol length in the
2430 executable, and setting the length of the global and static lists
2433 The global symbols and static symbols are then seperately sorted.
2435 Then the partial symtab is put on the global list.
2436 *** List variables and peculiarities of same. ***
2439 end_psymtab (pst
, include_list
, num_includes
, capping_symbol_offset
,
2440 capping_text
, dependency_list
, number_dependencies
,
2441 capping_global
, capping_static
)
2442 struct partial_symtab
*pst
;
2443 char **include_list
;
2445 int capping_symbol_offset
;
2446 CORE_ADDR capping_text
;
2447 struct partial_symtab
**dependency_list
;
2448 int number_dependencies
;
2449 struct partial_symbol
*capping_global
, *capping_static
;
2453 pst
->ldsymlen
= capping_symbol_offset
- pst
->ldsymoff
;
2454 pst
->texthigh
= capping_text
;
2456 pst
->n_global_syms
=
2457 capping_global
- (global_psymbols
.list
+ pst
->globals_offset
);
2458 pst
->n_static_syms
=
2459 capping_static
- (static_psymbols
.list
+ pst
->statics_offset
);
2461 pst
->number_of_dependencies
= number_dependencies
;
2462 if (number_dependencies
)
2464 pst
->dependencies
= (struct partial_symtab
**)
2465 obstack_alloc (psymbol_obstack
,
2466 number_dependencies
* sizeof (struct partial_symtab
*));
2467 bcopy (dependency_list
, pst
->dependencies
,
2468 number_dependencies
* sizeof (struct partial_symtab
*));
2471 pst
->dependencies
= 0;
2473 for (i
= 0; i
< num_includes
; i
++)
2475 /* Eventually, put this on obstack */
2476 struct partial_symtab
*subpst
=
2477 (struct partial_symtab
*)
2478 obstack_alloc (psymbol_obstack
,
2479 sizeof (struct partial_symtab
));
2482 (char *) obstack_alloc (psymbol_obstack
,
2483 strlen (include_list
[i
]) + 1);
2484 strcpy (subpst
->filename
, include_list
[i
]);
2486 subpst
->symfile_name
= pst
->symfile_name
;
2487 subpst
->addr
= pst
->addr
;
2491 subpst
->texthigh
= 0;
2493 /* We could save slight bits of space by only making one of these,
2494 shared by the entire set of include files. FIXME-someday. */
2495 subpst
->dependencies
= (struct partial_symtab
**)
2496 obstack_alloc (psymbol_obstack
,
2497 sizeof (struct partial_symtab
*));
2498 subpst
->dependencies
[0] = pst
;
2499 subpst
->number_of_dependencies
= 1;
2501 subpst
->globals_offset
=
2502 subpst
->n_global_syms
=
2503 subpst
->statics_offset
=
2504 subpst
->n_static_syms
= 0;
2508 subpst
->read_symtab
= dbx_psymtab_to_symtab
;
2510 subpst
->next
= partial_symtab_list
;
2511 partial_symtab_list
= subpst
;
2514 /* Sort the global list; don't sort the static list */
2515 qsort (global_psymbols
.list
+ pst
->globals_offset
, pst
->n_global_syms
,
2516 sizeof (struct partial_symbol
), compare_psymbols
);
2518 /* If there is already a psymtab or symtab for a file of this name, remove it.
2519 (If there is a symtab, more drastic things also happen.)
2520 This happens in VxWorks. */
2521 free_named_symtabs (pst
->filename
);
2523 /* Put the psymtab on the psymtab list */
2524 pst
->next
= partial_symtab_list
;
2525 partial_symtab_list
= pst
;
2529 psymtab_to_symtab_1 (pst
, desc
, stringtab
, stringtab_size
, sym_offset
)
2530 struct partial_symtab
*pst
;
2536 struct cleanup
*old_chain
;
2544 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2549 /* Read in all partial symtabs on which this one is dependent */
2550 for (i
= 0; i
< pst
->number_of_dependencies
; i
++)
2551 if (!pst
->dependencies
[i
]->readin
)
2553 /* Inform about additional files that need to be read in. */
2556 fputs_filtered (" ", stdout
);
2558 fputs_filtered ("and ", stdout
);
2560 printf_filtered ("%s...", pst
->dependencies
[i
]->filename
);
2561 wrap_here (""); /* Flush output */
2564 psymtab_to_symtab_1 (pst
->dependencies
[i
], desc
,
2565 stringtab
, stringtab_size
, sym_offset
);
2568 if (pst
->ldsymlen
) /* Otherwise it's a dummy */
2570 /* Init stuff necessary for reading in symbols */
2575 old_chain
= make_cleanup (really_free_pendings
, 0);
2577 /* Read in this files symbols */
2578 lseek (desc
, sym_offset
, L_SET
);
2580 read_ofile_symtab (desc
, stringtab
, stringtab_size
,
2582 pst
->ldsymlen
, pst
->textlow
,
2583 pst
->texthigh
- pst
->textlow
, pst
->addr
);
2584 sort_symtab_syms (pst
->symtab
);
2586 do_cleanups (old_chain
);
2593 * Read in all of the symbols for a given psymtab for real.
2594 * Be verbose about it if the user wants that.
2597 dbx_psymtab_to_symtab (pst
)
2598 struct partial_symtab
*pst
;
2603 struct stat statbuf
;
2604 struct cleanup
*old_chain
;
2613 fprintf (stderr
, "Psymtab for %s already read in. Shouldn't happen.\n",
2618 if (pst
->ldsymlen
|| pst
->number_of_dependencies
)
2620 /* Print the message now, before reading the string table,
2621 to avoid disconcerting pauses. */
2624 printf_filtered ("Reading in symbols for %s...", pst
->filename
);
2628 /* Open symbol file and read in string table. Symbol_file_command
2629 guarantees that the symbol file name will be absolute, so there is
2630 no need for openp. */
2631 desc
= open(pst
->symfile_name
, O_RDONLY
, 0);
2634 perror_with_name (pst
->symfile_name
);
2636 sym_bfd
= bfd_fdopenr (pst
->symfile_name
, NULL
, desc
);
2640 error ("Could not open `%s' to read symbols: %s",
2641 pst
->symfile_name
, bfd_errmsg (bfd_error
));
2643 old_chain
= make_cleanup (bfd_close
, sym_bfd
);
2644 if (!bfd_check_format (sym_bfd
, bfd_object
))
2645 error ("\"%s\": can't read symbols: %s.",
2646 pst
->symfile_name
, bfd_errmsg (bfd_error
));
2648 /* We keep the string table for symfile resident in memory, but
2649 not the string table for any other symbol files. */
2650 if ((symfile
== 0) || 0 != strcmp(pst
->symfile_name
, symfile
))
2652 /* Read in the string table */
2654 /* FIXME, this uses internal BFD variables. See above in
2655 dbx_symbol_file_open where the macro is defined! */
2656 lseek (desc
, STRING_TABLE_OFFSET
, L_SET
);
2658 val
= myread (desc
, &st_temp
, sizeof st_temp
);
2660 perror_with_name (pst
->symfile_name
);
2661 stsize
= bfd_h_get_32 (sym_bfd
, (unsigned char *)&st_temp
);
2662 if (fstat (desc
, &statbuf
) < 0)
2663 perror_with_name (pst
->symfile_name
);
2665 if (stsize
>= 0 && stsize
< statbuf
.st_size
)
2667 #ifdef BROKEN_LARGE_ALLOCA
2668 stringtab
= (char *) xmalloc (stsize
);
2669 make_cleanup (free
, stringtab
);
2671 stringtab
= (char *) alloca (stsize
);
2676 if (stringtab
== NULL
&& stsize
!= 0)
2677 error ("ridiculous string table size: %d bytes", stsize
);
2679 /* FIXME, this uses internal BFD variables. See above in
2680 dbx_symbol_file_open where the macro is defined! */
2681 val
= lseek (desc
, STRING_TABLE_OFFSET
, L_SET
);
2683 perror_with_name (pst
->symfile_name
);
2684 val
= myread (desc
, stringtab
, stsize
);
2686 perror_with_name (pst
->symfile_name
);
2690 stringtab
= symfile_string_table
;
2691 stsize
= symfile_string_table_size
;
2694 symfile_bfd
= sym_bfd
; /* Kludge for SWAP_SYMBOL */
2695 /* FIXME POKING INSIDE BFD DATA STRUCTURES */
2696 symbol_size
= obj_symbol_entry_size (sym_bfd
);
2698 /* FIXME, this uses internal BFD variables. See above in
2699 dbx_symbol_file_open where the macro is defined! */
2700 psymtab_to_symtab_1 (pst
, desc
, stringtab
, stsize
,
2701 SYMBOL_TABLE_OFFSET
);
2703 /* Match with global symbols. This only needs to be done once,
2704 after all of the symtabs and dependencies have been read in. */
2705 scan_file_globals ();
2707 do_cleanups (old_chain
);
2709 /* Finish up the debug error message. */
2711 printf_filtered ("done.\n");
2716 * Scan through all of the global symbols defined in the object file,
2717 * assigning values to the debugging symbols that need to be assigned
2718 * to. Get these symbols from the misc function list.
2721 scan_file_globals ()
2726 for (mf
= 0; mf
< misc_function_count
; mf
++)
2728 char *namestring
= misc_function_vector
[mf
].name
;
2729 struct symbol
*sym
, *prev
;
2733 prev
= (struct symbol
*) 0;
2735 /* Get the hash index and check all the symbols
2736 under that hash index. */
2738 hash
= hashname (namestring
);
2740 for (sym
= global_sym_chain
[hash
]; sym
;)
2742 if (*namestring
== SYMBOL_NAME (sym
)[0]
2743 && !strcmp(namestring
+ 1, SYMBOL_NAME (sym
) + 1))
2745 /* Splice this symbol out of the hash chain and
2746 assign the value we have to it. */
2748 SYMBOL_VALUE_CHAIN (prev
) = SYMBOL_VALUE_CHAIN (sym
);
2750 global_sym_chain
[hash
] = SYMBOL_VALUE_CHAIN (sym
);
2752 /* Check to see whether we need to fix up a common block. */
2753 /* Note: this code might be executed several times for
2754 the same symbol if there are multiple references. */
2755 if (SYMBOL_CLASS (sym
) == LOC_BLOCK
)
2756 fix_common_block (sym
, misc_function_vector
[mf
].address
);
2758 SYMBOL_VALUE_ADDRESS (sym
) = misc_function_vector
[mf
].address
;
2761 sym
= SYMBOL_VALUE_CHAIN (prev
);
2763 sym
= global_sym_chain
[hash
];
2768 sym
= SYMBOL_VALUE_CHAIN (sym
);
2774 /* Process a pair of symbols. Currently they must both be N_SO's. */
2777 process_symbol_pair (type1
, desc1
, value1
, name1
,
2778 type2
, desc2
, value2
, name2
)
2788 /* No need to check PCC_SOL_BROKEN, on the assumption that such
2789 broken PCC's don't put out N_SO pairs. */
2790 if (last_source_file
)
2791 (void)end_symtab (value2
);
2792 start_symtab (name2
, name1
, value2
);
2796 * Read in a defined section of a specific object file's symbols.
2798 * DESC is the file descriptor for the file, positioned at the
2799 * beginning of the symtab
2800 * STRINGTAB is a pointer to the files string
2801 * table, already read in
2802 * SYM_OFFSET is the offset within the file of
2803 * the beginning of the symbols we want to read, NUM_SUMBOLS is the
2804 * number of symbols to read
2805 * TEXT_OFFSET is the beginning of the text segment we are reading symbols for
2806 * TEXT_SIZE is the size of the text segment read in.
2807 * OFFSET is a relocation offset which gets added to each symbol
2810 static struct symtab
*
2811 read_ofile_symtab (desc
, stringtab
, stringtab_size
, sym_offset
,
2812 sym_size
, text_offset
, text_size
, offset
)
2814 register char *stringtab
;
2815 unsigned int stringtab_size
;
2818 CORE_ADDR text_offset
;
2822 register char *namestring
;
2823 struct internal_nlist
*bufp
;
2825 unsigned max_symnum
;
2828 stringtab_global
= stringtab
;
2829 last_source_file
= 0;
2831 symtab_input_desc
= desc
;
2832 symbuf_end
= symbuf_idx
= 0;
2834 /* It is necessary to actually read one symbol *before* the start
2835 of this symtab's symbols, because the GCC_COMPILED_FLAG_SYMBOL
2836 occurs before the N_SO symbol.
2838 Detecting this in read_dbx_symtab
2839 would slow down initial readin, so we look for it here instead. */
2840 if (sym_offset
>= (int)symbol_size
)
2842 lseek (desc
, sym_offset
- symbol_size
, L_INCR
);
2844 bufp
= &symbuf
[symbuf_idx
++];
2849 processing_gcc_compilation
=
2850 (bufp
->n_type
== N_TEXT
2851 && !strcmp (namestring
, GCC_COMPILED_FLAG_SYMBOL
));
2852 /* FIXME!!! Check for gcc2_compiled... */
2856 /* The N_SO starting this symtab is the first symbol, so we
2857 better not check the symbol before it. I'm not this can
2858 happen, but it doesn't hurt to check for it. */
2859 lseek(desc
, sym_offset
, L_INCR
);
2860 processing_gcc_compilation
= 0;
2863 if (symbuf_idx
== symbuf_end
)
2865 bufp
= &symbuf
[symbuf_idx
];
2866 if (bufp
->n_type
!= (unsigned char)N_SO
)
2867 error("First symbol in segment of executable not a source symbol");
2869 max_symnum
= sym_size
/ symbol_size
;
2872 symnum
< max_symnum
;
2875 QUIT
; /* Allow this to be interruptable */
2876 if (symbuf_idx
== symbuf_end
)
2878 bufp
= &symbuf
[symbuf_idx
++];
2881 type
= bufp
->n_type
& N_TYPE
;
2882 if (type
== (unsigned char)N_CATCH
)
2884 /* N_CATCH is not fixed up by the linker, and unfortunately,
2885 there's no other place to put it in the .stab map. */
2886 bufp
->n_value
+= text_offset
+ offset
;
2888 else if (type
== N_TEXT
|| type
== N_DATA
|| type
== N_BSS
)
2889 bufp
->n_value
+= offset
;
2891 type
= bufp
->n_type
;
2896 short bufp_n_desc
= bufp
->n_desc
;
2897 unsigned long valu
= bufp
->n_value
;
2899 /* Check for a pair of N_SO symbols. */
2900 if (type
== (unsigned char)N_SO
)
2902 if (symbuf_idx
== symbuf_end
)
2904 bufp
= &symbuf
[symbuf_idx
];
2905 if (bufp
->n_type
== (unsigned char)N_SO
)
2907 char *namestring1
= namestring
;
2910 bufp
->n_value
+= offset
; /* Relocate */
2915 process_symbol_pair (N_SO
, bufp_n_desc
, valu
, namestring1
,
2916 N_SO
, bufp
->n_desc
, bufp
->n_value
,
2920 process_one_symbol(type
, bufp_n_desc
, valu
, namestring
);
2923 process_one_symbol (type
, bufp_n_desc
, valu
, namestring
);
2925 /* We skip checking for a new .o or -l file; that should never
2926 happen in this routine. */
2927 else if (type
== N_TEXT
2928 && !strcmp (namestring
, GCC_COMPILED_FLAG_SYMBOL
))
2929 /* I don't think this code will ever be executed, because
2930 the GCC_COMPILED_FLAG_SYMBOL usually is right before
2931 the N_SO symbol which starts this source file.
2932 However, there is no reason not to accept
2933 the GCC_COMPILED_FLAG_SYMBOL anywhere. */
2934 processing_gcc_compilation
= 1;
2935 else if (type
& N_EXT
|| type
== (unsigned char)N_TEXT
2936 || type
== (unsigned char)N_NBTEXT
2938 /* Global symbol: see if we came across a dbx defintion for
2939 a corresponding symbol. If so, store the value. Remove
2940 syms from the chain when their values are stored, but
2941 search the whole chain, as there may be several syms from
2942 different files with the same name. */
2943 /* This is probably not true. Since the files will be read
2944 in one at a time, each reference to a global symbol will
2945 be satisfied in each file as it appears. So we skip this
2951 return end_symtab (text_offset
+ text_size
);
2958 register char *p
= name
;
2959 register int total
= p
[0];
2972 /* Ensure result is positive. */
2973 if (total
< 0) total
+= (1000 << 6);
2974 return total
% HASHSIZE
;
2979 process_one_symbol (type
, desc
, valu
, name
)
2984 #ifndef SUN_FIXED_LBRAC_BUG
2985 /* This records the last pc address we've seen. We depend on their being
2986 an SLINE or FUN or SO before the first LBRAC, since the variable does
2987 not get reset in between reads of different symbol files. */
2988 static CORE_ADDR last_pc_address
;
2990 register struct context_stack
*new;
2993 /* Something is wrong if we see real data before
2994 seeing a source file name. */
2996 if (last_source_file
== 0 && type
!= (unsigned char)N_SO
)
2998 /* Currently this ignores N_ENTRY on Gould machines, N_NSYM on machines
2999 where that code is defined. */
3000 if (IGNORE_SYMBOL (type
))
3003 /* FIXME, this should not be an error, since it precludes extending
3004 the symbol table information in this way... */
3005 error ("Invalid symbol data: does not start by identifying a source file.");
3012 /* Either of these types of symbols indicates the start of
3013 a new function. We must process its "name" normally for dbx,
3014 but also record the start of a new lexical context, and possibly
3015 also the end of the lexical context for the previous function. */
3016 /* This is not always true. This type of symbol may indicate a
3017 text segment variable. */
3019 #ifndef SUN_FIXED_LBRAC_BUG
3020 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
3023 colon_pos
= strchr (name
, ':');
3025 || (*colon_pos
!= 'f' && *colon_pos
!= 'F'))
3027 define_symbol (valu
, name
, desc
, type
);
3031 within_function
= 1;
3032 if (context_stack_depth
> 0)
3034 new = &context_stack
[--context_stack_depth
];
3035 /* Make a block for the local symbols within. */
3036 finish_block (new->name
, &local_symbols
, new->old_blocks
,
3037 new->start_addr
, valu
);
3039 /* Stack must be empty now. */
3040 if (context_stack_depth
!= 0)
3041 error ("Invalid symbol data: unmatched N_LBRAC before symtab pos %d.",
3044 new = &context_stack
[context_stack_depth
++];
3045 new->old_blocks
= pending_blocks
;
3046 new->start_addr
= valu
;
3047 new->name
= define_symbol (valu
, name
, desc
, type
);
3052 /* Record the address at which this catch takes place. */
3053 define_symbol (valu
, name
, desc
, type
);
3057 /* Don't know what to do with these yet. */
3058 error ("action uncertain for eh extensions");
3062 /* This "symbol" just indicates the start of an inner lexical
3063 context within a function. */
3065 #if !defined (BLOCK_ADDRESS_ABSOLUTE)
3066 /* On most machines, the block addresses are relative to the
3067 N_SO, the linker did not relocate them (sigh). */
3068 valu
+= last_source_start_addr
;
3071 #ifndef SUN_FIXED_LBRAC_BUG
3072 if (valu
< last_pc_address
) {
3073 /* Patch current LBRAC pc value to match last handy pc value */
3074 complain (&lbrac_complaint
, 0);
3075 valu
= last_pc_address
;
3078 if (context_stack_depth
== context_stack_size
)
3080 context_stack_size
*= 2;
3081 context_stack
= (struct context_stack
*)
3082 xrealloc (context_stack
,
3084 * sizeof (struct context_stack
)));
3087 new = &context_stack
[context_stack_depth
++];
3089 new->locals
= local_symbols
;
3090 new->old_blocks
= pending_blocks
;
3091 new->start_addr
= valu
;
3097 /* This "symbol" just indicates the end of an inner lexical
3098 context that was started with N_LBRAC. */
3100 #if !defined (BLOCK_ADDRESS_ABSOLUTE)
3101 /* On most machines, the block addresses are relative to the
3102 N_SO, the linker did not relocate them (sigh). */
3103 valu
+= last_source_start_addr
;
3106 new = &context_stack
[--context_stack_depth
];
3107 if (desc
!= new->depth
)
3108 error ("Invalid symbol data: N_LBRAC/N_RBRAC symbol mismatch, symtab pos %d.", symnum
);
3110 /* Some compilers put the variable decls inside of an
3111 LBRAC/RBRAC block. This macro should be nonzero if this
3112 is true. DESC is N_DESC from the N_RBRAC symbol.
3113 GCC_P is true if we've detected the GCC_COMPILED_SYMBOL. */
3114 #if !defined (VARIABLES_INSIDE_BLOCK)
3115 #define VARIABLES_INSIDE_BLOCK(desc, gcc_p) 0
3118 /* Can only use new->locals as local symbols here if we're in
3119 gcc or on a machine that puts them before the lbrack. */
3120 if (!VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
))
3121 local_symbols
= new->locals
;
3123 /* If this is not the outermost LBRAC...RBRAC pair in the
3124 function, its local symbols preceded it, and are the ones
3125 just recovered from the context stack. Defined the block for them.
3127 If this is the outermost LBRAC...RBRAC pair, there is no
3128 need to do anything; leave the symbols that preceded it
3129 to be attached to the function's own block. However, if
3130 it is so, we need to indicate that we just moved outside
3133 && (context_stack_depth
3134 > !VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
)))
3136 /* FIXME Muzzle a compiler bug that makes end < start. */
3137 if (new->start_addr
> valu
)
3139 complain(&lbrac_rbrac_complaint
, 0);
3140 new->start_addr
= valu
;
3142 /* Make a block for the local symbols within. */
3143 finish_block (0, &local_symbols
, new->old_blocks
,
3144 new->start_addr
, valu
);
3148 within_function
= 0;
3150 if (VARIABLES_INSIDE_BLOCK(desc
, processing_gcc_compilation
))
3151 /* Now pop locals of block just finished. */
3152 local_symbols
= new->locals
;
3157 /* This kind of symbol indicates the start of an object file. */
3161 /* This type of symbol indicates the start of data
3162 for one source file.
3163 Finish the symbol table of the previous source file
3164 (if any) and start accumulating a new symbol table. */
3165 #ifndef SUN_FIXED_LBRAC_BUG
3166 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
3169 #ifdef PCC_SOL_BROKEN
3170 /* pcc bug, occasionally puts out SO for SOL. */
3171 if (context_stack_depth
> 0)
3173 start_subfile (name
, NULL
);
3177 if (last_source_file
)
3178 (void)end_symtab (valu
);
3179 start_symtab (name
, NULL
, valu
);
3183 /* This type of symbol indicates the start of data for
3184 a sub-source-file, one whose contents were copied or
3185 included in the compilation of the main source file
3186 (whose name was given in the N_SO symbol.) */
3187 start_subfile (name
, NULL
);
3192 add_new_header_file (name
, valu
);
3193 start_subfile (name
, NULL
);
3197 start_subfile (pop_subfile (), NULL
);
3201 add_old_header_file (name
, valu
);
3205 /* This type of "symbol" really just records
3206 one line-number -- core-address correspondence.
3207 Enter it in the line list for this symbol table. */
3208 #ifndef SUN_FIXED_LBRAC_BUG
3209 last_pc_address
= valu
; /* Save for SunOS bug circumcision */
3211 record_line (desc
, valu
);
3216 error ("Invalid symbol data: common within common at symtab pos %d",
3218 common_block
= local_symbols
;
3219 common_block_i
= local_symbols
? local_symbols
->nsyms
: 0;
3223 /* Symbols declared since the BCOMM are to have the common block
3224 start address added in when we know it. common_block points to
3225 the first symbol after the BCOMM in the local_symbols list;
3226 copy the list and hang it off the symbol for the common block name
3230 struct symbol
*sym
=
3231 (struct symbol
*) xmalloc (sizeof (struct symbol
));
3232 bzero (sym
, sizeof *sym
);
3233 SYMBOL_NAME (sym
) = savestring (name
, strlen (name
));
3234 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3235 SYMBOL_NAMESPACE (sym
) = (enum namespace)((long)
3236 copy_pending (local_symbols
, common_block_i
, common_block
));
3237 i
= hashname (SYMBOL_NAME (sym
));
3238 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3239 global_sym_chain
[i
] = sym
;
3246 case N_DEFD
: /* GNU Modula-2 symbol */
3251 define_symbol (valu
, name
, desc
, type
);
3255 /* Read a number by which a type is referred to in dbx data,
3256 or perhaps read a pair (FILENUM, TYPENUM) in parentheses.
3257 Just a single number N is equivalent to (0,N).
3258 Return the two numbers by storing them in the vector TYPENUMS.
3259 TYPENUMS will then be used as an argument to dbx_lookup_type. */
3262 read_type_number (pp
, typenums
)
3264 register int *typenums
;
3269 typenums
[0] = read_number (pp
, ',');
3270 typenums
[1] = read_number (pp
, ')');
3275 typenums
[1] = read_number (pp
, 0);
3279 /* To handle GNU C++ typename abbreviation, we need to be able to
3280 fill in a type's name as soon as space for that type is allocated.
3281 `type_synonym_name' is the name of the type being allocated.
3282 It is cleared as soon as it is used (lest all allocated types
3284 static char *type_synonym_name
;
3287 static struct symbol
*
3288 define_symbol (valu
, string
, desc
, type
)
3294 register struct symbol
*sym
;
3295 char *p
= (char *) strchr (string
, ':');
3300 /* Ignore syms with empty names. */
3304 /* Ignore old-style symbols from cc -go */
3308 sym
= (struct symbol
*)obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
3310 if (processing_gcc_compilation
) {
3311 /* GCC 2.x puts the line number in desc. SunOS apparently puts in the
3312 number of bytes occupied by a type or object, which we ignore. */
3313 SYMBOL_LINE(sym
) = desc
;
3315 SYMBOL_LINE(sym
) = 0; /* unknown */
3318 if (string
[0] == CPLUS_MARKER
)
3320 /* Special GNU C++ names. */
3324 SYMBOL_NAME (sym
) = "this";
3326 case 'v': /* $vtbl_ptr_type */
3327 /* Was: SYMBOL_NAME (sym) = "vptr"; */
3330 SYMBOL_NAME (sym
) = "eh_throw";
3334 /* This was an anonymous type that was never fixed up. */
3345 = (char *) obstack_alloc (symbol_obstack
, ((p
- string
) + 1));
3346 /* Open-coded bcopy--saves function call time. */
3348 register char *p1
= string
;
3349 register char *p2
= SYMBOL_NAME (sym
);
3356 /* Determine the type of name being defined. */
3357 /* The Acorn RISC machine's compiler can put out locals that don't
3358 start with "234=" or "(3,4)=", so assume anything other than the
3359 deftypes we know how to handle is a local. */
3360 /* (Peter Watkins @ Computervision)
3361 Handle Sun-style local fortran array types 'ar...' .
3362 (gnu@cygnus.com) -- this strchr() handles them properly?
3363 (tiemann@cygnus.com) -- 'C' is for catch. */
3364 if (!strchr ("cfFGpPrStTvVXC", *p
))
3369 /* c is a special case, not followed by a type-number.
3370 SYMBOL:c=iVALUE for an integer constant symbol.
3371 SYMBOL:c=rVALUE for a floating constant symbol.
3372 SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3373 e.g. "b:c=e6,0" for "const b = blob1"
3374 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3378 error ("Invalid symbol data at symtab pos %d.", symnum
);
3383 double d
= atof (p
);
3386 SYMBOL_TYPE (sym
) = builtin_type_double
;
3388 (char *) obstack_alloc (symbol_obstack
, sizeof (double));
3389 bcopy (&d
, dbl_valu
, sizeof (double));
3390 SWAP_TARGET_AND_HOST (dbl_valu
, sizeof (double));
3391 SYMBOL_VALUE_BYTES (sym
) = dbl_valu
;
3392 SYMBOL_CLASS (sym
) = LOC_CONST_BYTES
;
3397 SYMBOL_TYPE (sym
) = builtin_type_int
;
3398 SYMBOL_VALUE (sym
) = atoi (p
);
3399 SYMBOL_CLASS (sym
) = LOC_CONST
;
3403 /* SYMBOL:c=eTYPE,INTVALUE for an enum constant symbol.
3404 e.g. "b:c=e6,0" for "const b = blob1"
3405 (where type 6 is defined by "blobs:t6=eblob1:0,blob2:1,;"). */
3409 read_type_number (&p
, typenums
);
3411 error ("Invalid symbol data: no comma in enum const symbol");
3413 SYMBOL_TYPE (sym
) = *dbx_lookup_type (typenums
);
3414 SYMBOL_VALUE (sym
) = atoi (p
);
3415 SYMBOL_CLASS (sym
) = LOC_CONST
;
3419 error ("Invalid symbol data at symtab pos %d.", symnum
);
3421 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3422 add_symbol_to_list (sym
, &file_symbols
);
3426 /* Now usually comes a number that says which data type,
3427 and possibly more stuff to define the type
3428 (all of which is handled by read_type) */
3430 if (deftype
== 'p' && *p
== 'F')
3431 /* pF is a two-letter code that means a function parameter in Fortran.
3432 The type-number specifies the type of the return value.
3433 Translate it into a pointer-to-function type. */
3437 = lookup_pointer_type (lookup_function_type (read_type (&p
)));
3441 struct type
*type_read
;
3442 synonym
= *p
== 't';
3447 type_synonym_name
= obsavestring (SYMBOL_NAME (sym
),
3448 strlen (SYMBOL_NAME (sym
)));
3451 type_read
= read_type (&p
);
3453 if ((deftype
== 'F' || deftype
== 'f')
3454 && TYPE_CODE (type_read
) != TYPE_CODE_FUNC
)
3457 /* This code doesn't work -- it needs to realloc and can't. */
3458 struct type
*new = (struct type
*)
3459 obstack_alloc (symbol_obstack
, sizeof (struct type
));
3461 /* Generate a template for the type of this function. The
3462 types of the arguments will be added as we read the symbol
3464 *new = *lookup_function_type (type_read
);
3465 SYMBOL_TYPE(sym
) = new;
3466 in_function_type
= new;
3468 SYMBOL_TYPE (sym
) = lookup_function_type (type_read
);
3472 SYMBOL_TYPE (sym
) = type_read
;
3478 /* The name of a caught exception. */
3479 SYMBOL_CLASS (sym
) = LOC_LABEL
;
3480 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3481 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
3482 add_symbol_to_list (sym
, &local_symbols
);
3486 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3487 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3488 add_symbol_to_list (sym
, &file_symbols
);
3492 SYMBOL_CLASS (sym
) = LOC_BLOCK
;
3493 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3494 add_symbol_to_list (sym
, &global_symbols
);
3498 /* For a class G (global) symbol, it appears that the
3499 value is not correct. It is necessary to search for the
3500 corresponding linker definition to find the value.
3501 These definitions appear at the end of the namelist. */
3502 i
= hashname (SYMBOL_NAME (sym
));
3503 SYMBOL_VALUE_CHAIN (sym
) = global_sym_chain
[i
];
3504 global_sym_chain
[i
] = sym
;
3505 SYMBOL_CLASS (sym
) = LOC_STATIC
;
3506 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3507 add_symbol_to_list (sym
, &global_symbols
);
3510 /* This case is faked by a conditional above,
3511 when there is no code letter in the dbx data.
3512 Dbx data never actually contains 'l'. */
3514 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
3515 SYMBOL_VALUE (sym
) = valu
;
3516 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3517 add_symbol_to_list (sym
, &local_symbols
);
3521 /* Normally this is a parameter, a LOC_ARG. On the i960, it
3522 can also be a LOC_LOCAL_ARG depending on symbol type. */
3523 #ifndef DBX_PARM_SYMBOL_CLASS
3524 #define DBX_PARM_SYMBOL_CLASS(type) LOC_ARG
3526 SYMBOL_CLASS (sym
) = DBX_PARM_SYMBOL_CLASS (type
);
3527 SYMBOL_VALUE (sym
) = valu
;
3528 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3530 /* This doesn't work yet. */
3531 add_param_to_type (&in_function_type
, sym
);
3533 add_symbol_to_list (sym
, &local_symbols
);
3535 /* If it's gcc-compiled, if it says `short', believe it. */
3536 if (processing_gcc_compilation
|| BELIEVE_PCC_PROMOTION
)
3539 #if defined(BELIEVE_PCC_PROMOTION_TYPE)
3540 /* This macro is defined on machines (e.g. sparc) where
3541 we should believe the type of a PCC 'short' argument,
3542 but shouldn't believe the address (the address is
3543 the address of the corresponding int). Note that
3544 this is only different from the BELIEVE_PCC_PROMOTION
3545 case on big-endian machines.
3547 My guess is that this correction, as opposed to changing
3548 the parameter to an 'int' (as done below, for PCC
3549 on most machines), is the right thing to do
3550 on all machines, but I don't want to risk breaking
3551 something that already works. On most PCC machines,
3552 the sparc problem doesn't come up because the calling
3553 function has to zero the top bytes (not knowing whether
3554 the called function wants an int or a short), so there
3555 is no practical difference between an int and a short
3556 (except perhaps what happens when the GDB user types
3557 "print short_arg = 0x10000;").
3559 Hacked for SunOS 4.1 by gnu@cygnus.com. In 4.1, the compiler
3560 actually produces the correct address (we don't need to fix it
3561 up). I made this code adapt so that it will offset the symbol
3562 if it was pointing at an int-aligned location and not
3563 otherwise. This way you can use the same gdb for 4.0.x and
3566 if (0 == SYMBOL_VALUE (sym
) % sizeof (int))
3568 if (SYMBOL_TYPE (sym
) == builtin_type_char
3569 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
)
3570 SYMBOL_VALUE (sym
) += 3;
3571 else if (SYMBOL_TYPE (sym
) == builtin_type_short
3572 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
3573 SYMBOL_VALUE (sym
) += 2;
3577 #else /* no BELIEVE_PCC_PROMOTION_TYPE. */
3579 /* If PCC says a parameter is a short or a char,
3580 it is really an int. */
3581 if (SYMBOL_TYPE (sym
) == builtin_type_char
3582 || SYMBOL_TYPE (sym
) == builtin_type_short
)
3583 SYMBOL_TYPE (sym
) = builtin_type_int
;
3584 else if (SYMBOL_TYPE (sym
) == builtin_type_unsigned_char
3585 || SYMBOL_TYPE (sym
) == builtin_type_unsigned_short
)
3586 SYMBOL_TYPE (sym
) = builtin_type_unsigned_int
;
3589 #endif /* no BELIEVE_PCC_PROMOTION_TYPE. */
3592 SYMBOL_CLASS (sym
) = LOC_REGPARM
;
3593 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
3594 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3595 add_symbol_to_list (sym
, &local_symbols
);
3599 SYMBOL_CLASS (sym
) = LOC_REGISTER
;
3600 SYMBOL_VALUE (sym
) = STAB_REG_TO_REGNUM (valu
);
3601 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3602 add_symbol_to_list (sym
, &local_symbols
);
3606 /* Static symbol at top level of file */
3607 SYMBOL_CLASS (sym
) = LOC_STATIC
;
3608 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
3609 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3610 add_symbol_to_list (sym
, &file_symbols
);
3614 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
3615 SYMBOL_VALUE (sym
) = valu
;
3616 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3617 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
3618 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
3619 TYPE_NAME (SYMBOL_TYPE (sym
)) =
3620 obsavestring (SYMBOL_NAME (sym
),
3621 strlen (SYMBOL_NAME (sym
)));
3622 /* C++ vagaries: we may have a type which is derived from
3623 a base type which did not have its name defined when the
3624 derived class was output. We fill in the derived class's
3625 base part member's name here in that case. */
3626 else if ((TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
3627 || TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_UNION
)
3628 && TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)))
3631 for (j
= TYPE_N_BASECLASSES (SYMBOL_TYPE (sym
)) - 1; j
>= 0; j
--)
3632 if (TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) == 0)
3633 TYPE_BASECLASS_NAME (SYMBOL_TYPE (sym
), j
) =
3634 type_name_no_tag (TYPE_BASECLASS (SYMBOL_TYPE (sym
), j
));
3637 add_symbol_to_list (sym
, &file_symbols
);
3641 SYMBOL_CLASS (sym
) = LOC_TYPEDEF
;
3642 SYMBOL_VALUE (sym
) = valu
;
3643 SYMBOL_NAMESPACE (sym
) = STRUCT_NAMESPACE
;
3644 if (TYPE_NAME (SYMBOL_TYPE (sym
)) == 0
3645 && (TYPE_FLAGS (SYMBOL_TYPE (sym
)) & TYPE_FLAG_PERM
) == 0)
3646 TYPE_NAME (SYMBOL_TYPE (sym
))
3648 (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_ENUM
3650 : (TYPE_CODE (SYMBOL_TYPE (sym
)) == TYPE_CODE_STRUCT
3651 ? "struct " : "union ")),
3653 add_symbol_to_list (sym
, &file_symbols
);
3657 register struct symbol
*typedef_sym
3658 = (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
3659 SYMBOL_NAME (typedef_sym
) = SYMBOL_NAME (sym
);
3660 SYMBOL_TYPE (typedef_sym
) = SYMBOL_TYPE (sym
);
3662 SYMBOL_CLASS (typedef_sym
) = LOC_TYPEDEF
;
3663 SYMBOL_VALUE (typedef_sym
) = valu
;
3664 SYMBOL_NAMESPACE (typedef_sym
) = VAR_NAMESPACE
;
3665 add_symbol_to_list (typedef_sym
, &file_symbols
);
3670 /* Static symbol of local scope */
3671 SYMBOL_CLASS (sym
) = LOC_STATIC
;
3672 SYMBOL_VALUE_ADDRESS (sym
) = valu
;
3673 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3674 add_symbol_to_list (sym
, &local_symbols
);
3678 /* Reference parameter */
3679 SYMBOL_CLASS (sym
) = LOC_REF_ARG
;
3680 SYMBOL_VALUE (sym
) = valu
;
3681 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3682 add_symbol_to_list (sym
, &local_symbols
);
3686 /* This is used by Sun FORTRAN for "function result value".
3687 Sun claims ("dbx and dbxtool interfaces", 2nd ed)
3688 that Pascal uses it too, but when I tried it Pascal used
3689 "x:3" (local symbol) instead. */
3690 SYMBOL_CLASS (sym
) = LOC_LOCAL
;
3691 SYMBOL_VALUE (sym
) = valu
;
3692 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
3693 add_symbol_to_list (sym
, &local_symbols
);
3697 error ("Invalid symbol data: unknown symbol-type code `%c' at symtab pos %d.", deftype
, symnum
);
3702 /* What about types defined as forward references inside of a small lexical
3704 /* Add a type to the list of undefined types to be checked through
3705 once this file has been read in. */
3707 add_undefined_type (type
)
3710 if (undef_types_length
== undef_types_allocated
)
3712 undef_types_allocated
*= 2;
3713 undef_types
= (struct type
**)
3714 xrealloc (undef_types
,
3715 undef_types_allocated
* sizeof (struct type
*));
3717 undef_types
[undef_types_length
++] = type
;
3720 /* Add here something to go through each undefined type, see if it's
3721 still undefined, and do a full lookup if so. */
3723 cleanup_undefined_types ()
3727 for (type
= undef_types
; type
< undef_types
+ undef_types_length
; type
++)
3729 /* Reasonable test to see if it's been defined since. */
3730 if (TYPE_NFIELDS (*type
) == 0)
3732 struct pending
*ppt
;
3734 /* Name of the type, without "struct" or "union" */
3735 char *typename
= TYPE_NAME (*type
);
3737 if (!strncmp (typename
, "struct ", 7))
3739 if (!strncmp (typename
, "union ", 6))
3742 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3743 for (i
= 0; i
< ppt
->nsyms
; i
++)
3745 struct symbol
*sym
= ppt
->symbol
[i
];
3747 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3748 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3749 && (TYPE_CODE (SYMBOL_TYPE (sym
)) ==
3751 && !strcmp (SYMBOL_NAME (sym
), typename
))
3752 bcopy (SYMBOL_TYPE (sym
), *type
, sizeof (struct type
));
3756 /* It has been defined; don't mark it as a stub. */
3757 TYPE_FLAGS (*type
) &= ~TYPE_FLAG_STUB
;
3759 undef_types_length
= 0;
3762 /* Skip rest of this symbol and return an error type.
3764 General notes on error recovery: error_type always skips to the
3765 end of the symbol (modulo cretinous dbx symbol name continuation).
3766 Thus code like this:
3768 if (*(*pp)++ != ';')
3769 return error_type (pp);
3771 is wrong because if *pp starts out pointing at '\0' (typically as the
3772 result of an earlier error), it will be incremented to point to the
3773 start of the next symbol, which might produce strange results, at least
3774 if you run off the end of the string table. Instead use
3777 return error_type (pp);
3783 foo = error_type (pp);
3787 And in case it isn't obvious, the point of all this hair is so the compiler
3788 can define new types and new syntaxes, and old versions of the
3789 debugger will be able to read the new symbol tables. */
3791 static struct type
*
3795 complain (&error_type_complaint
, 0);
3798 /* Skip to end of symbol. */
3799 while (**pp
!= '\0')
3802 /* Check for and handle cretinous dbx symbol name continuation! */
3803 if ((*pp
)[-1] == '\\')
3804 *pp
= next_symbol_text ();
3808 return builtin_type_error
;
3811 /* Read a dbx type reference or definition;
3812 return the type that is meant.
3813 This can be just a number, in which case it references
3814 a type already defined and placed in type_vector.
3815 Or the number can be followed by an =, in which case
3816 it means to define a new type according to the text that
3824 register struct type
*type
= 0;
3829 /* Read type number if present. The type number may be omitted.
3830 for instance in a two-dimensional array declared with type
3831 "ar1;1;10;ar1;1;10;4". */
3832 if ((**pp
>= '0' && **pp
<= '9')
3835 read_type_number (pp
, typenums
);
3837 /* Detect random reference to type not yet defined.
3838 Allocate a type object but leave it zeroed. */
3840 return dbx_alloc_type (typenums
);
3846 /* 'typenums=' not present, type is anonymous. Read and return
3847 the definition, but don't put it in the type vector. */
3848 typenums
[0] = typenums
[1] = -1;
3856 enum type_code code
;
3858 /* Used to index through file_symbols. */
3859 struct pending
*ppt
;
3862 /* Name including "struct", etc. */
3865 /* Name without "struct", etc. */
3866 char *type_name_only
;
3872 /* Set the type code according to the following letter. */
3876 code
= TYPE_CODE_STRUCT
;
3880 code
= TYPE_CODE_UNION
;
3884 code
= TYPE_CODE_ENUM
;
3888 return error_type (pp
);
3891 to
= type_name
= (char *)
3892 obstack_alloc (symbol_obstack
,
3894 ((char *) strchr (*pp
, ':') - (*pp
)) + 1));
3896 /* Copy the prefix. */
3898 while (*to
++ = *from
++)
3902 type_name_only
= to
;
3904 /* Copy the name. */
3906 while ((*to
++ = *from
++) != ':')
3910 /* Set the pointer ahead of the name which we just read. */
3914 /* The following hack is clearly wrong, because it doesn't
3915 check whether we are in a baseclass. I tried to reproduce
3916 the case that it is trying to fix, but I couldn't get
3917 g++ to put out a cross reference to a basetype. Perhaps
3918 it doesn't do it anymore. */
3919 /* Note: for C++, the cross reference may be to a base type which
3920 has not yet been seen. In this case, we skip to the comma,
3921 which will mark the end of the base class name. (The ':'
3922 at the end of the base class name will be skipped as well.)
3923 But sometimes (ie. when the cross ref is the last thing on
3924 the line) there will be no ','. */
3925 from
= (char *) strchr (*pp
, ',');
3931 /* Now check to see whether the type has already been declared. */
3932 /* This is necessary at least in the case where the
3933 program says something like
3935 The compiler puts out a cross-reference; we better find
3936 set the length of the structure correctly so we can
3937 set the length of the array. */
3938 for (ppt
= file_symbols
; ppt
; ppt
= ppt
->next
)
3939 for (i
= 0; i
< ppt
->nsyms
; i
++)
3941 struct symbol
*sym
= ppt
->symbol
[i
];
3943 if (SYMBOL_CLASS (sym
) == LOC_TYPEDEF
3944 && SYMBOL_NAMESPACE (sym
) == STRUCT_NAMESPACE
3945 && (TYPE_CODE (SYMBOL_TYPE (sym
)) == code
)
3946 && !strcmp (SYMBOL_NAME (sym
), type_name_only
))
3948 obstack_free (symbol_obstack
, type_name
);
3949 type
= SYMBOL_TYPE (sym
);
3954 /* Didn't find the type to which this refers, so we must
3955 be dealing with a forward reference. Allocate a type
3956 structure for it, and keep track of it so we can
3957 fill in the rest of the fields when we get the full
3959 type
= dbx_alloc_type (typenums
);
3960 TYPE_CODE (type
) = code
;
3961 TYPE_NAME (type
) = type_name
;
3963 TYPE_FLAGS (type
) |= TYPE_FLAG_STUB
;
3965 add_undefined_type (type
);
3981 read_type_number (pp
, xtypenums
);
3982 type
= *dbx_lookup_type (xtypenums
);
3984 type
= builtin_type_void
;
3985 if (typenums
[0] != -1)
3986 *dbx_lookup_type (typenums
) = type
;
3990 type1
= read_type (pp
);
3991 type
= lookup_pointer_type (type1
);
3992 if (typenums
[0] != -1)
3993 *dbx_lookup_type (typenums
) = type
;
3998 struct type
*domain
= read_type (pp
);
3999 struct type
*memtype
;
4002 /* Invalid member type data format. */
4003 return error_type (pp
);
4006 memtype
= read_type (pp
);
4007 type
= dbx_alloc_type (typenums
);
4008 smash_to_member_type (type
, domain
, memtype
);
4013 if ((*pp
)[0] == '#')
4015 /* We'll get the parameter types from the name. */
4016 struct type
*return_type
;
4019 return_type
= read_type (pp
);
4020 if (*(*pp
)++ != ';')
4021 complain (&invalid_member_complaint
, symnum
);
4022 type
= allocate_stub_method (return_type
);
4023 if (typenums
[0] != -1)
4024 *dbx_lookup_type (typenums
) = type
;
4028 struct type
*domain
= read_type (pp
);
4029 struct type
*return_type
;
4032 if (*(*pp
)++ != ',')
4033 error ("invalid member type data format, at symtab pos %d.",
4036 return_type
= read_type (pp
);
4037 args
= read_args (pp
, ';');
4038 type
= dbx_alloc_type (typenums
);
4039 smash_to_method_type (type
, domain
, return_type
, args
);
4044 type1
= read_type (pp
);
4045 type
= lookup_reference_type (type1
);
4046 if (typenums
[0] != -1)
4047 *dbx_lookup_type (typenums
) = type
;
4051 type1
= read_type (pp
);
4052 type
= lookup_function_type (type1
);
4053 if (typenums
[0] != -1)
4054 *dbx_lookup_type (typenums
) = type
;
4058 type
= read_range_type (pp
, typenums
);
4059 if (typenums
[0] != -1)
4060 *dbx_lookup_type (typenums
) = type
;
4064 type
= dbx_alloc_type (typenums
);
4065 type
= read_enum_type (pp
, type
);
4066 *dbx_lookup_type (typenums
) = type
;
4070 type
= dbx_alloc_type (typenums
);
4071 TYPE_NAME (type
) = type_synonym_name
;
4072 type_synonym_name
= 0;
4073 type
= read_struct_type (pp
, type
);
4077 type
= dbx_alloc_type (typenums
);
4078 TYPE_NAME (type
) = type_synonym_name
;
4079 type_synonym_name
= 0;
4080 type
= read_struct_type (pp
, type
);
4081 TYPE_CODE (type
) = TYPE_CODE_UNION
;
4086 return error_type (pp
);
4089 type
= dbx_alloc_type (typenums
);
4090 type
= read_array_type (pp
, type
);
4094 --*pp
; /* Go back to the symbol in error */
4095 /* Particularly important if it was \0! */
4096 return error_type (pp
);
4103 /* If this is an overriding temporary alteration for a header file's
4104 contents, and this type number is unknown in the global definition,
4105 put this type into the global definition at this type number. */
4106 if (header_file_prev_index
>= 0)
4108 register struct type
**tp
4109 = explicit_lookup_type (header_file_prev_index
, typenums
[1]);
4118 /* This would be a good idea, but it doesn't really work. The problem
4119 is that in order to get the virtual context for a particular type,
4120 you need to know the virtual info from all of its basetypes,
4121 and you need to have processed its methods. Since GDB reads
4122 symbols on a file-by-file basis, this means processing the symbols
4123 of all the files that are needed for each baseclass, which
4124 means potentially reading in all the debugging info just to fill
4125 in information we may never need. */
4127 /* This page contains subroutines of read_type. */
4129 /* FOR_TYPE is a struct type defining a virtual function NAME with type
4130 FN_TYPE. The `virtual context' for this virtual function is the
4131 first base class of FOR_TYPE in which NAME is defined with signature
4132 matching FN_TYPE. OFFSET serves as a hash on matches here.
4134 TYPE is the current type in which we are searching. */
4136 static struct type
*
4137 virtual_context (for_type
, type
, name
, fn_type
, offset
)
4138 struct type
*for_type
, *type
;
4140 struct type
*fn_type
;
4143 struct type
*basetype
= 0;
4146 if (for_type
!= type
)
4148 /* Check the methods of TYPE. */
4149 /* Need to do a check_stub_type here, but that breaks
4150 things because we can get infinite regress. */
4151 for (i
= TYPE_NFN_FIELDS (type
) - 1; i
>= 0; --i
)
4152 if (!strcmp (TYPE_FN_FIELDLIST_NAME (type
, i
), name
))
4156 int j
= TYPE_FN_FIELDLIST_LENGTH (type
, i
);
4157 struct fn_field
*f
= TYPE_FN_FIELDLIST1 (type
, i
);
4160 if (TYPE_FN_FIELD_VOFFSET (f
, j
) == offset
-1)
4161 return TYPE_FN_FIELD_FCONTEXT (f
, j
);
4164 for (i
= TYPE_N_BASECLASSES (type
) - 1; i
>= 0; i
--)
4166 basetype
= virtual_context (for_type
, TYPE_BASECLASS (type
, i
), name
,
4168 if (basetype
!= for_type
)
4175 /* Read the description of a structure (or union type)
4176 and return an object describing the type. */
4178 static struct type
*
4179 read_struct_type (pp
, type
)
4181 register struct type
*type
;
4183 /* Total number of methods defined in this class.
4184 If the class defines two `f' methods, and one `g' method,
4185 then this will have the value 3. */
4186 int total_length
= 0;
4190 struct nextfield
*next
;
4191 int visibility
; /* 0=public, 1=protected, 2=public */
4197 struct next_fnfield
*next
;
4198 int visibility
; /* 0=public, 1=protected, 2=public */
4199 struct fn_field fn_field
;
4202 struct next_fnfieldlist
4204 struct next_fnfieldlist
*next
;
4205 struct fn_fieldlist fn_fieldlist
;
4208 register struct nextfield
*list
= 0;
4209 struct nextfield
*new;
4214 register struct next_fnfieldlist
*mainlist
= 0;
4217 if (TYPE_MAIN_VARIANT (type
) == 0)
4219 TYPE_MAIN_VARIANT (type
) = type
;
4222 TYPE_CODE (type
) = TYPE_CODE_STRUCT
;
4224 /* First comes the total size in bytes. */
4226 TYPE_LENGTH (type
) = read_number (pp
, 0);
4228 /* C++: Now, if the class is a derived class, then the next character
4229 will be a '!', followed by the number of base classes derived from.
4230 Each element in the list contains visibility information,
4231 the offset of this base class in the derived structure,
4232 and then the base type. */
4235 int i
, n_baseclasses
, offset
;
4236 struct type
*baseclass
;
4239 /* Nonzero if it is a virtual baseclass, i.e.,
4243 struct C : public B, public virtual A {};
4245 B is a baseclass of C; A is a virtual baseclass for C. This is a C++
4246 2.0 language feature. */
4251 n_baseclasses
= read_number (pp
, ',');
4252 TYPE_FIELD_VIRTUAL_BITS (type
) =
4253 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (n_baseclasses
));
4254 B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type
), n_baseclasses
);
4256 for (i
= 0; i
< n_baseclasses
; i
++)
4259 *pp
= next_symbol_text ();
4270 /* Bad visibility format. */
4271 return error_type (pp
);
4284 /* Bad visibility format. */
4285 return error_type (pp
);
4288 SET_TYPE_FIELD_VIRTUAL (type
, i
);
4291 /* Offset of the portion of the object corresponding to
4292 this baseclass. Always zero in the absence of
4293 multiple inheritance. */
4294 offset
= read_number (pp
, ',');
4295 baseclass
= read_type (pp
);
4296 *pp
+= 1; /* skip trailing ';' */
4298 /* Make this baseclass visible for structure-printing purposes. */
4299 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
4302 list
->visibility
= via_public
;
4303 list
->field
.type
= baseclass
;
4304 list
->field
.name
= type_name_no_tag (baseclass
);
4305 list
->field
.bitpos
= offset
;
4306 list
->field
.bitsize
= 0; /* this should be an unpacked field! */
4309 TYPE_N_BASECLASSES (type
) = n_baseclasses
;
4312 /* Now come the fields, as NAME:?TYPENUM,BITPOS,BITSIZE; for each one.
4313 At the end, we see a semicolon instead of a field.
4315 In C++, this may wind up being NAME:?TYPENUM:PHYSNAME; for
4318 The `?' is a placeholder for one of '/2' (public visibility),
4319 '/1' (protected visibility), '/0' (private visibility), or nothing
4320 (C style symbol table, public visibility). */
4322 /* We better set p right now, in case there are no fields at all... */
4327 /* Check for and handle cretinous dbx symbol name continuation! */
4328 if (**pp
== '\\') *pp
= next_symbol_text ();
4330 /* Get space to record the next field's data. */
4331 new = (struct nextfield
*) alloca (sizeof (struct nextfield
));
4335 /* Get the field name. */
4337 if (*p
== CPLUS_MARKER
)
4339 /* Special GNU C++ name. */
4344 struct type
*context
;
4355 error ("invalid abbreviation at symtab pos %d.", symnum
);
4358 context
= read_type (pp
);
4359 if (type_name_no_tag (context
) == 0)
4362 error ("type name unknown at symtab pos %d.", symnum
);
4363 /* FIXME-tiemann: when is `name' ever non-0? */
4364 TYPE_NAME (context
) = obsavestring (name
, p
- name
- 1);
4366 list
->field
.name
= obconcat (prefix
, type_name_no_tag (context
), "");
4369 error ("invalid abbreviation at symtab pos %d.", symnum
);
4370 list
->field
.type
= read_type (pp
);
4371 (*pp
)++; /* Skip the comma. */
4372 list
->field
.bitpos
= read_number (pp
, ';');
4373 /* This field is unpacked. */
4374 list
->field
.bitsize
= 0;
4376 /* GNU C++ anonymous type. */
4380 error ("invalid abbreviation at symtab pos %d.", symnum
);
4386 while (*p
!= ':') p
++;
4387 list
->field
.name
= obsavestring (*pp
, p
- *pp
);
4389 /* C++: Check to see if we have hit the methods yet. */
4395 /* This means we have a visibility for a field coming. */
4401 list
->visibility
= 0; /* private */
4406 list
->visibility
= 1; /* protected */
4411 list
->visibility
= 2; /* public */
4416 else /* normal dbx-style format. */
4417 list
->visibility
= 2; /* public */
4419 list
->field
.type
= read_type (pp
);
4422 /* Static class member. */
4423 list
->field
.bitpos
= (long)-1;
4425 while (*p
!= ';') p
++;
4426 list
->field
.bitsize
= (long) savestring (*pp
, p
- *pp
);
4431 else if (**pp
!= ',')
4432 /* Bad structure-type format. */
4433 return error_type (pp
);
4435 (*pp
)++; /* Skip the comma. */
4436 list
->field
.bitpos
= read_number (pp
, ',');
4437 list
->field
.bitsize
= read_number (pp
, ';');
4440 /* FIXME-tiemann: Can't the compiler put out something which
4441 lets us distinguish these? (or maybe just not put out anything
4442 for the field). What is the story here? What does the compiler
4443 really do? Also, patch gdb.texinfo for this case; I document
4444 it as a possible problem there. Search for "DBX-style". */
4446 /* This is wrong because this is identical to the symbols
4447 produced for GCC 0-size arrays. For example:
4452 The code which dumped core in such circumstances should be
4453 fixed not to dump core. */
4455 /* g++ -g0 can put out bitpos & bitsize zero for a static
4456 field. This does not give us any way of getting its
4457 class, so we can't know its name. But we can just
4458 ignore the field so we don't dump core and other nasty
4460 if (list
->field
.bitpos
== 0
4461 && list
->field
.bitsize
== 0)
4463 complain (&dbx_class_complaint
, 0);
4464 /* Ignore this field. */
4470 /* Detect an unpacked field and mark it as such.
4471 dbx gives a bit size for all fields.
4472 Note that forward refs cannot be packed,
4473 and treat enums as if they had the width of ints. */
4474 if (TYPE_CODE (list
->field
.type
) != TYPE_CODE_INT
4475 && TYPE_CODE (list
->field
.type
) != TYPE_CODE_ENUM
)
4476 list
->field
.bitsize
= 0;
4477 if ((list
->field
.bitsize
== 8 * TYPE_LENGTH (list
->field
.type
)
4478 || (TYPE_CODE (list
->field
.type
) == TYPE_CODE_ENUM
4479 && (list
->field
.bitsize
4480 == 8 * TYPE_LENGTH (builtin_type_int
))
4484 list
->field
.bitpos
% 8 == 0)
4485 list
->field
.bitsize
= 0;
4491 /* chill the list of fields: the last entry (at the head)
4492 is a partially constructed entry which we now scrub. */
4495 /* Now create the vector of fields, and record how big it is.
4496 We need this info to record proper virtual function table information
4497 for this class's virtual functions. */
4499 TYPE_NFIELDS (type
) = nfields
;
4500 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
,
4501 sizeof (struct field
) * nfields
);
4503 TYPE_FIELD_PRIVATE_BITS (type
) =
4504 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
4505 B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type
), nfields
);
4507 TYPE_FIELD_PROTECTED_BITS (type
) =
4508 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (nfields
));
4509 B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type
), nfields
);
4511 /* Copy the saved-up fields into the field vector. */
4513 for (n
= nfields
; list
; list
= list
->next
)
4516 TYPE_FIELD (type
, n
) = list
->field
;
4517 if (list
->visibility
== 0)
4518 SET_TYPE_FIELD_PRIVATE (type
, n
);
4519 else if (list
->visibility
== 1)
4520 SET_TYPE_FIELD_PROTECTED (type
, n
);
4523 /* Now come the method fields, as NAME::methods
4524 where each method is of the form TYPENUM,ARGS,...:PHYSNAME;
4525 At the end, we see a semicolon instead of a field.
4527 For the case of overloaded operators, the format is
4528 OPERATOR::*.methods, where OPERATOR is the string "operator",
4529 `*' holds the place for an operator name (such as `+=')
4530 and `.' marks the end of the operator name. */
4533 /* Now, read in the methods. To simplify matters, we
4534 "unread" the name that has been read, so that we can
4535 start from the top. */
4537 /* For each list of method lists... */
4541 struct next_fnfield
*sublist
= 0;
4542 struct type
*look_ahead_type
= NULL
;
4544 struct next_fnfieldlist
*new_mainlist
=
4545 (struct next_fnfieldlist
*)alloca (sizeof (struct next_fnfieldlist
));
4550 /* read in the name. */
4551 while (*p
!= ':') p
++;
4552 if ((*pp
)[0] == 'o' && (*pp
)[1] == 'p' && (*pp
)[2] == CPLUS_MARKER
)
4554 /* This lets the user type "break operator+".
4555 We could just put in "+" as the name, but that wouldn't
4557 static char opname
[32] = {'o', 'p', CPLUS_MARKER
};
4558 char *o
= opname
+ 3;
4560 /* Skip past '::'. */
4564 main_fn_name
= savestring (opname
, o
- opname
);
4571 main_fn_name
= savestring (*pp
, p
- *pp
);
4572 /* Skip past '::'. */
4575 new_mainlist
->fn_fieldlist
.name
= main_fn_name
;
4579 struct next_fnfield
*new_sublist
=
4580 (struct next_fnfield
*)alloca (sizeof (struct next_fnfield
));
4582 /* Check for and handle cretinous dbx symbol name continuation! */
4583 if (look_ahead_type
== NULL
) /* Normal case. */
4585 if (**pp
== '\\') *pp
= next_symbol_text ();
4587 new_sublist
->fn_field
.type
= read_type (pp
);
4589 /* Invalid symtab info for method. */
4590 return error_type (pp
);
4593 { /* g++ version 1 kludge */
4594 new_sublist
->fn_field
.type
= look_ahead_type
;
4595 look_ahead_type
= NULL
;
4600 while (*p
!= ';') p
++;
4601 /* If this is just a stub, then we don't have the
4603 new_sublist
->fn_field
.physname
= savestring (*pp
, p
- *pp
);
4605 new_sublist
->visibility
= *(*pp
)++ - '0';
4606 if (**pp
== '\\') *pp
= next_symbol_text ();
4607 /* FIXME-tiemann: need to add const/volatile info
4608 to the methods. For now, just skip the char.
4609 In future, here's what we need to implement:
4611 A for normal functions.
4612 B for `const' member functions.
4613 C for `volatile' member functions.
4614 D for `const volatile' member functions. */
4615 if (**pp
== 'A' || **pp
== 'B' || **pp
== 'C' || **pp
== 'D')
4618 /* This probably just means we're processing a file compiled
4619 with g++ version 1. */
4621 complain(&const_vol_complaint
, **pp
);
4626 /* virtual member function, followed by index. */
4627 /* The sign bit is set to distinguish pointers-to-methods
4628 from virtual function indicies. Since the array is
4629 in words, the quantity must be shifted left by 1
4630 on 16 bit machine, and by 2 on 32 bit machine, forcing
4631 the sign bit out, and usable as a valid index into
4632 the array. Remove the sign bit here. */
4633 new_sublist
->fn_field
.voffset
=
4634 (0x7fffffff & read_number (pp
, ';')) + 1;
4636 if (**pp
== '\\') *pp
= next_symbol_text ();
4638 if (**pp
== ';' || **pp
== '\0')
4639 /* Must be g++ version 1. */
4640 new_sublist
->fn_field
.fcontext
= 0;
4643 /* Figure out from whence this virtual function came.
4644 It may belong to virtual function table of
4645 one of its baseclasses. */
4646 look_ahead_type
= read_type (pp
);
4648 { /* g++ version 1 overloaded methods. */ }
4651 new_sublist
->fn_field
.fcontext
= look_ahead_type
;
4653 return error_type (pp
);
4656 look_ahead_type
= NULL
;
4662 /* static member function. */
4663 new_sublist
->fn_field
.voffset
= VOFFSET_STATIC
;
4667 /* normal member function. */
4668 new_sublist
->fn_field
.voffset
= 0;
4669 new_sublist
->fn_field
.fcontext
= 0;
4673 new_sublist
->next
= sublist
;
4674 sublist
= new_sublist
;
4677 while (**pp
!= ';' && **pp
!= '\0');
4681 new_mainlist
->fn_fieldlist
.fn_fields
=
4682 (struct fn_field
*) obstack_alloc (symbol_obstack
,
4683 sizeof (struct fn_field
) * length
);
4684 TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
) =
4685 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
4686 B_CLRALL (TYPE_FN_PRIVATE_BITS (new_mainlist
->fn_fieldlist
), length
);
4688 TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
) =
4689 (B_TYPE
*) obstack_alloc (symbol_obstack
, B_BYTES (length
));
4690 B_CLRALL (TYPE_FN_PROTECTED_BITS (new_mainlist
->fn_fieldlist
), length
);
4692 for (i
= length
; (i
--, sublist
); sublist
= sublist
->next
)
4694 new_mainlist
->fn_fieldlist
.fn_fields
[i
] = sublist
->fn_field
;
4695 if (sublist
->visibility
== 0)
4696 B_SET (new_mainlist
->fn_fieldlist
.private_fn_field_bits
, i
);
4697 else if (sublist
->visibility
== 1)
4698 B_SET (new_mainlist
->fn_fieldlist
.protected_fn_field_bits
, i
);
4701 new_mainlist
->fn_fieldlist
.length
= length
;
4702 new_mainlist
->next
= mainlist
;
4703 mainlist
= new_mainlist
;
4705 total_length
+= length
;
4707 while (**pp
!= ';');
4712 TYPE_FN_FIELDLISTS (type
) =
4713 (struct fn_fieldlist
*) obstack_alloc (symbol_obstack
,
4714 sizeof (struct fn_fieldlist
) * nfn_fields
);
4716 TYPE_NFN_FIELDS (type
) = nfn_fields
;
4717 TYPE_NFN_FIELDS_TOTAL (type
) = total_length
;
4721 for (i
= 0; i
< TYPE_N_BASECLASSES (type
); ++i
)
4722 TYPE_NFN_FIELDS_TOTAL (type
) +=
4723 TYPE_NFN_FIELDS_TOTAL (TYPE_BASECLASS (type
, i
));
4726 for (n
= nfn_fields
; mainlist
; mainlist
= mainlist
->next
)
4727 TYPE_FN_FIELDLISTS (type
)[--n
] = mainlist
->fn_fieldlist
;
4736 |= TYPE_FLAG_HAS_CONSTRUCTOR
| TYPE_FLAG_HAS_DESTRUCTOR
;
4739 else if (**pp
== '+')
4741 TYPE_FLAGS (type
) |= TYPE_FLAG_HAS_CONSTRUCTOR
;
4744 else if (**pp
== '-')
4746 TYPE_FLAGS (type
) |= TYPE_FLAG_HAS_DESTRUCTOR
;
4750 /* Read either a '%' or the final ';'. */
4751 if (*(*pp
)++ == '%')
4753 /* Now we must record the virtual function table pointer's
4754 field information. */
4761 while (*p
!= '\0' && *p
!= ';')
4764 /* Premature end of symbol. */
4765 return error_type (pp
);
4767 TYPE_VPTR_BASETYPE (type
) = t
;
4770 if (TYPE_FIELD_NAME (t
, TYPE_N_BASECLASSES (t
)) == 0)
4772 /* FIXME-tiemann: what's this? */
4774 TYPE_VPTR_FIELDNO (type
) = i
= TYPE_N_BASECLASSES (t
);
4779 else for (i
= TYPE_NFIELDS (t
) - 1; i
>= TYPE_N_BASECLASSES (t
); --i
)
4780 if (! strncmp (TYPE_FIELD_NAME (t
, i
), vptr_name
,
4781 sizeof (vptr_name
) -1))
4783 TYPE_VPTR_FIELDNO (type
) = i
;
4787 /* Virtual function table field not found. */
4788 return error_type (pp
);
4791 TYPE_VPTR_FIELDNO (type
) = TYPE_VPTR_FIELDNO (t
);
4799 /* Read a definition of an array type,
4800 and create and return a suitable type object.
4801 Also creates a range type which represents the bounds of that
4803 static struct type
*
4804 read_array_type (pp
, type
)
4806 register struct type
*type
;
4808 struct type
*index_type
, *element_type
, *range_type
;
4812 /* Format of an array type:
4813 "ar<index type>;lower;upper;<array_contents_type>". Put code in
4816 Fortran adjustable arrays use Adigits or Tdigits for lower or upper;
4817 for these, produce a type like float[][]. */
4819 index_type
= read_type (pp
);
4821 /* Improper format of array type decl. */
4822 return error_type (pp
);
4825 if (!(**pp
>= '0' && **pp
<= '9'))
4830 lower
= read_number (pp
, ';');
4832 if (!(**pp
>= '0' && **pp
<= '9'))
4837 upper
= read_number (pp
, ';');
4839 element_type
= read_type (pp
);
4848 /* Create range type. */
4849 range_type
= (struct type
*) obstack_alloc (symbol_obstack
,
4850 sizeof (struct type
));
4851 TYPE_CODE (range_type
) = TYPE_CODE_RANGE
;
4852 TYPE_TARGET_TYPE (range_type
) = index_type
;
4854 /* This should never be needed. */
4855 TYPE_LENGTH (range_type
) = sizeof (int);
4857 TYPE_NFIELDS (range_type
) = 2;
4858 TYPE_FIELDS (range_type
) =
4859 (struct field
*) obstack_alloc (symbol_obstack
,
4860 2 * sizeof (struct field
));
4861 TYPE_FIELD_BITPOS (range_type
, 0) = lower
;
4862 TYPE_FIELD_BITPOS (range_type
, 1) = upper
;
4865 TYPE_CODE (type
) = TYPE_CODE_ARRAY
;
4866 TYPE_TARGET_TYPE (type
) = element_type
;
4867 TYPE_LENGTH (type
) = (upper
- lower
+ 1) * TYPE_LENGTH (element_type
);
4868 TYPE_NFIELDS (type
) = 1;
4869 TYPE_FIELDS (type
) =
4870 (struct field
*) obstack_alloc (symbol_obstack
,
4871 sizeof (struct field
));
4872 TYPE_FIELD_TYPE (type
, 0) = range_type
;
4878 /* Read a definition of an enumeration type,
4879 and create and return a suitable type object.
4880 Also defines the symbols that represent the values of the type. */
4882 static struct type
*
4883 read_enum_type (pp
, type
)
4885 register struct type
*type
;
4890 register struct symbol
*sym
;
4892 struct pending
**symlist
;
4893 struct pending
*osyms
, *syms
;
4896 if (within_function
)
4897 symlist
= &local_symbols
;
4899 symlist
= &file_symbols
;
4901 o_nsyms
= osyms
? osyms
->nsyms
: 0;
4903 /* Read the value-names and their values.
4904 The input syntax is NAME:VALUE,NAME:VALUE, and so on.
4905 A semicolon or comman instead of a NAME means the end. */
4906 while (**pp
&& **pp
!= ';' && **pp
!= ',')
4908 /* Check for and handle cretinous dbx symbol name continuation! */
4909 if (**pp
== '\\') *pp
= next_symbol_text ();
4912 while (*p
!= ':') p
++;
4913 name
= obsavestring (*pp
, p
- *pp
);
4915 n
= read_number (pp
, ',');
4917 sym
= (struct symbol
*) obstack_alloc (symbol_obstack
, sizeof (struct symbol
));
4918 bzero (sym
, sizeof (struct symbol
));
4919 SYMBOL_NAME (sym
) = name
;
4920 SYMBOL_CLASS (sym
) = LOC_CONST
;
4921 SYMBOL_NAMESPACE (sym
) = VAR_NAMESPACE
;
4922 SYMBOL_VALUE (sym
) = n
;
4923 add_symbol_to_list (sym
, symlist
);
4928 (*pp
)++; /* Skip the semicolon. */
4930 /* Now fill in the fields of the type-structure. */
4932 TYPE_LENGTH (type
) = sizeof (int);
4933 TYPE_CODE (type
) = TYPE_CODE_ENUM
;
4934 TYPE_NFIELDS (type
) = nsyms
;
4935 TYPE_FIELDS (type
) = (struct field
*) obstack_alloc (symbol_obstack
, sizeof (struct field
) * nsyms
);
4937 /* Find the symbols for the values and put them into the type.
4938 The symbols can be found in the symlist that we put them on
4939 to cause them to be defined. osyms contains the old value
4940 of that symlist; everything up to there was defined by us. */
4941 /* Note that we preserve the order of the enum constants, so
4942 that in something like "enum {FOO, LAST_THING=FOO}" we print
4943 FOO, not LAST_THING. */
4945 for (syms
= *symlist
, n
= 0; syms
; syms
= syms
->next
)
4950 for (; j
< syms
->nsyms
; j
++,n
++)
4952 struct symbol
*xsym
= syms
->symbol
[j
];
4953 SYMBOL_TYPE (xsym
) = type
;
4954 TYPE_FIELD_NAME (type
, n
) = SYMBOL_NAME (xsym
);
4955 TYPE_FIELD_VALUE (type
, n
) = 0;
4956 TYPE_FIELD_BITPOS (type
, n
) = SYMBOL_VALUE (xsym
);
4957 TYPE_FIELD_BITSIZE (type
, n
) = 0;
4964 /* This screws up perfectly good C programs with enums. FIXME. */
4965 /* Is this Modula-2's BOOLEAN type? Flag it as such if so. */
4966 if(TYPE_NFIELDS(type
) == 2 &&
4967 ((!strcmp(TYPE_FIELD_NAME(type
,0),"TRUE") &&
4968 !strcmp(TYPE_FIELD_NAME(type
,1),"FALSE")) ||
4969 (!strcmp(TYPE_FIELD_NAME(type
,1),"TRUE") &&
4970 !strcmp(TYPE_FIELD_NAME(type
,0),"FALSE"))))
4971 TYPE_CODE(type
) = TYPE_CODE_BOOL
;
4977 /* Read a number from the string pointed to by *PP.
4978 The value of *PP is advanced over the number.
4979 If END is nonzero, the character that ends the
4980 number must match END, or an error happens;
4981 and that character is skipped if it does match.
4982 If END is zero, *PP is left pointing to that character.
4984 If the number fits in a long, set *VALUE and set *BITS to 0.
4985 If not, set *BITS to be the number of bits in the number.
4987 If encounter garbage, set *BITS to -1. */
4990 read_huge_number (pp
, end
, valu
, bits
)
5011 /* Leading zero means octal. GCC uses this to output values larger
5012 than an int (because that would be hard in decimal). */
5019 upper_limit
= LONG_MAX
/ radix
;
5020 while ((c
= *p
++) >= '0' && c
<= ('0' + radix
))
5022 if (n
<= upper_limit
)
5025 n
+= c
- '0'; /* FIXME this overflows anyway */
5030 /* This depends on large values being output in octal, which is
5037 /* Ignore leading zeroes. */
5041 else if (c
== '2' || c
== '3')
5067 /* Large decimal constants are an error (because it is hard to
5068 count how many bits are in them). */
5074 /* -0x7f is the same as 0x80. So deal with it by adding one to
5075 the number of bits. */
5090 #define MAX_OF_C_TYPE(t) ((1 << (sizeof (t)*8 - 1)) - 1)
5091 #define MIN_OF_C_TYPE(t) (-(1 << (sizeof (t)*8 - 1)))
5093 static struct type
*
5094 read_range_type (pp
, typenums
)
5102 struct type
*result_type
;
5104 /* First comes a type we are a subrange of.
5105 In C it is usually 0, 1 or the type being defined. */
5106 read_type_number (pp
, rangenums
);
5107 self_subrange
= (rangenums
[0] == typenums
[0] &&
5108 rangenums
[1] == typenums
[1]);
5110 /* A semicolon should now follow; skip it. */
5114 /* The remaining two operands are usually lower and upper bounds
5115 of the range. But in some special cases they mean something else. */
5116 read_huge_number (pp
, ';', &n2
, &n2bits
);
5117 read_huge_number (pp
, ';', &n3
, &n3bits
);
5119 if (n2bits
== -1 || n3bits
== -1)
5120 return error_type (pp
);
5122 /* If limits are huge, must be large integral type. */
5123 if (n2bits
!= 0 || n3bits
!= 0)
5125 char got_signed
= 0;
5126 char got_unsigned
= 0;
5127 /* Number of bits in the type. */
5130 /* Range from 0 to <large number> is an unsigned large integral type. */
5131 if ((n2bits
== 0 && n2
== 0) && n3bits
!= 0)
5136 /* Range from <large number> to <large number>-1 is a large signed
5138 else if (n2bits
!= 0 && n3bits
!= 0 && n2bits
== n3bits
+ 1)
5144 /* Check for "long long". */
5145 if (got_signed
&& nbits
== TARGET_LONG_LONG_BIT
)
5146 return builtin_type_long_long
;
5147 if (got_unsigned
&& nbits
== TARGET_LONG_LONG_BIT
)
5148 return builtin_type_unsigned_long_long
;
5150 if (got_signed
|| got_unsigned
)
5152 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
5153 sizeof (struct type
));
5154 bzero (result_type
, sizeof (struct type
));
5155 TYPE_LENGTH (result_type
) = nbits
/ TARGET_CHAR_BIT
;
5156 TYPE_MAIN_VARIANT (result_type
) = result_type
;
5157 TYPE_CODE (result_type
) = TYPE_CODE_INT
;
5159 TYPE_FLAGS (result_type
) |= TYPE_FLAG_UNSIGNED
;
5163 return error_type (pp
);
5166 /* A type defined as a subrange of itself, with bounds both 0, is void. */
5167 if (self_subrange
&& n2
== 0 && n3
== 0)
5168 return builtin_type_void
;
5170 /* If n3 is zero and n2 is not, we want a floating type,
5171 and n2 is the width in bytes.
5173 Fortran programs appear to use this for complex types also,
5174 and they give no way to distinguish between double and single-complex!
5175 We don't have complex types, so we would lose on all fortran files!
5176 So return type `double' for all of those. It won't work right
5177 for the complex values, but at least it makes the file loadable. */
5179 if (n3
== 0 && n2
> 0)
5181 if (n2
== sizeof (float))
5182 return builtin_type_float
;
5183 return builtin_type_double
;
5186 /* If the upper bound is -1, it must really be an unsigned int. */
5188 else if (n2
== 0 && n3
== -1)
5190 if (sizeof (int) == sizeof (long))
5191 return builtin_type_unsigned_int
;
5193 return builtin_type_unsigned_long
;
5196 /* Special case: char is defined (Who knows why) as a subrange of
5197 itself with range 0-127. */
5198 else if (self_subrange
&& n2
== 0 && n3
== 127)
5199 return builtin_type_char
;
5201 /* Assumptions made here: Subrange of self is equivalent to subrange
5204 && (self_subrange
||
5205 *dbx_lookup_type (rangenums
) == builtin_type_int
))
5207 /* an unsigned type */
5209 if (n3
== - sizeof (long long))
5210 return builtin_type_unsigned_long_long
;
5212 if (n3
== (unsigned int)~0L)
5213 return builtin_type_unsigned_int
;
5214 if (n3
== (unsigned long)~0L)
5215 return builtin_type_unsigned_long
;
5216 if (n3
== (unsigned short)~0L)
5217 return builtin_type_unsigned_short
;
5218 if (n3
== (unsigned char)~0L)
5219 return builtin_type_unsigned_char
;
5222 else if (n3
== 0 && n2
== -sizeof (long long))
5223 return builtin_type_long_long
;
5225 else if (n2
== -n3
-1)
5228 if (n3
== (1 << (8 * sizeof (int) - 1)) - 1)
5229 return builtin_type_int
;
5230 if (n3
== (1 << (8 * sizeof (long) - 1)) - 1)
5231 return builtin_type_long
;
5232 if (n3
== (1 << (8 * sizeof (short) - 1)) - 1)
5233 return builtin_type_short
;
5234 if (n3
== (1 << (8 * sizeof (char) - 1)) - 1)
5235 return builtin_type_char
;
5238 /* We have a real range type on our hands. Allocate space and
5239 return a real pointer. */
5241 /* At this point I don't have the faintest idea how to deal with
5242 a self_subrange type; I'm going to assume that this is used
5243 as an idiom, and that all of them are special cases. So . . . */
5245 return error_type (pp
);
5247 result_type
= (struct type
*) obstack_alloc (symbol_obstack
,
5248 sizeof (struct type
));
5249 bzero (result_type
, sizeof (struct type
));
5251 TYPE_CODE (result_type
) = TYPE_CODE_RANGE
;
5253 TYPE_TARGET_TYPE (result_type
) = *dbx_lookup_type(rangenums
);
5254 if (TYPE_TARGET_TYPE (result_type
) == 0) {
5255 complain (&range_type_base_complaint
, rangenums
[1]);
5256 TYPE_TARGET_TYPE (result_type
) = builtin_type_int
;
5259 TYPE_NFIELDS (result_type
) = 2;
5260 TYPE_FIELDS (result_type
) =
5261 (struct field
*) obstack_alloc (symbol_obstack
,
5262 2 * sizeof (struct field
));
5263 bzero (TYPE_FIELDS (result_type
), 2 * sizeof (struct field
));
5264 TYPE_FIELD_BITPOS (result_type
, 0) = n2
;
5265 TYPE_FIELD_BITPOS (result_type
, 1) = n3
;
5268 /* Note that TYPE_LENGTH (result_type) is just overridden a few
5269 statements down. What do we really need here? */
5270 /* We have to figure out how many bytes it takes to hold this
5271 range type. I'm going to assume that anything that is pushing
5272 the bounds of a long was taken care of above. */
5273 if (n2
>= MIN_OF_C_TYPE(char) && n3
<= MAX_OF_C_TYPE(char))
5274 TYPE_LENGTH (result_type
) = 1;
5275 else if (n2
>= MIN_OF_C_TYPE(short) && n3
<= MAX_OF_C_TYPE(short))
5276 TYPE_LENGTH (result_type
) = sizeof (short);
5277 else if (n2
>= MIN_OF_C_TYPE(int) && n3
<= MAX_OF_C_TYPE(int))
5278 TYPE_LENGTH (result_type
) = sizeof (int);
5279 else if (n2
>= MIN_OF_C_TYPE(long) && n3
<= MAX_OF_C_TYPE(long))
5280 TYPE_LENGTH (result_type
) = sizeof (long);
5282 /* Ranged type doesn't fit within known sizes. */
5283 /* FIXME -- use "long long" here. */
5284 return error_type (pp
);
5287 TYPE_LENGTH (result_type
) = TYPE_LENGTH (TYPE_TARGET_TYPE (result_type
));
5292 /* Read a number from the string pointed to by *PP.
5293 The value of *PP is advanced over the number.
5294 If END is nonzero, the character that ends the
5295 number must match END, or an error happens;
5296 and that character is skipped if it does match.
5297 If END is zero, *PP is left pointing to that character. */
5300 read_number (pp
, end
)
5304 register char *p
= *pp
;
5305 register long n
= 0;
5309 /* Handle an optional leading minus sign. */
5317 /* Read the digits, as far as they go. */
5319 while ((c
= *p
++) >= '0' && c
<= '9')
5327 error ("Invalid symbol data: invalid character \\%03o at symbol pos %d.", c
, symnum
);
5336 /* Read in an argument list. This is a list of types, separated by commas
5337 and terminated with END. Return the list of types read in, or (struct type
5338 **)-1 if there is an error. */
5339 static struct type
**
5344 struct type
*types
[1024], **rval
; /* allow for fns of 1023 parameters */
5350 /* Invalid argument list: no ','. */
5351 return (struct type
**)-1;
5354 /* Check for and handle cretinous dbx symbol name continuation! */
5356 *pp
= next_symbol_text ();
5358 types
[n
++] = read_type (pp
);
5360 *pp
+= 1; /* get past `end' (the ':' character) */
5364 rval
= (struct type
**) xmalloc (2 * sizeof (struct type
*));
5366 else if (TYPE_CODE (types
[n
-1]) != TYPE_CODE_VOID
)
5368 rval
= (struct type
**) xmalloc ((n
+ 1) * sizeof (struct type
*));
5369 bzero (rval
+ n
, sizeof (struct type
*));
5373 rval
= (struct type
**) xmalloc (n
* sizeof (struct type
*));
5375 bcopy (types
, rval
, n
* sizeof (struct type
*));
5379 /* Copy a pending list, used to record the contents of a common
5380 block for later fixup. */
5381 static struct pending
*
5382 copy_pending (beg
, begi
, end
)
5383 struct pending
*beg
, *end
;
5386 struct pending
*new = 0;
5387 struct pending
*next
;
5389 for (next
= beg
; next
!= 0 && (next
!= end
|| begi
< end
->nsyms
);
5390 next
= next
->next
, begi
= 0)
5393 for (j
= begi
; j
< next
->nsyms
; j
++)
5394 add_symbol_to_list (next
->symbol
[j
], &new);
5399 /* Add a common block's start address to the offset of each symbol
5400 declared to be in it (by being between a BCOMM/ECOMM pair that uses
5401 the common block name). */
5404 fix_common_block (sym
, valu
)
5408 struct pending
*next
= (struct pending
*) SYMBOL_NAMESPACE (sym
);
5409 for ( ; next
; next
= next
->next
)
5412 for (j
= next
->nsyms
- 1; j
>= 0; j
--)
5413 SYMBOL_VALUE_ADDRESS (next
->symbol
[j
]) += valu
;
5417 /* Register our willingness to decode symbols for SunOS and a.out and
5418 b.out files handled by BFD... */
5419 static struct sym_fns sunos_sym_fns
= {"sunOs", 6,
5420 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
5422 static struct sym_fns aout_sym_fns
= {"a.out", 5,
5423 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
5425 static struct sym_fns bout_sym_fns
= {"b.out", 5,
5426 dbx_new_init
, dbx_symfile_init
, dbx_symfile_read
};
5429 _initialize_dbxread ()
5431 add_symtab_fns(&sunos_sym_fns
);
5432 add_symtab_fns(&aout_sym_fns
);
5433 add_symtab_fns(&bout_sym_fns
);
5435 undef_types_allocated
= 20;
5436 undef_types_length
= 0;
5437 undef_types
= (struct type
**) xmalloc (undef_types_allocated
*
5438 sizeof (struct type
*));