Commit | Line | Data |
---|---|---|
1ab3bf1b JG |
1 | /* GDB routines for manipulating objfiles. |
2 | Copyright 1992 Free Software Foundation, Inc. | |
3 | Contributed by Cygnus Support, using pieces from other GDB modules. | |
4 | ||
5 | This file is part of GDB. | |
6 | ||
7 | This program is free software; you can redistribute it and/or modify | |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | This program is distributed in the hope that it will be useful, | |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
18 | along with this program; if not, write to the Free Software | |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
20 | ||
21 | /* This file contains support routines for creating, manipulating, and | |
22 | destroying objfile structures. */ | |
23 | ||
1ab3bf1b JG |
24 | #include "defs.h" |
25 | #include "bfd.h" /* Binary File Description */ | |
26 | #include "symtab.h" | |
27 | #include "symfile.h" | |
28 | ||
29 | #include <obstack.h> | |
30 | ||
31 | /* Externally visible variables that are owned by this module. */ | |
32 | ||
33 | struct objfile *object_files; /* Linked list of all objfiles */ | |
34 | ||
35 | /* Allocate a new objfile struct, fill it in as best we can, and return it. | |
36 | It is also linked into the list of all known object files. */ | |
37 | ||
38 | struct objfile * | |
39 | allocate_objfile (abfd, filename, dumpable) | |
40 | bfd *abfd; | |
41 | char *filename; | |
42 | int dumpable; | |
43 | { | |
44 | struct objfile *objfile; | |
45 | ||
46 | /* First, if the objfile is to be dumpable, we must malloc the structure | |
47 | itself using the mmap version, and arrange that all memory allocation | |
48 | for the objfile uses the mmap routines. Otherwise, just use the | |
49 | old sbrk'd malloc routines. */ | |
50 | ||
51 | if (dumpable) | |
52 | { | |
53 | objfile = (struct objfile *) mmap_xmalloc (sizeof (struct objfile)); | |
54 | (void) memset (objfile, 0, sizeof (struct objfile)); | |
55 | objfile -> malloc = mmap_malloc; | |
56 | objfile -> realloc = mmap_realloc; | |
57 | objfile -> xmalloc = mmap_xmalloc; | |
58 | objfile -> xrealloc = mmap_xrealloc; | |
59 | objfile -> free = mmap_free; | |
60 | objfile -> flags |= OBJF_DUMPABLE; | |
61 | } | |
62 | else | |
63 | { | |
64 | objfile = (struct objfile *) xmalloc (sizeof (struct objfile)); | |
65 | (void) memset (objfile, 0, sizeof (struct objfile)); | |
6c6afbb9 PB |
66 | objfile -> malloc = (PTR (*) PARAMS ((long))) malloc; |
67 | objfile -> realloc = (PTR (*) PARAMS ((PTR, long))) realloc; | |
1ab3bf1b JG |
68 | objfile -> xmalloc = xmalloc; |
69 | objfile -> xrealloc = xrealloc; | |
70 | objfile -> free = free; | |
71 | } | |
72 | ||
73 | /* Now, malloc a fresh copy of the filename string using the malloc | |
74 | specified as appropriate for the objfile. */ | |
75 | ||
76 | objfile -> name = (*objfile -> xmalloc) (strlen (filename) + 1); | |
77 | strcpy (objfile -> name, filename); | |
78 | ||
79 | objfile -> obfd = abfd; | |
80 | ||
81 | objfile -> mtime = bfd_get_mtime (abfd); | |
82 | ||
83 | /* Set up the various obstacks to use the memory allocation/free | |
84 | functions that are appropriate for this objfile. */ | |
85 | ||
86 | obstack_full_begin (&objfile -> psymbol_obstack, 0, 0, | |
87 | objfile -> xmalloc, objfile -> free); | |
88 | obstack_full_begin (&objfile -> symbol_obstack, 0, 0, | |
89 | objfile -> xmalloc, objfile -> free); | |
90 | obstack_full_begin (&objfile -> type_obstack, 0, 0, | |
91 | objfile -> xmalloc, objfile -> free); | |
92 | ||
93 | /* Push this file onto the head of the linked list of other such files. */ | |
94 | ||
95 | objfile -> next = object_files; | |
96 | object_files = objfile; | |
97 | ||
98 | return (objfile); | |
99 | } | |
100 | ||
101 | ||
102 | /* Destroy an objfile and all the symtabs and psymtabs under it. Note | |
103 | that as much as possible is allocated on the symbol_obstack and | |
104 | psymbol_obstack, so that the memory can be efficiently freed. */ | |
105 | ||
106 | void | |
107 | free_objfile (objfile) | |
108 | struct objfile *objfile; | |
109 | { | |
110 | struct objfile *ofp; | |
111 | ||
112 | if (objfile -> name) | |
113 | { | |
114 | (*objfile -> free) (objfile -> name); | |
115 | } | |
116 | if (objfile -> obfd) | |
117 | { | |
118 | bfd_close (objfile -> obfd); | |
119 | } | |
120 | ||
121 | /* Remove it from the chain of all objfiles. */ | |
122 | ||
123 | if (object_files == objfile) | |
124 | { | |
125 | object_files = objfile -> next; | |
126 | } | |
127 | else | |
128 | { | |
129 | for (ofp = object_files; ofp; ofp = ofp -> next) | |
130 | { | |
131 | if (ofp -> next == objfile) | |
132 | { | |
133 | ofp -> next = objfile -> next; | |
134 | } | |
135 | } | |
136 | } | |
137 | ||
138 | obstack_free (&objfile -> psymbol_obstack, 0); | |
139 | obstack_free (&objfile -> symbol_obstack, 0); | |
140 | obstack_free (&objfile -> type_obstack, 0); | |
141 | ||
142 | #if 0 /* FIXME!! */ | |
143 | ||
144 | /* Before the symbol table code was redone to make it easier to | |
145 | selectively load and remove information particular to a specific | |
146 | linkage unit, gdb used to do these things whenever the monolithic | |
147 | symbol table was blown away. How much still needs to be done | |
148 | is unknown, but we play it safe for now and keep each action until | |
149 | it is shown to be no longer needed. */ | |
150 | ||
151 | clear_symtab_users_once (); | |
152 | #if defined (CLEAR_SOLIB) | |
153 | CLEAR_SOLIB (); | |
154 | #endif | |
155 | clear_pc_function_cache (); | |
156 | ||
157 | #endif | |
158 | ||
159 | /* The last thing we do is free the objfile struct itself, using the | |
160 | free() that is appropriate for the objfile. */ | |
161 | ||
162 | (*objfile -> free) (objfile); | |
163 | } | |
164 | ||
cba0d141 JG |
165 | |
166 | /* Free all the object files at once. */ | |
167 | ||
168 | void | |
169 | free_all_objfiles () | |
170 | { | |
171 | struct objfile *objfile, *temp; | |
172 | ||
173 | ALL_OBJFILES_SAFE (objfile, temp) | |
174 | { | |
175 | free_objfile (objfile); | |
176 | } | |
177 | } | |
178 | ||
1ab3bf1b JG |
179 | /* Many places in gdb want to test just to see if we have any partial |
180 | symbols available. This function returns zero if none are currently | |
181 | available, nonzero otherwise. */ | |
182 | ||
183 | int | |
184 | have_partial_symbols () | |
185 | { | |
186 | struct objfile *ofp; | |
187 | int havethem = 0; | |
188 | ||
189 | for (ofp = object_files; ofp; ofp = ofp -> next) | |
190 | { | |
191 | if (ofp -> psymtabs != NULL) | |
192 | { | |
193 | havethem++; | |
194 | break; | |
195 | } | |
196 | } | |
197 | return (havethem); | |
198 | } | |
199 | ||
200 | /* Many places in gdb want to test just to see if we have any full | |
201 | symbols available. This function returns zero if none are currently | |
202 | available, nonzero otherwise. */ | |
203 | ||
204 | int | |
205 | have_full_symbols () | |
206 | { | |
207 | struct objfile *ofp; | |
208 | int havethem = 0; | |
209 | ||
210 | for (ofp = object_files; ofp; ofp = ofp -> next) | |
211 | { | |
212 | if (ofp -> symtabs != NULL) | |
213 | { | |
214 | havethem++; | |
215 | break; | |
216 | } | |
217 | } | |
218 | return (havethem); | |
219 | } | |
220 | ||
221 | /* Many places in gdb want to test just to see if we have any minimal | |
222 | symbols available. This function returns zero if none are currently | |
223 | available, nonzero otherwise. */ | |
224 | ||
225 | int | |
226 | have_minimal_symbols () | |
227 | { | |
228 | struct objfile *ofp; | |
229 | int havethem = 0; | |
230 | ||
231 | for (ofp = object_files; ofp; ofp = ofp -> next) | |
232 | { | |
233 | if (ofp -> msymbols != NULL) | |
234 | { | |
235 | havethem++; | |
236 | break; | |
237 | } | |
238 | } | |
239 | return (havethem); | |
240 | } | |
241 | ||
242 | /* Call the function specified by FUNC for each currently available objfile, | |
243 | for as long as this function continues to return NULL. If the function | |
244 | ever returns non-NULL, then the iteration over the objfiles is terminated, | |
245 | and the result is returned to the caller. The function called has full | |
246 | control over the form and content of the information returned via the | |
247 | non-NULL result, which may be as simple as a pointer to the objfile that | |
248 | the iteration terminated on, or as complex as a pointer to a private | |
249 | structure containing multiple results. */ | |
250 | ||
251 | PTR | |
252 | iterate_over_objfiles (func, arg1, arg2, arg3) | |
253 | PTR (*func) PARAMS ((struct objfile *, PTR, PTR, PTR)); | |
254 | PTR arg1; | |
255 | PTR arg2; | |
256 | PTR arg3; | |
257 | { | |
258 | register struct objfile *objfile; | |
259 | PTR result = NULL; | |
260 | ||
261 | for (objfile = object_files; | |
262 | objfile != NULL && result == NULL; | |
263 | objfile = objfile -> next) | |
264 | { | |
265 | result = (*func)(objfile, arg1, arg2, arg3); | |
266 | } | |
267 | return (result); | |
268 | } | |
269 | ||
270 | /* Call the function specified by FUNC for each currently available symbol | |
271 | table, for as long as this function continues to return NULL. If the | |
272 | function ever returns non-NULL, then the iteration over the symbol tables | |
273 | is terminated, and the result is returned to the caller. The function | |
274 | called has full control over the form and content of the information | |
275 | returned via the non-NULL result, which may be as simple as a pointer | |
276 | to the symtab that the iteration terminated on, or as complex as a | |
277 | pointer to a private structure containing multiple results. */ | |
278 | ||
279 | PTR | |
280 | iterate_over_symtabs (func, arg1, arg2, arg3) | |
281 | PTR (*func) PARAMS ((struct objfile *, struct symtab *, PTR, PTR, PTR)); | |
282 | PTR arg1; | |
283 | PTR arg2; | |
284 | PTR arg3; | |
285 | { | |
286 | register struct objfile *objfile; | |
287 | register struct symtab *symtab; | |
288 | PTR result = NULL; | |
289 | ||
290 | for (objfile = object_files; | |
291 | objfile != NULL && result == NULL; | |
292 | objfile = objfile -> next) | |
293 | { | |
294 | for (symtab = objfile -> symtabs; | |
295 | symtab != NULL && result == NULL; | |
296 | symtab = symtab -> next) | |
297 | { | |
298 | result = (*func)(objfile, symtab, arg1, arg2, arg3); | |
299 | } | |
300 | } | |
301 | return (result); | |
302 | } | |
303 | ||
304 | /* Call the function specified by FUNC for each currently available partial | |
305 | symbol table, for as long as this function continues to return NULL. If | |
306 | the function ever returns non-NULL, then the iteration over the partial | |
307 | symbol tables is terminated, and the result is returned to the caller. | |
308 | ||
309 | The function called has full control over the form and content of the | |
310 | information returned via the non-NULL result, which may be as simple as a | |
311 | pointer to the partial symbol table that the iteration terminated on, or | |
312 | as complex as a pointer to a private structure containing multiple | |
313 | results. */ | |
314 | ||
315 | PTR | |
316 | iterate_over_psymtabs (func, arg1, arg2, arg3) | |
317 | PTR (*func) PARAMS ((struct objfile *, struct partial_symtab *, | |
318 | PTR, PTR, PTR)); | |
319 | PTR arg1; | |
320 | PTR arg2; | |
321 | PTR arg3; | |
322 | { | |
323 | register struct objfile *objfile; | |
324 | register struct partial_symtab *psymtab; | |
325 | PTR result = NULL; | |
326 | ||
327 | for (objfile = object_files; | |
328 | objfile != NULL && result == NULL; | |
329 | objfile = objfile -> next) | |
330 | { | |
331 | for (psymtab = objfile -> psymtabs; | |
332 | psymtab != NULL && result == NULL; | |
333 | psymtab = psymtab -> next) | |
334 | { | |
335 | result = (*func)(objfile, psymtab, arg1, arg2, arg3); | |
336 | } | |
337 | } | |
338 | return (result); | |
339 | } |