1 /* GDB routines for manipulating objfiles.
2 Copyright 1992 Free Software Foundation, Inc.
3 Contributed by Cygnus Support, using pieces from other GDB modules.
5 This file is part of GDB.
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.
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.
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. */
21 /* This file contains support routines for creating, manipulating, and
22 destroying objfile structures. */
26 #include "bfd.h" /* Binary File Description */
32 /* Externally visible variables that are owned by this module. */
34 struct objfile *object_files; /* Linked list of all objfiles */
36 /* Allocate a new objfile struct, fill it in as best we can, and return it.
37 It is also linked into the list of all known object files. */
40 allocate_objfile (abfd, filename, dumpable)
45 struct objfile *objfile;
47 /* First, if the objfile is to be dumpable, we must malloc the structure
48 itself using the mmap version, and arrange that all memory allocation
49 for the objfile uses the mmap routines. Otherwise, just use the
50 old sbrk'd malloc routines. */
54 objfile = (struct objfile *) mmap_xmalloc (sizeof (struct objfile));
55 (void) memset (objfile, 0, sizeof (struct objfile));
56 objfile -> malloc = mmap_malloc;
57 objfile -> realloc = mmap_realloc;
58 objfile -> xmalloc = mmap_xmalloc;
59 objfile -> xrealloc = mmap_xrealloc;
60 objfile -> free = mmap_free;
61 objfile -> flags |= OBJF_DUMPABLE;
65 objfile = (struct objfile *) xmalloc (sizeof (struct objfile));
66 (void) memset (objfile, 0, sizeof (struct objfile));
67 objfile -> malloc = malloc;
68 objfile -> realloc = realloc;
69 objfile -> xmalloc = xmalloc;
70 objfile -> xrealloc = xrealloc;
71 objfile -> free = free;
74 /* Now, malloc a fresh copy of the filename string using the malloc
75 specified as appropriate for the objfile. */
77 objfile -> name = (*objfile -> xmalloc) (strlen (filename) + 1);
78 strcpy (objfile -> name, filename);
80 objfile -> obfd = abfd;
82 objfile -> mtime = bfd_get_mtime (abfd);
84 /* Set up the various obstacks to use the memory allocation/free
85 functions that are appropriate for this objfile. */
87 obstack_full_begin (&objfile -> psymbol_obstack, 0, 0,
88 objfile -> xmalloc, objfile -> free);
89 obstack_full_begin (&objfile -> symbol_obstack, 0, 0,
90 objfile -> xmalloc, objfile -> free);
91 obstack_full_begin (&objfile -> type_obstack, 0, 0,
92 objfile -> xmalloc, objfile -> free);
94 /* Push this file onto the head of the linked list of other such files. */
96 objfile -> next = object_files;
97 object_files = objfile;
103 /* Destroy an objfile and all the symtabs and psymtabs under it. Note
104 that as much as possible is allocated on the symbol_obstack and
105 psymbol_obstack, so that the memory can be efficiently freed. */
108 free_objfile (objfile)
109 struct objfile *objfile;
115 (*objfile -> free) (objfile -> name);
119 bfd_close (objfile -> obfd);
122 /* Remove it from the chain of all objfiles. */
124 if (object_files == objfile)
126 object_files = objfile -> next;
130 for (ofp = object_files; ofp; ofp = ofp -> next)
132 if (ofp -> next == objfile)
134 ofp -> next = objfile -> next;
139 obstack_free (&objfile -> psymbol_obstack, 0);
140 obstack_free (&objfile -> symbol_obstack, 0);
141 obstack_free (&objfile -> type_obstack, 0);
145 /* Before the symbol table code was redone to make it easier to
146 selectively load and remove information particular to a specific
147 linkage unit, gdb used to do these things whenever the monolithic
148 symbol table was blown away. How much still needs to be done
149 is unknown, but we play it safe for now and keep each action until
150 it is shown to be no longer needed. */
152 clear_symtab_users_once ();
153 #if defined (CLEAR_SOLIB)
156 clear_pc_function_cache ();
160 /* The last thing we do is free the objfile struct itself, using the
161 free() that is appropriate for the objfile. */
163 (*objfile -> free) (objfile);
166 /* Many places in gdb want to test just to see if we have any partial
167 symbols available. This function returns zero if none are currently
168 available, nonzero otherwise. */
171 have_partial_symbols ()
176 for (ofp = object_files; ofp; ofp = ofp -> next)
178 if (ofp -> psymtabs != NULL)
187 /* Many places in gdb want to test just to see if we have any full
188 symbols available. This function returns zero if none are currently
189 available, nonzero otherwise. */
197 for (ofp = object_files; ofp; ofp = ofp -> next)
199 if (ofp -> symtabs != NULL)
208 /* Many places in gdb want to test just to see if we have any minimal
209 symbols available. This function returns zero if none are currently
210 available, nonzero otherwise. */
213 have_minimal_symbols ()
218 for (ofp = object_files; ofp; ofp = ofp -> next)
220 if (ofp -> msymbols != NULL)
229 /* Call the function specified by FUNC for each currently available objfile,
230 for as long as this function continues to return NULL. If the function
231 ever returns non-NULL, then the iteration over the objfiles is terminated,
232 and the result is returned to the caller. The function called has full
233 control over the form and content of the information returned via the
234 non-NULL result, which may be as simple as a pointer to the objfile that
235 the iteration terminated on, or as complex as a pointer to a private
236 structure containing multiple results. */
239 iterate_over_objfiles (func, arg1, arg2, arg3)
240 PTR (*func) PARAMS ((struct objfile *, PTR, PTR, PTR));
245 register struct objfile *objfile;
248 for (objfile = object_files;
249 objfile != NULL && result == NULL;
250 objfile = objfile -> next)
252 result = (*func)(objfile, arg1, arg2, arg3);
257 /* Call the function specified by FUNC for each currently available symbol
258 table, for as long as this function continues to return NULL. If the
259 function ever returns non-NULL, then the iteration over the symbol tables
260 is terminated, and the result is returned to the caller. The function
261 called has full control over the form and content of the information
262 returned via the non-NULL result, which may be as simple as a pointer
263 to the symtab that the iteration terminated on, or as complex as a
264 pointer to a private structure containing multiple results. */
267 iterate_over_symtabs (func, arg1, arg2, arg3)
268 PTR (*func) PARAMS ((struct objfile *, struct symtab *, PTR, PTR, PTR));
273 register struct objfile *objfile;
274 register struct symtab *symtab;
277 for (objfile = object_files;
278 objfile != NULL && result == NULL;
279 objfile = objfile -> next)
281 for (symtab = objfile -> symtabs;
282 symtab != NULL && result == NULL;
283 symtab = symtab -> next)
285 result = (*func)(objfile, symtab, arg1, arg2, arg3);
291 /* Call the function specified by FUNC for each currently available partial
292 symbol table, for as long as this function continues to return NULL. If
293 the function ever returns non-NULL, then the iteration over the partial
294 symbol tables is terminated, and the result is returned to the caller.
296 The function called has full control over the form and content of the
297 information returned via the non-NULL result, which may be as simple as a
298 pointer to the partial symbol table that the iteration terminated on, or
299 as complex as a pointer to a private structure containing multiple
303 iterate_over_psymtabs (func, arg1, arg2, arg3)
304 PTR (*func) PARAMS ((struct objfile *, struct partial_symtab *,
310 register struct objfile *objfile;
311 register struct partial_symtab *psymtab;
314 for (objfile = object_files;
315 objfile != NULL && result == NULL;
316 objfile = objfile -> next)
318 for (psymtab = objfile -> psymtabs;
319 psymtab != NULL && result == NULL;
320 psymtab = psymtab -> next)
322 result = (*func)(objfile, psymtab, arg1, arg2, arg3);