]>
Commit | Line | Data |
---|---|---|
bd5635a1 | 1 | /* Definitions for reading symbol files into GDB. |
318bf84f | 2 | Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc. |
bd5635a1 RP |
3 | |
4 | This file is part of GDB. | |
5 | ||
2f068b0d | 6 | This program is free software; you can redistribute it and/or modify |
bd5635a1 | 7 | it under the terms of the GNU General Public License as published by |
2f068b0d FF |
8 | the Free Software Foundation; either version 2 of the License, or |
9 | (at your option) any later version. | |
bd5635a1 | 10 | |
2f068b0d | 11 | This program is distributed in the hope that it will be useful, |
bd5635a1 RP |
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. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
2f068b0d FF |
17 | along with this program; if not, write to the Free Software |
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
bd5635a1 | 19 | |
318bf84f FF |
20 | #if !defined (SYMFILE_H) |
21 | #define SYMFILE_H | |
22 | ||
bd5635a1 RP |
23 | /* This file requires that you first include "bfd.h". */ |
24 | ||
318bf84f FF |
25 | struct psymbol_allocation_list { |
26 | struct partial_symbol *list; | |
27 | struct partial_symbol *next; | |
28 | int size; | |
29 | }; | |
30 | ||
80d68b1d FF |
31 | /* Structure to keep track of symbol reading functions for various |
32 | object file types. */ | |
33 | ||
34 | struct sym_fns { | |
35 | ||
36 | /* is the name, or name prefix, of the BFD "target type" that this | |
37 | set of functions handles. E.g. "a.out" or "sunOs" or "coff" or "elf". */ | |
38 | ||
39 | char *sym_name; | |
40 | ||
41 | /* counts how many bytes of sym_name should be checked against the | |
42 | BFD target type of the file being read. If an exact match is | |
43 | desired, specify the number of characters in sym_name plus 1 for the | |
44 | NUL. If a prefix match is desired, specify the number of characters in | |
45 | sym_name. */ | |
46 | ||
47 | int sym_namelen; | |
48 | ||
49 | /* Initializes anything that is global to the entire symbol table. It is | |
50 | called during symbol_file_add, when we begin debugging an entirely new | |
51 | program. */ | |
52 | ||
53 | void (*sym_new_init) PARAMS ((struct objfile *)); | |
54 | ||
55 | /* Reads any initial information from a symbol file, and initializes the | |
56 | struct sym_fns SF in preparation for sym_read(). It is called every | |
57 | time we read a symbol file for any reason. */ | |
58 | ||
59 | void (*sym_init) PARAMS ((struct objfile *)); | |
60 | ||
61 | /* sym_read (objfile, addr, mainline) | |
62 | Reads a symbol file into a psymtab (or possibly a symtab). | |
63 | OBJFILE is the objfile struct for the file we are reading. ADDR | |
64 | is the offset between the file's specified start address and | |
65 | its true address in memory. MAINLINE is 1 if this is the | |
66 | main symbol table being read, and 0 if a secondary | |
67 | symbol file (e.g. shared library or dynamically loaded file) | |
68 | is being read. */ | |
69 | ||
70 | void (*sym_read) PARAMS ((struct objfile *, CORE_ADDR, int)); | |
71 | ||
72 | /* Called when we are finished with an objfile. Should do all cleanup | |
73 | that is specific to the object file format for the particular objfile. */ | |
74 | ||
75 | void (*sym_finish) PARAMS ((struct objfile *)); | |
76 | ||
77 | /* Finds the next struct sym_fns. They are allocated and initialized | |
78 | in whatever module implements the functions pointed to; an | |
79 | initializer calls add_symtab_fns to add them to the global chain. */ | |
80 | ||
81 | struct sym_fns *next; | |
82 | ||
83 | }; | |
84 | ||
318bf84f FF |
85 | /* Master structure for keeping track of each input file from which |
86 | gdb reads symbols. One of these is allocated for each such file we | |
87 | access, e.g. the exec_file, symbol_file, and any shared library object | |
88 | files. */ | |
7e258d18 | 89 | |
318bf84f FF |
90 | struct objfile |
91 | { | |
7e258d18 | 92 | |
318bf84f FF |
93 | /* All struct objfile's are chained together by their next pointers. |
94 | The global variable "object_files" points to the first link in this | |
95 | chain. */ | |
7e258d18 | 96 | |
7e258d18 PB |
97 | struct objfile *next; |
98 | ||
318bf84f FF |
99 | /* The object file's name. Malloc'd; free it if you free this struct. */ |
100 | ||
101 | char *name; | |
102 | ||
103 | /* Some flag bits for this objfile. */ | |
104 | ||
105 | unsigned short flags; | |
106 | ||
107 | /* Each objfile points to a linked list of symtabs derived from this file, | |
108 | one symtab structure for each compilation unit (source file). Each link | |
109 | in the symtab list contains a backpointer to this objfile. */ | |
110 | ||
7e258d18 PB |
111 | struct symtab *symtabs; |
112 | ||
318bf84f FF |
113 | /* Each objfile points to a linked list of partial symtabs derived from |
114 | this file, one partial symtab structure for each compilation unit | |
115 | (source file). */ | |
116 | ||
7e258d18 PB |
117 | struct partial_symtab *psymtabs; |
118 | ||
318bf84f FF |
119 | /* List of freed partial symtabs, available for re-use */ |
120 | ||
121 | struct partial_symtab *free_psymtabs; | |
7e258d18 PB |
122 | |
123 | /* The object file's BFD. Can be null, in which case bfd_open (name) and | |
124 | put the result here. */ | |
318bf84f | 125 | |
7e258d18 PB |
126 | bfd *obfd; |
127 | ||
128 | /* The modification timestamp of the object file, as of the last time | |
129 | we read its symbols. */ | |
318bf84f | 130 | |
7e258d18 | 131 | long mtime; |
318bf84f FF |
132 | |
133 | /* Obstacks to hold objects that should be freed when we load a new symbol | |
134 | table from this object file. */ | |
135 | ||
136 | struct obstack psymbol_obstack; /* Partial symbols */ | |
137 | struct obstack symbol_obstack; /* Full symbols */ | |
138 | struct obstack type_obstack; /* Types */ | |
139 | ||
140 | /* Vectors of all partial symbols read in from file. The actual data | |
141 | is stored in the psymbol_obstack. */ | |
142 | ||
143 | struct psymbol_allocation_list global_psymbols; | |
144 | struct psymbol_allocation_list static_psymbols; | |
145 | ||
146 | /* Each file contains a pointer to an array of minimal symbols for all | |
147 | global symbols that are defined within the file. The array is terminated | |
148 | by a "null symbol", one that has a NULL pointer for the name and a zero | |
149 | value for the address. This makes it easy to walk through the array | |
150 | when passed a pointer to somewhere in the middle of it. There is also | |
151 | a count of the number of symbols, which does include the terminating | |
152 | null symbol. The array itself, as well as all the data that it points | |
153 | to, should be allocated on the symbol_obstack for this file. */ | |
154 | ||
155 | struct minimal_symbol *msymbols; | |
156 | int minimal_symbol_count; | |
157 | ||
158 | /* For object file formats which don't specify fundamental types, gdb | |
159 | can create such types. For now, it maintains a vector of pointers | |
160 | to these internally created fundamental types on a per objfile basis, | |
161 | however it really should ultimately keep them on a per-compilation-unit | |
162 | basis, to account for linkage-units that consist of a number of | |
163 | compilation units that may have different fundamental types, such as | |
164 | linking C modules with ADA modules, or linking C modules that are | |
165 | compiled with 32-bit ints with C modules that are compiled with 64-bit | |
166 | ints (not inherently evil with a smarter linker). */ | |
167 | ||
168 | struct type **fundamental_types; | |
169 | ||
170 | /* The mmalloc() malloc-descriptor for this objfile if we are using | |
171 | the memory mapped malloc() package to manage storage for this objfile's | |
172 | data. NULL if we are not. */ | |
173 | ||
80d68b1d FF |
174 | PTR md; |
175 | ||
176 | /* Structure which keeps track of functions that manipulate objfile's | |
177 | of the same type as this objfile. I.E. the function to read partial | |
178 | symbols for example. Note that this structure is in statically | |
179 | allocated memory, and is shared by all objfiles that use the | |
180 | object module reader of this type. */ | |
181 | ||
182 | struct sym_fns *sf; | |
183 | ||
184 | /* Hook for information which is shared by sym_init and sym_read for | |
185 | this objfile. It is typically a pointer to malloc'd memory. */ | |
186 | ||
187 | PTR sym_private; | |
318bf84f | 188 | |
7e258d18 PB |
189 | }; |
190 | ||
318bf84f FF |
191 | /* Defines for the objfile flag word. */ |
192 | ||
193 | /* Gdb can arrange to allocate storage for all objects related to a | |
194 | particular objfile in a designated section of it's address space, | |
195 | managed at a low level by mmap() and using a special version of | |
196 | malloc that handles malloc/free/realloc on top of the mmap() interface. | |
197 | This allows the "internal gdb state" for a particular objfile to be | |
198 | dumped to a gdb state file and subsequently reloaded at a later time. */ | |
199 | ||
200 | #define OBJF_MAPPED (1 << 0) /* Objfile data is mmap'd */ | |
201 | ||
bd5635a1 | 202 | |
318bf84f FF |
203 | extern void |
204 | extend_psymbol_list PARAMS ((struct psymbol_allocation_list *, | |
205 | struct objfile *)); | |
7e258d18 PB |
206 | |
207 | /* Add any kind of symbol to a psymbol_allocation_list. */ | |
208 | ||
318bf84f | 209 | #define ADD_PSYMBOL_VT_TO_LIST(NAME,NAMELENGTH,NAMESPACE,CLASS,LIST,VALUE,VT) \ |
7e258d18 PB |
210 | do { \ |
211 | register struct partial_symbol *psym; \ | |
212 | if ((LIST).next >= (LIST).list + (LIST).size) \ | |
318bf84f | 213 | extend_psymbol_list (&(LIST),objfile); \ |
7e258d18 PB |
214 | psym = (LIST).next++; \ |
215 | \ | |
318bf84f | 216 | SYMBOL_NAME (psym) = (char *) obstack_alloc (&objfile->psymbol_obstack, \ |
7e258d18 | 217 | (NAMELENGTH) + 1); \ |
318bf84f | 218 | memcpy (SYMBOL_NAME (psym), (NAME), (NAMELENGTH)); \ |
7e258d18 PB |
219 | SYMBOL_NAME (psym)[(NAMELENGTH)] = '\0'; \ |
220 | SYMBOL_NAMESPACE (psym) = (NAMESPACE); \ | |
221 | SYMBOL_CLASS (psym) = (CLASS); \ | |
222 | VT (psym) = (VALUE); \ | |
223 | } while (0); | |
224 | ||
318bf84f FF |
225 | #ifdef DEBUG |
226 | ||
227 | /* Since one arg is a struct, we have to pass in a ptr and deref it (sigh) */ | |
228 | ||
229 | #define ADD_PSYMBOL_TO_LIST(name, namelength, namespace, class, list, value) \ | |
230 | add_psymbol_to_list (name, namelength, namespace, class, &list, value) | |
231 | ||
232 | #define ADD_PSYMBOL_ADDR_TO_LIST(name, namelength, namespace, class, list, value) \ | |
233 | add_psymbol_addr_to_list (name, namelength, namespace, class, &list, value) | |
234 | ||
235 | #else /* !DEBUG */ | |
236 | ||
237 | /* Add a symbol with an integer value to a psymtab. */ | |
238 | ||
239 | #define ADD_PSYMBOL_TO_LIST(name, namelength, namespace, class, list, value) \ | |
240 | ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, list, value, SYMBOL_VALUE) | |
241 | ||
242 | /* Add a symbol with a CORE_ADDR value to a psymtab. */ | |
243 | ||
244 | #define ADD_PSYMBOL_ADDR_TO_LIST(name, namelength, namespace, class, list, value)\ | |
245 | ADD_PSYMBOL_VT_TO_LIST (name, namelength, namespace, class, list, value, SYMBOL_VALUE_ADDRESS) | |
246 | ||
247 | #endif /* DEBUG */ | |
248 | ||
bd5635a1 RP |
249 | /* Functions */ |
250 | ||
318bf84f FF |
251 | extern void |
252 | sort_pst_symbols PARAMS ((struct partial_symtab *)); | |
253 | ||
254 | extern struct symtab * | |
255 | allocate_symtab PARAMS ((char *, struct objfile *)); | |
256 | ||
257 | extern struct objfile * | |
b0246b3b | 258 | allocate_objfile PARAMS ((bfd *, int)); |
318bf84f FF |
259 | |
260 | extern void | |
261 | free_objfile PARAMS ((struct objfile *)); | |
262 | ||
263 | extern void | |
264 | free_all_objfiles PARAMS ((void)); | |
265 | ||
266 | extern int | |
267 | free_named_symtabs PARAMS ((char *)); | |
bd5635a1 | 268 | |
318bf84f FF |
269 | extern void |
270 | fill_in_vptr_fieldno PARAMS ((struct type *)); | |
bd5635a1 | 271 | |
318bf84f FF |
272 | extern void |
273 | add_symtab_fns PARAMS ((struct sym_fns *)); | |
274 | ||
275 | extern void | |
276 | syms_from_objfile PARAMS ((struct objfile *, CORE_ADDR, int, int)); | |
277 | ||
278 | extern struct partial_symtab * | |
279 | start_psymtab_common PARAMS ((struct objfile *, CORE_ADDR, char *, CORE_ADDR, | |
280 | struct partial_symbol *, | |
281 | struct partial_symbol *)); | |
bd5635a1 RP |
282 | |
283 | /* Sorting your symbols for fast lookup or alphabetical printing. */ | |
284 | ||
318bf84f FF |
285 | extern void |
286 | sort_block_syms PARAMS ((struct block *)); | |
287 | ||
288 | extern void | |
289 | sort_symtab_syms PARAMS ((struct symtab *)); | |
290 | ||
291 | extern void | |
292 | sort_all_symtab_syms PARAMS ((void)); | |
bd5635a1 RP |
293 | |
294 | /* Make a copy of the string at PTR with SIZE characters in the symbol obstack | |
295 | (and add a null character at the end in the copy). | |
296 | Returns the address of the copy. */ | |
297 | ||
318bf84f FF |
298 | extern char * |
299 | obsavestring PARAMS ((char *, int, struct obstack *)); | |
bd5635a1 RP |
300 | |
301 | /* Concatenate strings S1, S2 and S3; return the new string. | |
302 | Space is found in the symbol_obstack. */ | |
303 | ||
318bf84f FF |
304 | extern char * |
305 | obconcat PARAMS ((struct obstack *obstackp, const char *, const char *, | |
306 | const char *)); | |
bd5635a1 RP |
307 | |
308 | /* Variables */ | |
309 | ||
7e258d18 PB |
310 | /* The object file that the main symbol table was loaded from (e.g. the |
311 | argument to the "symbol-file" or "file" command). */ | |
312 | ||
313 | extern struct objfile *symfile_objfile; | |
314 | ||
315 | /* Where execution starts in symfile */ | |
bd5635a1 | 316 | |
318bf84f | 317 | extern CORE_ADDR entry_point; |
bd5635a1 | 318 | |
7e258d18 | 319 | /* Root of object file struct chain. */ |
bd5635a1 | 320 | |
318bf84f | 321 | extern struct objfile *object_files; |
bd5635a1 | 322 | |
318bf84f FF |
323 | /* Traverse all object files. ALL_OBJFILES_SAFE works even if you delete |
324 | the objfile during the traversal. */ | |
bd5635a1 | 325 | |
318bf84f FF |
326 | #define ALL_OBJFILES(obj) \ |
327 | for (obj = object_files; 0 != obj; obj = obj->next) | |
328 | ||
329 | #define ALL_OBJFILES_SAFE(obj,nxt) \ | |
330 | for (obj = object_files; obj? (nxt=obj->next, 1): 0; obj = nxt) | |
bd5635a1 RP |
331 | |
332 | /* Support for complaining about things in the symbol file that aren't | |
333 | catastrophic. | |
334 | ||
335 | Each such thing gets a counter. The first time we have the problem, | |
336 | during a symbol read, we report it. At the end of symbol reading, | |
337 | if verbose, we report how many of each problem we had. */ | |
338 | ||
339 | struct complaint { | |
340 | char *message; | |
341 | unsigned counter; | |
342 | struct complaint *next; | |
343 | }; | |
344 | ||
345 | /* Root of the chain of complaints that have at some point been issued. | |
346 | This is used to reset the counters, and/or report the total counts. */ | |
347 | ||
348 | extern struct complaint complaint_root[1]; | |
349 | ||
350 | /* Functions that handle complaints. (in symfile.c) */ | |
351 | ||
318bf84f FF |
352 | extern void |
353 | complain PARAMS ((struct complaint *, char *)); | |
354 | ||
355 | extern void | |
356 | clear_complaints PARAMS ((int sym_reading, int noisy)); | |
357 | ||
358 | /* From symfile.c */ | |
359 | ||
360 | extern struct partial_symtab * | |
361 | allocate_psymtab PARAMS ((char *, struct objfile *)); | |
362 | ||
363 | /* From minsyms.c */ | |
364 | ||
365 | extern PTR | |
366 | iterate_over_msymbols PARAMS ((PTR (*func) (struct objfile *, | |
367 | struct minimal_symbol *, | |
368 | PTR arg1, PTR arg2, PTR arg3), | |
369 | PTR arg1, PTR arg2, PTR arg3)); | |
370 | ||
371 | /* From objfiles.c */ | |
372 | ||
373 | extern PTR | |
374 | iterate_over_objfiles PARAMS ((PTR (*func) (struct objfile *, | |
375 | PTR arg1, PTR arg2, PTR arg3), | |
376 | PTR arg1, PTR arg2, PTR arg3)); | |
377 | ||
378 | extern PTR | |
379 | iterate_over_symtabs PARAMS ((PTR (*func) (struct objfile *, struct symtab *, | |
380 | PTR arg1, PTR arg2, PTR arg3), | |
381 | PTR arg1, PTR arg2, PTR arg3)); | |
382 | ||
383 | extern PTR | |
384 | iterate_over_psymtabs PARAMS ((PTR (*func) (struct objfile *, | |
385 | struct partial_symtab *, | |
386 | PTR arg1, PTR arg2, PTR arg3), | |
387 | PTR arg1, PTR arg2, PTR arg3)); | |
388 | ||
389 | /* From dwarfread.c */ | |
390 | ||
391 | extern void | |
392 | dwarf_build_psymtabs PARAMS ((int, char *, CORE_ADDR, int, unsigned int, | |
393 | unsigned int, unsigned int, unsigned int, | |
394 | struct objfile *)); | |
395 | ||
396 | #endif /* !defined(SYMFILE_H) */ |