1 /* Definitions for reading symbol files into GDB.
2 Copyright (C) 1990, 1991, 1992 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 #if !defined (SYMFILE_H)
23 /* This file requires that you first include "bfd.h". */
25 struct psymbol_allocation_list {
26 struct partial_symbol *list;
27 struct partial_symbol *next;
31 /* Master structure for keeping track of each input file from which
32 gdb reads symbols. One of these is allocated for each such file we
33 access, e.g. the exec_file, symbol_file, and any shared library object
39 /* All struct objfile's are chained together by their next pointers.
40 The global variable "object_files" points to the first link in this
45 /* The object file's name. Malloc'd; free it if you free this struct. */
49 /* Some flag bits for this objfile. */
53 /* Each objfile points to a linked list of symtabs derived from this file,
54 one symtab structure for each compilation unit (source file). Each link
55 in the symtab list contains a backpointer to this objfile. */
57 struct symtab *symtabs;
59 /* Each objfile points to a linked list of partial symtabs derived from
60 this file, one partial symtab structure for each compilation unit
63 struct partial_symtab *psymtabs;
65 /* List of freed partial symtabs, available for re-use */
67 struct partial_symtab *free_psymtabs;
69 /* The object file's BFD. Can be null, in which case bfd_open (name) and
70 put the result here. */
74 /* The modification timestamp of the object file, as of the last time
75 we read its symbols. */
79 /* Obstacks to hold objects that should be freed when we load a new symbol
80 table from this object file. */
82 struct obstack psymbol_obstack; /* Partial symbols */
83 struct obstack symbol_obstack; /* Full symbols */
84 struct obstack type_obstack; /* Types */
86 /* Vectors of all partial symbols read in from file. The actual data
87 is stored in the psymbol_obstack. */
89 struct psymbol_allocation_list global_psymbols;
90 struct psymbol_allocation_list static_psymbols;
92 /* Each file contains a pointer to an array of minimal symbols for all
93 global symbols that are defined within the file. The array is terminated
94 by a "null symbol", one that has a NULL pointer for the name and a zero
95 value for the address. This makes it easy to walk through the array
96 when passed a pointer to somewhere in the middle of it. There is also
97 a count of the number of symbols, which does include the terminating
98 null symbol. The array itself, as well as all the data that it points
99 to, should be allocated on the symbol_obstack for this file. */
101 struct minimal_symbol *msymbols;
102 int minimal_symbol_count;
104 /* For object file formats which don't specify fundamental types, gdb
105 can create such types. For now, it maintains a vector of pointers
106 to these internally created fundamental types on a per objfile basis,
107 however it really should ultimately keep them on a per-compilation-unit
108 basis, to account for linkage-units that consist of a number of
109 compilation units that may have different fundamental types, such as
110 linking C modules with ADA modules, or linking C modules that are
111 compiled with 32-bit ints with C modules that are compiled with 64-bit
112 ints (not inherently evil with a smarter linker). */
114 struct type **fundamental_types;
116 /* The mmalloc() malloc-descriptor for this objfile if we are using
117 the memory mapped malloc() package to manage storage for this objfile's
118 data. NULL if we are not. */
124 /* Defines for the objfile flag word. */
126 /* Gdb can arrange to allocate storage for all objects related to a
127 particular objfile in a designated section of it's address space,
128 managed at a low level by mmap() and using a special version of
129 malloc that handles malloc/free/realloc on top of the mmap() interface.
130 This allows the "internal gdb state" for a particular objfile to be
131 dumped to a gdb state file and subsequently reloaded at a later time. */
133 #define OBJF_MAPPED (1 << 0) /* Objfile data is mmap'd */
136 /* Structure to keep track of symbol reading functions for various
137 object file types. */
141 /* is the name, or name prefix, of the BFD "target type" that this
142 set of functions handles. E.g. "a.out" or "sunOs" or "coff" or "elf". */
146 /* counts how many bytes of sym_name should be checked against the
147 BFD target type of the file being read. If an exact match is
148 desired, specify the number of characters in sym_name plus 1 for the
149 NUL. If a prefix match is desired, specify the number of characters in
154 /* initializes anything that is global to the entire
155 symbol table. It is called during symbol_file_add, when
156 we begin debugging an entirely new program. */
158 void (*sym_new_init) PARAMS ((void));
161 reads any initial information from a symbol file, and
162 initializes the struct sym_fns SF in preparation for sym_read().
163 It is called every time we read a symbol file for any reason. */
165 void (*sym_init) PARAMS ((struct sym_fns *));
167 /* sym_read (sf, addr, mainline)
168 reads a symbol file into a psymtab (or possibly a symtab).
169 SF is the struct sym_fns that sym_init initialized. ADDR
170 is the offset between the file's specified start address and
171 its true address in memory. MAINLINE is 1 if this is the
172 main symbol table being read, and 0 if a secondary
173 symbol file (e.g. shared library or dynamically loaded file)
176 void (*sym_read) PARAMS ((struct sym_fns *, CORE_ADDR, int));
178 /* is the accessor for the symbol file being read. */
182 /* is where information can be shared among sym_init and sym_read.
183 It is typically a pointer to malloc'd memory. */
185 char *sym_private; /* Should be void * */
187 /* is the "struct objfile" for the object file being read. */
189 struct objfile *objfile;
191 /* finds the next struct sym_fns. They are allocated and initialized
192 in whatever module implements the functions pointed to; an
193 initializer calls add_symtab_fns to add them to the global chain. */
195 struct sym_fns *next;
200 extend_psymbol_list PARAMS ((struct psymbol_allocation_list *,
203 /* Add any kind of symbol to a psymbol_allocation_list. */
205 #define ADD_PSYMBOL_VT_TO_LIST(NAME,NAMELENGTH,NAMESPACE,CLASS,LIST,VALUE,VT) \
207 register struct partial_symbol *psym; \
208 if ((LIST).next >= (LIST).list + (LIST).size) \
209 extend_psymbol_list (&(LIST),objfile); \
210 psym = (LIST).next++; \
212 SYMBOL_NAME (psym) = (char *) obstack_alloc (&objfile->psymbol_obstack, \
214 memcpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \
215 SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \
216 SYMBOL_NAMESPACE (psym) = (NAMESPACE); \
217 SYMBOL_CLASS (psym) = (CLASS); \
218 VT (psym) = (VALUE); \
223 /* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */
225 #define ADD_PSYMBOL_TO_LIST(name, namelength, namespace, class, list, value) \
226 add_psymbol_to_list (name, namelength, namespace, class, &list, value)
228 #define ADD_PSYMBOL_ADDR_TO_LIST(name, namelength, namespace, class, list, value) \
229 add_psymbol_addr_to_list (name, namelength, namespace, class, &list, value)
233 /* Add a symbol with an integer value to a psymtab. */
235 #define ADD_PSYMBOL_TO_LIST(name, namelength, namespace, class, list, value) \
236 ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, list, value, SYMBOL_VALUE)
238 /* Add a symbol with a CORE_ADDR value to a psymtab. */
240 #define ADD_PSYMBOL_ADDR_TO_LIST(name, namelength, namespace, class, list, value)\
241 ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, list, value, SYMBOL_VALUE_ADDRESS)
248 sort_pst_symbols PARAMS ((struct partial_symtab *));
250 extern struct symtab *
251 allocate_symtab PARAMS ((char *, struct objfile *));
253 extern struct objfile *
254 allocate_objfile PARAMS ((bfd *, int));
257 free_objfile PARAMS ((struct objfile *));
260 free_all_objfiles PARAMS ((void));
263 free_named_symtabs PARAMS ((char *));
266 fill_in_vptr_fieldno PARAMS ((struct type *));
269 add_symtab_fns PARAMS ((struct sym_fns *));
272 syms_from_objfile PARAMS ((struct objfile *, CORE_ADDR, int, int));
274 extern struct partial_symtab *
275 start_psymtab_common PARAMS ((struct objfile *, CORE_ADDR, char *, CORE_ADDR,
276 struct partial_symbol *,
277 struct partial_symbol *));
279 /* Sorting your symbols for fast lookup or alphabetical printing. */
282 sort_block_syms PARAMS ((struct block *));
285 sort_symtab_syms PARAMS ((struct symtab *));
288 sort_all_symtab_syms PARAMS ((void));
290 /* Make a copy of the string at PTR with SIZE characters in the symbol obstack
291 (and add a null character at the end in the copy).
292 Returns the address of the copy. */
295 obsavestring PARAMS ((char *, int, struct obstack *));
297 /* Concatenate strings S1, S2 and S3; return the new string.
298 Space is found in the symbol_obstack. */
301 obconcat PARAMS ((struct obstack *obstackp, const char *, const char *,
306 /* The object file that the main symbol table was loaded from (e.g. the
307 argument to the "symbol-file" or "file" command). */
309 extern struct objfile *symfile_objfile;
311 /* Where execution starts in symfile */
313 extern CORE_ADDR entry_point;
315 /* Root of object file struct chain. */
317 extern struct objfile *object_files;
319 /* Traverse all object files. ALL_OBJFILES_SAFE works even if you delete
320 the objfile during the traversal. */
322 #define ALL_OBJFILES(obj) \
323 for (obj = object_files; 0 != obj; obj = obj->next)
325 #define ALL_OBJFILES_SAFE(obj,nxt) \
326 for (obj = object_files; obj? (nxt=obj->next, 1): 0; obj = nxt)
328 /* Support for complaining about things in the symbol file that aren't
331 Each such thing gets a counter. The first time we have the problem,
332 during a symbol read, we report it. At the end of symbol reading,
333 if verbose, we report how many of each problem we had. */
338 struct complaint *next;
341 /* Root of the chain of complaints that have at some point been issued.
342 This is used to reset the counters, and/or report the total counts. */
344 extern struct complaint complaint_root[1];
346 /* Externally visible variables defined in symfile.c */
348 /* The object file that the main symbol table was loaded from (e.g. the
349 argument to the "symbol-file" or "file" command). */
351 extern struct objfile *symfile_objfile;
353 /* Where execution starts in symfile */
355 extern CORE_ADDR entry_point;
357 /* Root of object file struct chain. */
359 extern struct objfile *object_files;
361 /* Functions that handle complaints. (in symfile.c) */
364 complain PARAMS ((struct complaint *, char *));
367 clear_complaints PARAMS ((int sym_reading, int noisy));
371 extern struct partial_symtab *
372 allocate_psymtab PARAMS ((char *, struct objfile *));
377 iterate_over_msymbols PARAMS ((PTR (*func) (struct objfile *,
378 struct minimal_symbol *,
379 PTR arg1, PTR arg2, PTR arg3),
380 PTR arg1, PTR arg2, PTR arg3));
382 /* From objfiles.c */
385 iterate_over_objfiles PARAMS ((PTR (*func) (struct objfile *,
386 PTR arg1, PTR arg2, PTR arg3),
387 PTR arg1, PTR arg2, PTR arg3));
390 iterate_over_symtabs PARAMS ((PTR (*func) (struct objfile *, struct symtab *,
391 PTR arg1, PTR arg2, PTR arg3),
392 PTR arg1, PTR arg2, PTR arg3));
395 iterate_over_psymtabs PARAMS ((PTR (*func) (struct objfile *,
396 struct partial_symtab *,
397 PTR arg1, PTR arg2, PTR arg3),
398 PTR arg1, PTR arg2, PTR arg3));
400 /* From dwarfread.c */
403 dwarf_build_psymtabs PARAMS ((int, char *, CORE_ADDR, int, unsigned int,
404 unsigned int, unsigned int, unsigned int,
407 #endif /* !defined(SYMFILE_H) */