53ac034b16a48b3ad4551a01c279d5316e9880b4
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
);
167 /* Free all the object files at once. */
172 struct objfile
*objfile
, *temp
;
174 ALL_OBJFILES_SAFE (objfile
, temp
)
176 free_objfile (objfile
);
180 /* Many places in gdb want to test just to see if we have any partial
181 symbols available. This function returns zero if none are currently
182 available, nonzero otherwise. */
185 have_partial_symbols ()
190 for (ofp
= object_files
; ofp
; ofp
= ofp
-> next
)
192 if (ofp
-> psymtabs
!= NULL
)
201 /* Many places in gdb want to test just to see if we have any full
202 symbols available. This function returns zero if none are currently
203 available, nonzero otherwise. */
211 for (ofp
= object_files
; ofp
; ofp
= ofp
-> next
)
213 if (ofp
-> symtabs
!= NULL
)
222 /* Many places in gdb want to test just to see if we have any minimal
223 symbols available. This function returns zero if none are currently
224 available, nonzero otherwise. */
227 have_minimal_symbols ()
232 for (ofp
= object_files
; ofp
; ofp
= ofp
-> next
)
234 if (ofp
-> msymbols
!= NULL
)
243 /* Call the function specified by FUNC for each currently available objfile,
244 for as long as this function continues to return NULL. If the function
245 ever returns non-NULL, then the iteration over the objfiles is terminated,
246 and the result is returned to the caller. The function called has full
247 control over the form and content of the information returned via the
248 non-NULL result, which may be as simple as a pointer to the objfile that
249 the iteration terminated on, or as complex as a pointer to a private
250 structure containing multiple results. */
253 iterate_over_objfiles (func
, arg1
, arg2
, arg3
)
254 PTR (*func
) PARAMS ((struct objfile
*, PTR
, PTR
, PTR
));
259 register struct objfile
*objfile
;
262 for (objfile
= object_files
;
263 objfile
!= NULL
&& result
== NULL
;
264 objfile
= objfile
-> next
)
266 result
= (*func
)(objfile
, arg1
, arg2
, arg3
);
271 /* Call the function specified by FUNC for each currently available symbol
272 table, for as long as this function continues to return NULL. If the
273 function ever returns non-NULL, then the iteration over the symbol tables
274 is terminated, and the result is returned to the caller. The function
275 called has full control over the form and content of the information
276 returned via the non-NULL result, which may be as simple as a pointer
277 to the symtab that the iteration terminated on, or as complex as a
278 pointer to a private structure containing multiple results. */
281 iterate_over_symtabs (func
, arg1
, arg2
, arg3
)
282 PTR (*func
) PARAMS ((struct objfile
*, struct symtab
*, PTR
, PTR
, PTR
));
287 register struct objfile
*objfile
;
288 register struct symtab
*symtab
;
291 for (objfile
= object_files
;
292 objfile
!= NULL
&& result
== NULL
;
293 objfile
= objfile
-> next
)
295 for (symtab
= objfile
-> symtabs
;
296 symtab
!= NULL
&& result
== NULL
;
297 symtab
= symtab
-> next
)
299 result
= (*func
)(objfile
, symtab
, arg1
, arg2
, arg3
);
305 /* Call the function specified by FUNC for each currently available partial
306 symbol table, for as long as this function continues to return NULL. If
307 the function ever returns non-NULL, then the iteration over the partial
308 symbol tables is terminated, and the result is returned to the caller.
310 The function called has full control over the form and content of the
311 information returned via the non-NULL result, which may be as simple as a
312 pointer to the partial symbol table that the iteration terminated on, or
313 as complex as a pointer to a private structure containing multiple
317 iterate_over_psymtabs (func
, arg1
, arg2
, arg3
)
318 PTR (*func
) PARAMS ((struct objfile
*, struct partial_symtab
*,
324 register struct objfile
*objfile
;
325 register struct partial_symtab
*psymtab
;
328 for (objfile
= object_files
;
329 objfile
!= NULL
&& result
== NULL
;
330 objfile
= objfile
-> next
)
332 for (psymtab
= objfile
-> psymtabs
;
333 psymtab
!= NULL
&& result
== NULL
;
334 psymtab
= psymtab
-> next
)
336 result
= (*func
)(objfile
, psymtab
, arg1
, arg2
, arg3
);
This page took 0.035457 seconds and 4 git commands to generate.