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. */
25 #include "bfd.h" /* Binary File Description */
31 /* Externally visible variables that are owned by this module. */
33 struct objfile
*object_files
; /* Linked list of all objfiles */
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. */
39 allocate_objfile (abfd
, filename
, dumpable
)
44 struct objfile
*objfile
;
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. */
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
;
64 objfile
= (struct objfile
*) xmalloc (sizeof (struct objfile
));
65 (void) memset (objfile
, 0, sizeof (struct objfile
));
66 objfile
-> malloc
= (PTR (*) PARAMS ((long))) malloc
;
67 objfile
-> realloc
= (PTR (*) PARAMS ((PTR
, long))) realloc
;
68 objfile
-> xmalloc
= xmalloc
;
69 objfile
-> xrealloc
= xrealloc
;
70 objfile
-> free
= free
;
73 /* Now, malloc a fresh copy of the filename string using the malloc
74 specified as appropriate for the objfile. */
76 objfile
-> name
= (*objfile
-> xmalloc
) (strlen (filename
) + 1);
77 strcpy (objfile
-> name
, filename
);
79 objfile
-> obfd
= abfd
;
81 objfile
-> mtime
= bfd_get_mtime (abfd
);
83 /* Set up the various obstacks to use the memory allocation/free
84 functions that are appropriate for this objfile. */
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
);
93 /* Push this file onto the head of the linked list of other such files. */
95 objfile
-> next
= object_files
;
96 object_files
= objfile
;
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. */
107 free_objfile (objfile
)
108 struct objfile
*objfile
;
114 (*objfile
-> free
) (objfile
-> name
);
118 bfd_close (objfile
-> obfd
);
121 /* Remove it from the chain of all objfiles. */
123 if (object_files
== objfile
)
125 object_files
= objfile
-> next
;
129 for (ofp
= object_files
; ofp
; ofp
= ofp
-> next
)
131 if (ofp
-> next
== objfile
)
133 ofp
-> next
= objfile
-> next
;
138 obstack_free (&objfile
-> psymbol_obstack
, 0);
139 obstack_free (&objfile
-> symbol_obstack
, 0);
140 obstack_free (&objfile
-> type_obstack
, 0);
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. */
151 clear_symtab_users_once ();
152 #if defined (CLEAR_SOLIB)
155 clear_pc_function_cache ();
159 /* The last thing we do is free the objfile struct itself, using the
160 free() that is appropriate for the objfile. */
162 (*objfile
-> free
) (objfile
);
166 /* Free all the object files at once. */
171 struct objfile
*objfile
, *temp
;
173 ALL_OBJFILES_SAFE (objfile
, temp
)
175 free_objfile (objfile
);
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. */
184 have_partial_symbols ()
189 for (ofp
= object_files
; ofp
; ofp
= ofp
-> next
)
191 if (ofp
-> psymtabs
!= NULL
)
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. */
210 for (ofp
= object_files
; ofp
; ofp
= ofp
-> next
)
212 if (ofp
-> symtabs
!= NULL
)
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. */
226 have_minimal_symbols ()
231 for (ofp
= object_files
; ofp
; ofp
= ofp
-> next
)
233 if (ofp
-> msymbols
!= NULL
)
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. */
252 iterate_over_objfiles (func
, arg1
, arg2
, arg3
)
253 PTR (*func
) PARAMS ((struct objfile
*, PTR
, PTR
, PTR
));
258 register struct objfile
*objfile
;
261 for (objfile
= object_files
;
262 objfile
!= NULL
&& result
== NULL
;
263 objfile
= objfile
-> next
)
265 result
= (*func
)(objfile
, arg1
, arg2
, arg3
);
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. */
280 iterate_over_symtabs (func
, arg1
, arg2
, arg3
)
281 PTR (*func
) PARAMS ((struct objfile
*, struct symtab
*, PTR
, PTR
, PTR
));
286 register struct objfile
*objfile
;
287 register struct symtab
*symtab
;
290 for (objfile
= object_files
;
291 objfile
!= NULL
&& result
== NULL
;
292 objfile
= objfile
-> next
)
294 for (symtab
= objfile
-> symtabs
;
295 symtab
!= NULL
&& result
== NULL
;
296 symtab
= symtab
-> next
)
298 result
= (*func
)(objfile
, symtab
, arg1
, arg2
, arg3
);
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.
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
316 iterate_over_psymtabs (func
, arg1
, arg2
, arg3
)
317 PTR (*func
) PARAMS ((struct objfile
*, struct partial_symtab
*,
323 register struct objfile
*objfile
;
324 register struct partial_symtab
*psymtab
;
327 for (objfile
= object_files
;
328 objfile
!= NULL
&& result
== NULL
;
329 objfile
= objfile
-> next
)
331 for (psymtab
= objfile
-> psymtabs
;
332 psymtab
!= NULL
&& result
== NULL
;
333 psymtab
= psymtab
-> next
)
335 result
= (*func
)(objfile
, psymtab
, arg1
, arg2
, arg3
);
This page took 0.036051 seconds and 4 git commands to generate.